Skip to content

Commit 0e52036

Browse files
committed
fix: Add ARM64 cross-compilation support for CGO builds
- Install gcc-aarch64-linux-gnu for Linux ARM64 builds in CI - Set CC=aarch64-linux-gnu-gcc for cross-compilation - Make local ARM64 builds conditional on cross-compiler availability - Provides helpful message when cross-compiler is missing locally This fixes build failures when cross-compiling ARM64 binaries with CGO enabled for SQLite support.
1 parent 8b17d19 commit 0e52036

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

.github/workflows/artifacts.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,18 @@ jobs:
4646
go-version-file: 'go.mod'
4747
cache: true
4848

49-
- name: Install build dependencies (Linux)
50-
if: matrix.goos == 'linux'
49+
- name: Install build dependencies (Linux amd64)
50+
if: matrix.goos == 'linux' && matrix.goarch == 'amd64'
5151
run: |
5252
sudo apt-get update
5353
sudo apt-get install -y gcc libsqlite3-dev
5454
55+
- name: Install build dependencies (Linux arm64)
56+
if: matrix.goos == 'linux' && matrix.goarch == 'arm64'
57+
run: |
58+
sudo apt-get update
59+
sudo apt-get install -y gcc-aarch64-linux-gnu libsqlite3-dev
60+
5561
- name: Get version info
5662
id: version
5763
run: |
@@ -67,6 +73,7 @@ jobs:
6773
CGO_ENABLED: ${{ matrix.cgo }}
6874
GOOS: ${{ matrix.goos }}
6975
GOARCH: ${{ matrix.goarch }}
76+
CC: ${{ matrix.goarch == 'arm64' && matrix.goos == 'linux' && 'aarch64-linux-gnu-gcc' || '' }}
7077
run: |
7178
go build -ldflags "-X github.com/inference-gateway/cli/cmd.version=${{ steps.version.outputs.version }} -X github.com/inference-gateway/cli/cmd.commit=${{ steps.version.outputs.commit }} -X github.com/inference-gateway/cli/cmd.date=${{ steps.version.outputs.date }}" -o infer-${{ matrix.goos }}-${{ matrix.goarch }} .
7279

Taskfile.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,13 @@ tasks:
155155
cmds:
156156
- mkdir -p dist
157157
- CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -ldflags "-X github.com/inference-gateway/cli/cmd.version={{.VERSION}} -X github.com/inference-gateway/cli/cmd.commit={{.COMMIT}} -X github.com/inference-gateway/cli/cmd.date={{.DATE}}" -o dist/{{.BINARY_NAME}}-linux-amd64 {{.MAIN_PACKAGE}}
158-
- CGO_ENABLED=1 GOOS=linux GOARCH=arm64 go build -ldflags "-X github.com/inference-gateway/cli/cmd.version={{.VERSION}} -X github.com/inference-gateway/cli/cmd.commit={{.COMMIT}} -X github.com/inference-gateway/cli/cmd.date={{.DATE}}" -o dist/{{.BINARY_NAME}}-linux-arm64 {{.MAIN_PACKAGE}}
158+
- |
159+
if command -v aarch64-linux-gnu-gcc >/dev/null 2>&1; then
160+
CC=aarch64-linux-gnu-gcc CGO_ENABLED=1 GOOS=linux GOARCH=arm64 go build -ldflags "-X github.com/inference-gateway/cli/cmd.version={{.VERSION}} -X github.com/inference-gateway/cli/cmd.commit={{.COMMIT}} -X github.com/inference-gateway/cli/cmd.date={{.DATE}}" -o dist/{{.BINARY_NAME}}-linux-arm64 {{.MAIN_PACKAGE}}
161+
else
162+
echo "⚠ ARM64 cross-compiler not found, skipping linux-arm64 build"
163+
echo " Install: gcc-aarch64-linux-gnu (or build on ARM64 machine)"
164+
fi
159165
- cd dist && sha256sum {{.BINARY_NAME}}-* > checksums.txt
160166
- |
161167
if command -v cosign >/dev/null 2>&1; then

0 commit comments

Comments
 (0)