Skip to content

Commit 2f61319

Browse files
committed
⚙️ ci(release): implement cross-platform build
1 parent babd804 commit 2f61319

File tree

2 files changed

+51
-7
lines changed

2 files changed

+51
-7
lines changed

.github/workflows/release.yml

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@ on:
66
- '**'
77

88
jobs:
9-
build-linux-x86_64:
9+
build:
1010
runs-on: ubuntu-latest
1111

12+
strategy:
13+
matrix:
14+
target: [linux-x86_64, linux-aarch64, windows-x86_64]
15+
1216
steps:
1317
- name: Checkout repository
1418
uses: actions/checkout@v4
@@ -17,25 +21,37 @@ jobs:
1721
run: |
1822
sudo apt-get update
1923
sudo apt-get install -y g++ make libunistring-dev
24+
gcc-aarch64-linux-gnu \
25+
g++-aarch64-linux-gnu \
26+
gcc-mingw-w64-x86-64 \
27+
g++-mingw-w64-x86-64
28+
29+
- name: Resolve compiler for ${{ matrix.target }}
30+
id: compiler
31+
run: |
32+
COMPILER=$(./scripts/resolve_compiler.sh ${{ matrix.target }})
33+
echo "compiler=$COMPILER" >> "$GITHUB_OUTPUT"
2034
2135
- name: Build binary
22-
run: make BIN=build/strui-linux-x86_64
36+
run: |
37+
mkdir -p build
38+
make BIN=build/strui-${{ matrix.target }} CXX=${{ steps.compiler.outputs.compiler }}
2339
2440
- name: Package binary
2541
run: |
26-
TARGET=linux-x86_64
42+
TARGET=${{ matrix.target }}
2743
mkdir -p dist/$TARGET
28-
strip build/strui-$TARGET
44+
strip build/strui-$TARGET || true
2945
tar -czf dist/$TARGET/strui-$TARGET.tar.gz -C build strui-$TARGET
3046
sha256sum dist/$TARGET/strui-$TARGET.tar.gz > dist/$TARGET/strui-$TARGET.sha256
3147
3248
- name: Upload release assets
3349
uses: softprops/action-gh-release@v2
3450
with:
3551
files: |
36-
dist/linux-x86_64/strui-linux-x86_64.tar.gz
37-
dist/linux-x86_64/strui-linux-x86_64.sha256
52+
dist/${{ matrix.target }}/strui-${{ matrix.target }}.tar.gz
53+
dist/${{ matrix.target }}/strui-${{ matrix.target }}.sha256
3854
generate_release_notes: true
3955
env:
4056
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
41-
57+

scripts/resolve_compiler.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env bash
2+
3+
# Resolve the appropriate compiler based on the target platform.
4+
5+
set -e
6+
7+
TARGET="$1"
8+
9+
if [[ -z "$TARGET" ]]; then
10+
echo "Usage: $0 <target>" >&2
11+
exit 1
12+
fi
13+
14+
case "$TARGET" in
15+
linux-x86_64)
16+
echo "g++"
17+
;;
18+
linux-aarch64)
19+
echo "aarch64-linux-gnu-g++"
20+
;;
21+
windows-x86_64)
22+
echo "x86_64-w64-mingw32-g++"
23+
;;
24+
*)
25+
echo "❌ Unknown target: $TARGET" >&2
26+
exit 1
27+
;;
28+
esac

0 commit comments

Comments
 (0)