Skip to content

Commit c16a926

Browse files
committed
objdiff-cli: Build static binary & for more arches
1 parent a32d999 commit c16a926

File tree

1 file changed

+97
-10
lines changed

1 file changed

+97
-10
lines changed

.github/workflows/build.yaml

Lines changed: 97 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,19 @@ jobs:
2525
sudo apt-get -y install libgtk-3-dev
2626
- name: Checkout
2727
uses: actions/checkout@v4
28+
- name: Check git tag against Cargo version
29+
if: startsWith(github.ref, 'refs/tags/')
30+
shell: bash
31+
run: |
32+
set -eou
33+
version=$(grep '^version' Cargo.toml | awk -F' = ' '{print $2}' | tr -d '"')
34+
version="v$version"
35+
tag='${{github.ref}}'
36+
tag="${tag#refs/tags/}"
37+
if [ "$tag" != "$version" ]; then
38+
echo "::error::Git tag doesn't match the Cargo version! ($tag != $version)"
39+
exit 1
40+
fi
2841
- name: Setup Rust toolchain
2942
uses: dtolnay/rust-toolchain@stable
3043
with:
@@ -100,8 +113,82 @@ jobs:
100113
SCCACHE_GHA_ENABLED: "true"
101114
run: cargo test --release
102115

103-
build:
104-
name: Build
116+
build-cli:
117+
name: Build objdiff-cli
118+
env:
119+
CARGO_BIN_NAME: objdiff-cli
120+
strategy:
121+
matrix:
122+
include:
123+
- platform: ubuntu-latest
124+
target: x86_64-unknown-linux-musl
125+
name: linux-x86_64
126+
build: zigbuild
127+
features: default
128+
- platform: ubuntu-latest
129+
target: i686-unknown-linux-musl
130+
name: linux-i686
131+
build: zigbuild
132+
features: default
133+
- platform: ubuntu-latest
134+
target: aarch64-unknown-linux-musl
135+
name: linux-aarch64
136+
build: zigbuild
137+
features: default
138+
- platform: ubuntu-latest
139+
target: armv7-unknown-linux-musleabi
140+
name: linux-armv7l
141+
build: zigbuild
142+
features: default
143+
- platform: windows-latest
144+
target: x86_64-pc-windows-msvc
145+
name: windows-x86_64
146+
build: build
147+
features: default
148+
- platform: windows-latest
149+
target: aarch64-pc-windows-msvc
150+
name: windows-arm64
151+
build: build
152+
features: default
153+
- platform: macos-latest
154+
target: x86_64-apple-darwin
155+
name: macos-x86_64
156+
build: build
157+
features: default
158+
- platform: macos-latest
159+
target: aarch64-apple-darwin
160+
name: macos-arm64
161+
build: build
162+
features: default
163+
fail-fast: false
164+
runs-on: ${{ matrix.platform }}
165+
steps:
166+
- name: Checkout
167+
uses: actions/checkout@v4
168+
- name: Install cargo-zigbuild
169+
if: matrix.build == 'zigbuild'
170+
run: pip install ziglang==0.13.0 cargo-zigbuild==0.19.1
171+
- name: Setup Rust toolchain
172+
uses: dtolnay/rust-toolchain@stable
173+
with:
174+
targets: ${{ matrix.target }}
175+
- name: Cargo build
176+
run: >
177+
cargo ${{ matrix.build }} --profile ${{ env.BUILD_PROFILE }} --target ${{ matrix.target }}
178+
--bin ${{ env.CARGO_BIN_NAME }} --features ${{ matrix.features }}
179+
- name: Upload artifacts
180+
uses: actions/upload-artifact@v4
181+
with:
182+
name: ${{ env.CARGO_BIN_NAME }}-${{ matrix.name }}
183+
path: |
184+
${{ env.CARGO_TARGET_DIR }}/${{ matrix.target }}/${{ env.BUILD_PROFILE }}/${{ env.CARGO_BIN_NAME }}
185+
${{ env.CARGO_TARGET_DIR }}/${{ matrix.target }}/${{ env.BUILD_PROFILE }}/${{ env.CARGO_BIN_NAME }}.exe
186+
if-no-files-found: error
187+
188+
build-gui:
189+
name: Build objdiff-gui
190+
env:
191+
CARGO_BIN_NAME: objdiff
105192
strategy:
106193
matrix:
107194
include:
@@ -144,23 +231,21 @@ jobs:
144231
SCCACHE_GHA_ENABLED: "true"
145232
run: >
146233
cargo build --profile ${{ env.BUILD_PROFILE }} --target ${{ matrix.target }}
147-
--bin objdiff-cli --bin objdiff --features ${{ matrix.features }}
234+
--bin ${{ env.CARGO_BIN_NAME }} --features ${{ matrix.features }}
148235
- name: Upload artifacts
149236
uses: actions/upload-artifact@v4
150237
with:
151-
name: ${{ matrix.name }}
238+
name: ${{ env.CARGO_BIN_NAME }}-${{ matrix.name }}
152239
path: |
153-
${{ env.CARGO_TARGET_DIR }}/${{ matrix.target }}/${{ env.BUILD_PROFILE }}/objdiff-cli
154-
${{ env.CARGO_TARGET_DIR }}/${{ matrix.target }}/${{ env.BUILD_PROFILE }}/objdiff-cli.exe
155-
${{ env.CARGO_TARGET_DIR }}/${{ matrix.target }}/${{ env.BUILD_PROFILE }}/objdiff
156-
${{ env.CARGO_TARGET_DIR }}/${{ matrix.target }}/${{ env.BUILD_PROFILE }}/objdiff.exe
240+
${{ env.CARGO_TARGET_DIR }}/${{ matrix.target }}/${{ env.BUILD_PROFILE }}/${{ env.CARGO_BIN_NAME }}
241+
${{ env.CARGO_TARGET_DIR }}/${{ matrix.target }}/${{ env.BUILD_PROFILE }}/${{ env.CARGO_BIN_NAME }}.exe
157242
if-no-files-found: error
158243

159244
release:
160245
name: Release
161246
if: startsWith(github.ref, 'refs/tags/')
162247
runs-on: ubuntu-latest
163-
needs: [ build ]
248+
needs: [ check, build-cli, build-gui ]
164249
permissions:
165250
contents: write
166251
steps:
@@ -183,7 +268,9 @@ jobs:
183268
else
184269
ext=".$ext"
185270
fi
186-
dst="../out/${name}-${dir%/}${ext}"
271+
arch="${dir%/}" # remove trailing slash
272+
arch="${arch##"$name-"}" # remove bin name
273+
dst="../out/${name}-${arch}${ext}"
187274
mv "$file" "$dst"
188275
done
189276
done

0 commit comments

Comments
 (0)