fix: build with target arch

dev_1
Bloomingg 9 months ago
parent 0050e20fba
commit 893a2c616b
  1. 18
      .github/workflows/auto-build-electron.yml
  2. 27
      magefile.go

@ -24,9 +24,9 @@ jobs:
- os: windows-latest - os: windows-latest
arch: amd64 arch: amd64
build: buildWindows build: buildWindows
- os: windows-latest # - os: windows-latest
arch: 386 # arch: 386
build: buildWindows # build: buildWindows386
steps: steps:
- name: Checkout code - name: Checkout code
@ -40,10 +40,17 @@ jobs:
- name: Check Go version - name: Check Go version
run: 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 }} - name: Setup and build on Windows ${{ matrix.arch }}
if: runner.os == 'Windows' if: runner.os == 'Windows'
run: | run: |
echo "GOARCH=${{ matrix.arch }}" >> $GITHUB_ENV
./bootstrap_install_mage.bat ./bootstrap_install_mage.bat
mage ${{ matrix.build }} mage ${{ matrix.build }}
@ -51,7 +58,8 @@ jobs:
if: runner.os != 'Windows' if: runner.os != 'Windows'
run: | run: |
sudo bash ./bootstrap_install_mage.sh sudo bash ./bootstrap_install_mage.sh
sudo mage ${{ matrix.build }} export GOARCH=${{ matrix.arch }}
sudo -E mage ${{ matrix.build }}
- name: Upload Artifacts - name: Upload Artifacts
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4

@ -57,8 +57,14 @@ func BuildAndroid() error {
func BuildIOS() error { func BuildIOS() error {
fmt.Println("Building for iOS...") fmt.Println("Building for iOS...")
outPath += "ios" outPath += "ios"
arch := os.Getenv("GOARCH")
if len(arch) == 0 {
arch = runtime.GOARCH
}
os.Setenv("GOOS", "darwin") os.Setenv("GOOS", "darwin")
os.Setenv("GOARCH", "arm64") os.Setenv("GOARCH", arch)
os.Setenv("CGO_ENABLED", "1") os.Setenv("CGO_ENABLED", "1")
os.Setenv("CC", "clang") os.Setenv("CC", "clang")
@ -81,11 +87,26 @@ func BuildLinux() error {
fmt.Println("Building for Linux...") fmt.Println("Building for Linux...")
outPath += "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("GOOS", "linux")
os.Setenv("GOARCH", "amd64") os.Setenv("GOARCH", arch)
os.Setenv("CGO_ENABLED", "1") 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 := exec.Command("go", "build", "-buildmode=c-shared", "-trimpath", "-ldflags=-s -w", "-o", outPath+"/"+soName+".so", ".")
cmd.Dir = goSrc cmd.Dir = goSrc

Loading…
Cancel
Save