|
1 | | -name: Build Go Windows DLL |
| 1 | +name: Build Go Windows DLL (Win7 / Go1.20) |
2 | 2 |
|
3 | 3 | permissions: |
4 | 4 | contents: write |
|
7 | 7 | workflow_dispatch: |
8 | 8 | inputs: |
9 | 9 | branch: |
10 | | - description: "Branch to build from" |
| 10 | + description: "要构建的代码分支(例如:unity)" |
11 | 11 | required: true |
12 | 12 | default: "main" |
| 13 | + dll_name: |
| 14 | + required: true |
| 15 | + default: "openimsdk" |
| 16 | + package_path: |
| 17 | + required: true |
| 18 | + default: "./" |
13 | 19 |
|
14 | 20 | jobs: |
15 | | - build-windows-dll: |
| 21 | + build: |
16 | 22 | runs-on: ubuntu-latest |
| 23 | + |
| 24 | + strategy: |
| 25 | + matrix: |
| 26 | + include: |
| 27 | + - arch: amd64 |
| 28 | + cc: x86_64-w64-mingw32-gcc |
| 29 | + cxx: x86_64-w64-mingw32-g++ |
| 30 | + suffix: amd64 |
| 31 | + - arch: "386" |
| 32 | + cc: i686-w64-mingw32-gcc |
| 33 | + cxx: i686-w64-mingw32-g++ |
| 34 | + suffix: 386 |
| 35 | + |
17 | 36 | steps: |
18 | | - - name: Checkout repository |
| 37 | + - name: Checkout |
19 | 38 | uses: actions/checkout@v4 |
20 | 39 | with: |
21 | | - ref: ${{ github.event.inputs.branch }} |
| 40 | + |
| 41 | + ref: ${{ inputs.branch }} |
22 | 42 |
|
23 | | - - name: Set up Go 1.20 |
| 43 | + - name: Setup Go 1.20 |
24 | 44 | uses: actions/setup-go@v5 |
25 | 45 | with: |
26 | 46 | go-version: "1.20" |
27 | 47 |
|
28 | | - - name: Build DLLs for Windows (32-bit and 64-bit) |
| 48 | + - name: Install mingw-w64 for CGO cross-compile |
| 49 | + run: | |
| 50 | + sudo apt-get update |
| 51 | + sudo apt-get install -y --no-install-recommends mingw-w64 |
| 52 | +
|
| 53 | + - name: Build Windows DLL (${{ matrix.arch }}) |
| 54 | + env: |
| 55 | + GOOS: windows |
| 56 | + GOARCH: ${{ matrix.arch }} |
| 57 | + CGO_ENABLED: "1" |
| 58 | + CC: ${{ matrix.cc }} |
| 59 | + CXX: ${{ matrix.cxx }} |
| 60 | + |
| 61 | + CGO_CFLAGS: "-D_WIN32_WINNT=0x0601 -DWINVER=0x0601" |
29 | 62 | run: | |
30 | 63 | mkdir -p windows |
| 64 | +
|
31 | 65 | |
32 | | - echo "Building 64-bit DLL..." |
33 | | - GOOS=windows GOARCH=amd64 CGO_ENABLED=1 \ |
34 | | - go build -buildmode=c-shared -trimpath -ldflags="-s -w" \ |
35 | | - -o ./windows/openimsdk_amd64.dll ./ |
| 66 | + OUT="windows/${{ inputs.dll_name }}_${{ matrix.suffix }}.dll" |
| 67 | +
|
| 68 | + echo "Building ${OUT} ..." |
| 69 | + go build -buildmode=c-shared -trimpath -ldflags="-s -w" \ |
| 70 | + -o "${OUT}" \ |
| 71 | + "${{ inputs.package_path }}" |
36 | 72 |
|
37 | | - echo "Building 32-bit DLL..." |
38 | | - GOOS=windows GOARCH=386 CGO_ENABLED=1 \ |
39 | | - go build -buildmode=c-shared -trimpath -ldflags="-s -w" \ |
40 | | - -o ./windows/openimsdk_386.dll ./ |
| 73 | + ls -l windows |
41 | 74 |
|
42 | | - - name: Upload DLLs as Artifacts |
| 75 | + - name: Upload Artifacts |
43 | 76 | uses: actions/upload-artifact@v4 |
44 | 77 | with: |
45 | | - name: windows-dlls |
46 | | - path: ./windows/*.dll |
| 78 | + name: ${{ inputs.dll_name }}-win-dlls |
| 79 | + path: | |
| 80 | + windows/${{ inputs.dll_name }}_*.dll |
| 81 | + windows/${{ inputs.dll_name }}_*.h |
0 commit comments