From 893a2c616b907a5d23c542fbc24ecaa07016c24d Mon Sep 17 00:00:00 2001 From: Bloomingg <1293499952@qq.com> Date: Fri, 27 Sep 2024 16:57:18 +0800 Subject: [PATCH] fix: build with target arch --- .github/workflows/auto-build-electron.yml | 20 ++++++++++++----- magefile.go | 27 ++++++++++++++++++++--- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/.github/workflows/auto-build-electron.yml b/.github/workflows/auto-build-electron.yml index 6acbe1e..4ecc628 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: buildWindows + # - os: windows-latest + # arch: 386 + # build: buildWindows386 steps: - name: Checkout code @@ -39,11 +39,18 @@ jobs: - name: Check Go version run: go version - + + - name: Install ARM64 cross-compilation toolchain + if: matrix.arch == 'arm64' && matrix.os == 'ubuntu-latest' + run: | + sudo apt-get update + sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu + echo "CC=aarch64-linux-gnu-gcc" >> $GITHUB_ENV + echo "CXX=aarch64-linux-gnu-g++" >> $GITHUB_ENV + - name: Setup and build on Windows ${{ matrix.arch }} if: runner.os == 'Windows' run: | - echo "GOARCH=${{ matrix.arch }}" >> $GITHUB_ENV ./bootstrap_install_mage.bat mage ${{ matrix.build }} @@ -51,7 +58,8 @@ jobs: if: runner.os != 'Windows' run: | sudo bash ./bootstrap_install_mage.sh - sudo mage ${{ matrix.build }} + export GOARCH=${{ matrix.arch }} + sudo -E mage ${{ matrix.build }} - name: Upload Artifacts uses: actions/upload-artifact@v4 diff --git a/magefile.go b/magefile.go index 2a8330e..ba760ec 100644 --- a/magefile.go +++ b/magefile.go @@ -57,8 +57,14 @@ func BuildAndroid() error { func BuildIOS() error { fmt.Println("Building for iOS...") outPath += "ios" + arch := os.Getenv("GOARCH") + + if len(arch) == 0 { + arch = runtime.GOARCH + } + os.Setenv("GOOS", "darwin") - os.Setenv("GOARCH", "arm64") + os.Setenv("GOARCH", arch) os.Setenv("CGO_ENABLED", "1") os.Setenv("CC", "clang") @@ -81,11 +87,26 @@ func BuildLinux() error { fmt.Println("Building for Linux...") outPath += "linux" + 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", "linux") - 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+".so", ".") cmd.Dir = goSrc