Skip to content

Commit 057c6d0

Browse files
committed
Cross-compilation linux / darwin arm64 / amd64
1 parent 42ebcb0 commit 057c6d0

File tree

1 file changed

+34
-13
lines changed

1 file changed

+34
-13
lines changed

.github/workflows/release.yml

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,36 +19,57 @@ env:
1919

2020
jobs:
2121
build:
22-
name: Build (${{ matrix.goos }}/${{ matrix.goarch }})
23-
runs-on: ubuntu-latest
2422
strategy:
2523
fail-fast: false
2624
matrix:
27-
goos: [linux, darwin]
28-
goarch: [amd64, arm64]
29-
25+
include:
26+
- os: ubuntu-latest
27+
goos: linux
28+
goarch: amd64
29+
- os: ubuntu-latest
30+
goos: linux
31+
goarch: arm64
32+
cc: aarch64-linux-gnu-gcc
33+
cxx: aarch64-linux-gnu-g++
34+
- os: macos-latest
35+
goos: darwin
36+
goarch: amd64
37+
- os: macos-latest
38+
goos: darwin
39+
goarch: arm64
40+
runs-on: ${{ matrix.os }}
3041
steps:
31-
- name: Checkout
32-
uses: actions/checkout@v4
42+
- uses: actions/checkout@v4
3343

34-
- name: Set up Go
35-
uses: actions/setup-go@v5
44+
- uses: actions/setup-go@v5
3645
with:
3746
go-version: '>=1.22'
3847
cache: true
3948

49+
- name: Install cross compiler (linux/arm64)
50+
if: ${{ matrix.cc == 'aarch64-linux-gnu-gcc' }}
51+
run: |
52+
sudo apt-get update
53+
sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
54+
4055
- name: Test
56+
if: ${{ matrix.goos == 'linux' }}
4157
run: go test ./...
4258

4359
- name: Build
4460
shell: bash
61+
env:
62+
CC: ${{ matrix.cc }}
63+
CXX: ${{ matrix.cxx }}
64+
CGO_ENABLED: 1
65+
GOOS: ${{ matrix.goos }}
66+
GOARCH: ${{ matrix.goarch }}
4567
run: |
4668
set -euxo pipefail
4769
mkdir -p dist
48-
OUT="dist/${APP_NAME}_${VERSION}_${{ matrix.goos }}_${{ matrix.goarch }}"
49-
CGO_ENABLED=0 GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} \
50-
go build -trimpath -ldflags="-s -w -X main.version=${VERSION}" -o "$OUT" .
51-
(cd dist && sha256sum "$(basename "$OUT")" > "$(basename "$OUT").sha256")
70+
OUT="dist/${APP_NAME}_${VERSION}_${GOOS}_${GOARCH}"
71+
go build -trimpath -ldflags="-s -w -X main.version=${VERSION}" -o "$OUT" .
72+
(cd dist && sha256sum "$(basename "$OUT")" > "$(basename "$OUT").sha256" || shasum -a 256 "$(basename "$OUT")" > "$(basename "$OUT").sha256")
5273
5374
- name: Upload artifact
5475
uses: actions/upload-artifact@v4

0 commit comments

Comments
 (0)