Build Go Windows DLL (Win7 / Go1.20) #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build Go Windows DLL (Win7 / Go1.20) | |
| permissions: | |
| contents: write | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| branch: | |
| description: "要构建的代码分支(例如:unity)" | |
| required: true | |
| default: "main" | |
| dll_name: | |
| required: true | |
| default: "openimsdk" | |
| package_path: | |
| required: true | |
| default: "./" | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| include: | |
| - arch: amd64 | |
| cc: x86_64-w64-mingw32-gcc | |
| cxx: x86_64-w64-mingw32-g++ | |
| suffix: amd64 | |
| - arch: "386" | |
| cc: i686-w64-mingw32-gcc | |
| cxx: i686-w64-mingw32-g++ | |
| suffix: 386 | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ inputs.branch }} | |
| - name: Setup Go 1.20 | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: "1.20" | |
| - name: Install mingw-w64 for CGO cross-compile | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y --no-install-recommends mingw-w64 | |
| - name: Build Windows DLL (${{ matrix.arch }}) | |
| env: | |
| GOOS: windows | |
| GOARCH: ${{ matrix.arch }} | |
| CGO_ENABLED: "1" | |
| CC: ${{ matrix.cc }} | |
| CXX: ${{ matrix.cxx }} | |
| CGO_CFLAGS: "-D_WIN32_WINNT=0x0601 -DWINVER=0x0601" | |
| run: | | |
| mkdir -p windows | |
| OUT="windows/${{ inputs.dll_name }}_${{ matrix.suffix }}.dll" | |
| echo "Building ${OUT} ..." | |
| go build -buildmode=c-shared -trimpath -ldflags="-s -w" \ | |
| -o "${OUT}" \ | |
| "${{ inputs.package_path }}" | |
| ls -l windows | |
| - name: Upload Artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ inputs.dll_name }}-win-dlls | |
| path: | | |
| windows/${{ inputs.dll_name }}_*.dll | |
| windows/${{ inputs.dll_name }}_*.h |