Skip to content

Commit 2b13e1d

Browse files
committed
Cross-compile binaries for aarch64-unknown-linux-gnu
GitHub does not provide a aarch64-unknown-linux-gnu runner that we would need to compile binaries for Raspberry Pi, but we can use `cross` to build those on the amd64 Ubuntu runner.
1 parent e459602 commit 2b13e1d

File tree

2 files changed

+34
-14
lines changed

2 files changed

+34
-14
lines changed

.github/workflows/release.yml

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,19 @@ jobs:
4747

4848
strategy:
4949
matrix:
50-
os:
51-
- ubuntu-latest
52-
- windows-latest
53-
- macos-latest
50+
include:
51+
- target: x86_64-unknown-linux-gnu
52+
os: ubuntu-latest
53+
name: xsnippet-api-x86_64-linux.gz
54+
- target: aarch64-unknown-linux-gnu
55+
os: ubuntu-latest
56+
name: xsnippet-api-aarch64-linux.gz
57+
- target: x86_64-pc-windows-msvc
58+
os: windows-latest
59+
name: xsnippet-api-x86_64-windows.exe.7z
60+
- target: aarch64-apple-darwin
61+
os: macos-latest
62+
name: xsnippet-api-aarch64-macos.gz
5463

5564
runs-on: ${{ matrix.os }}
5665

@@ -66,31 +75,37 @@ jobs:
6675
- name: Setup PostgreSQL
6776
uses: ikalnytskyi/action-setup-postgres@v6
6877

69-
- uses: actions-rs/cargo@v1
70-
with:
71-
command: build
72-
args: --release
73-
7478
- id: build
7579
run: |
7680
rustc --print cfg | grep = > rustc.vars
7781
source rustc.vars
7882
79-
pushd target/release
80-
if [ "$RUNNER_OS" == "Windows" ]; then
81-
export ASSET_NAME="xsnippet-api-${target_arch}-${target_os}.exe.7z"
83+
export HOST="${target_arch}-${target_os}-${target_env}"
84+
if [ "$HOST" = "$TARGET" ]; then
85+
cargo build --release
86+
87+
pushd target/release
88+
else
89+
cargo install cross
90+
cross build --release --target ${TARGET}
91+
92+
pushd target/${TARGET}/release
93+
fi
94+
95+
if [ "$TARGET" =~ "windows" ]; then
8296
7z a $ASSET_NAME xsnippet-api.exe
8397
else
84-
export ASSET_NAME="xsnippet-api-${target_arch}-${target_os}.gz"
8598
tar cvzf $ASSET_NAME xsnippet-api
8699
fi
87100
gh release upload $RELEASE_TAG $ASSET_NAME
88101
popd
89102
90-
echo "asset_path=target/release/$ASSET_NAME" >> $GITHUB_OUTPUT
103+
echo "asset_path=$PWD/$ASSET_NAME" >> $GITHUB_OUTPUT
91104
env:
105+
ASSET_NAME: ${{ matrix.name }}
92106
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
93107
GH_REPO: ${{ env.GITHUB_REPOSITORY }}
108+
TARGET: ${{ matrix.target }}
94109
RELEASE_TAG: ${{ needs.create_release.outputs.release_tag }}
95110

96111
- uses: actions/attest-build-provenance@v1

Cross.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[build]
2+
pre-build = [
3+
"dpkg --add-architecture $CROSS_DEB_ARCH",
4+
"apt-get update && apt-get install --assume-yes libssl-dev:$CROSS_DEB_ARCH libpq-dev:$CROSS_DEB_ARCH"
5+
]

0 commit comments

Comments
 (0)