From 080a428b9cd204d2a396c309fa891d2f5c257231 Mon Sep 17 00:00:00 2001 From: Bloomingg <1293499952@qq.com> Date: Fri, 11 Oct 2024 14:46:15 +0800 Subject: [PATCH] feat: add win32 platform --- .github/workflows/auto-build-electron.yml | 19 ++++++++++++++++--- magefile.go | 19 +++++++++++++++++-- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/.github/workflows/auto-build-electron.yml b/.github/workflows/auto-build-electron.yml index 4ecc628..b843d6e 100644 --- a/.github/workflows/auto-build-electron.yml +++ b/.github/workflows/auto-build-electron.yml @@ -24,9 +24,9 @@ jobs: - os: windows-latest arch: amd64 build: buildWindows - # - os: windows-latest - # arch: 386 - # build: buildWindows386 + - os: windows-latest + arch: 386 + build: buildWindows steps: - name: Checkout code @@ -48,10 +48,23 @@ jobs: echo "CC=aarch64-linux-gnu-gcc" >> $GITHUB_ENV echo "CXX=aarch64-linux-gnu-g++" >> $GITHUB_ENV + - name: Install MinGW-w64 using Chocolatey + if: runner.os == 'Windows' && matrix.arch == '386' + run: | + curl -L -o mingw32.7z https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/mingw-builds/8.1.0/threads-posix/dwarf/i686-8.1.0-release-posix-dwarf-rt_v6-rev0.7z/download + 7z x mingw32.7z -oC:/mingw32 + - name: Setup and build on Windows ${{ matrix.arch }} if: runner.os == 'Windows' run: | ./bootstrap_install_mage.bat + $env:GOARCH="${{ matrix.arch }}" + if ($env:GOARCH -eq "386") { + $env:PATH = "C:/mingw32/bin;$env:PATH" + gcc --version + $env:CC="gcc -m32" + $env:CXX="g++ -m32" + } mage ${{ matrix.build }} - name: Setup and build on ${{ matrix.os }} ${{ matrix.arch }} diff --git a/magefile.go b/magefile.go index ba760ec..8299d6b 100644 --- a/magefile.go +++ b/magefile.go @@ -127,11 +127,26 @@ func BuildWindows() error { fmt.Println("Building for Windows...") outPath += "windows" + arch := os.Getenv("GOARCH") + cc := os.Getenv("CC") + cxx := os.Getenv("CXX") + + if len(arch) == 0 { + arch = runtime.GOARCH + } + + if len(cc) == 0 { + cc = "gcc" + } + + if len(cxx) != 0 { + os.Setenv("CXX", cxx) + } os.Setenv("GOOS", "windows") - os.Setenv("GOARCH", "amd64") + os.Setenv("GOARCH", arch) os.Setenv("CGO_ENABLED", "1") - os.Setenv("CC", "gcc") + os.Setenv("CC", cc) cmd := exec.Command("go", "build", "-buildmode=c-shared", "-trimpath", "-ldflags=-s -w", "-o", outPath+"/"+soName+".dll", ".") cmd.Dir = goSrc