Skip to content

Commit 2a8a93f

Browse files
committed
ci: build release binaries with Nix
Refs #1683 Signed-off-by: Simon Scatton <[email protected]>
1 parent 2335177 commit 2a8a93f

2 files changed

Lines changed: 144 additions & 0 deletions

File tree

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
name: Build Binaries
5+
6+
on:
7+
workflow_call:
8+
inputs:
9+
checkout-ref:
10+
required: false
11+
type: string
12+
default: ""
13+
secrets:
14+
CACHIX_AUTH_TOKEN:
15+
required: true
16+
workflow_dispatch:
17+
18+
permissions:
19+
contents: read
20+
21+
jobs:
22+
version:
23+
name: Version
24+
runs-on: ubuntu-latest
25+
timeout-minutes: 5
26+
outputs:
27+
cargo: ${{ steps.version.outputs.cargo }}
28+
steps:
29+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
30+
with:
31+
ref: ${{ inputs['checkout-ref'] || github.sha }}
32+
fetch-depth: 0
33+
34+
- name: Compute version
35+
id: version
36+
shell: bash
37+
run: |
38+
cargo="$(python3 tasks/scripts/release.py get-version --cargo)"
39+
echo "cargo=$cargo" >> "$GITHUB_OUTPUT"
40+
41+
binary:
42+
name: ${{ matrix.binary }} (${{ matrix.triple }})
43+
needs: version
44+
strategy:
45+
matrix:
46+
include:
47+
- binary: openshell
48+
triple: x86_64-unknown-linux-musl
49+
runner: linux-amd64-cpu8
50+
dev_shell: .#devShells.x86_64-linux.musl
51+
- binary: openshell
52+
triple: aarch64-unknown-linux-musl
53+
runner: linux-arm64-cpu8
54+
dev_shell: .#devShells.aarch64-linux.musl
55+
- binary: openshell
56+
triple: aarch64-apple-darwin
57+
runner: macos-15-xlarge
58+
dev_shell: .#devShells.aarch64-darwin.default
59+
- binary: openshell-gateway
60+
triple: x86_64-unknown-linux-gnu
61+
runner: linux-amd64-cpu8
62+
dev_shell: .#devShells.x86_64-linux.glibc-2-28
63+
interpreter: /lib64/ld-linux-x86-64.so.2
64+
- binary: openshell-gateway
65+
triple: aarch64-unknown-linux-gnu
66+
runner: linux-arm64-cpu8
67+
dev_shell: .#devShells.aarch64-linux.glibc-2-28
68+
interpreter: /lib/ld-linux-aarch64.so.1
69+
- binary: openshell-gateway
70+
triple: aarch64-apple-darwin
71+
runner: macos-15-xlarge
72+
dev_shell: .#devShells.aarch64-darwin.default
73+
runs-on: ${{ matrix.runner }}
74+
timeout-minutes: 60
75+
defaults:
76+
run:
77+
shell: nix develop ${{ matrix.dev_shell }} -c bash -euo pipefail {0}
78+
steps:
79+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
80+
with:
81+
ref: ${{ inputs['checkout-ref'] || github.sha }}
82+
83+
- uses: cachix/install-nix-action@13d8dd58da0234aa297dedd986986ccb8e7f3e24 # v31.11.1
84+
with:
85+
github_access_token: ${{ secrets.GITHUB_TOKEN }}
86+
87+
- uses: cachix/cachix-action@5f2d7c5294214f71b873db4b969586b980625e71 # v17
88+
with:
89+
name: openshell
90+
authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
91+
92+
- name: Cache Rust artifacts
93+
uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2
94+
with:
95+
shared-key: binaries-${{ matrix.binary }}-${{ matrix.triple }}
96+
cache-on-failure: "true"
97+
cache-workspace-crates: "true"
98+
cache-bin: "false"
99+
cmd-format: nix develop ${{ matrix.dev_shell }} -c {0}
100+
101+
- name: Set version
102+
run: sed -i 's/^version = "0\.0\.0"$/version = "${{ needs.version.outputs.cargo }}"/' Cargo.toml
103+
104+
- name: Build ${{ matrix.binary }}
105+
run: GIT_DIR=/nonexistent cargo auditable build --release --bin "${{ matrix.binary }}"
106+
107+
- name: Verify ${{ matrix.binary }}
108+
run: |
109+
# Confirm the binary runs and reports the expected name.
110+
target/release/${{ matrix.binary }} --version | grep -q '^${{ matrix.binary }} '
111+
# Confirm Syft can decode the embedded cargo-auditable metadata.
112+
SYFT_CHECK_FOR_APP_UPDATE=false syft "file:target/release/${{ matrix.binary }}" -o cyclonedx-json | grep 'pkg:cargo/' > /dev/null
113+
114+
- name: Verify static linkage
115+
if: endsWith(matrix.triple, '-linux-musl')
116+
run: tasks/scripts/verify-static-binary.sh target/release/${{ matrix.binary }}
117+
118+
- name: Normalize Linux dynamic binary
119+
if: endsWith(matrix.triple, '-linux-gnu')
120+
run: |
121+
binary=target/release/${{ matrix.binary }}
122+
# Remove Nix store paths so the binary can run on other distributions.
123+
patchelf --set-interpreter "${{ matrix.interpreter }}" --remove-rpath "$binary"
124+
# Z3 must be embedded instead of loaded from the target system.
125+
test -z "$(patchelf --print-needed "$binary" | grep '^libz3')"
126+
# Reject symbols introduced after glibc 2.28.
127+
tasks/scripts/verify-glibc-symbols.sh 2.28 "$binary"
128+
129+
- name: Package ${{ matrix.binary }}
130+
run: |
131+
mkdir -p artifacts
132+
install -m0755 target/release/${{ matrix.binary }} artifacts/${{ matrix.binary }}
133+
tar -czf artifacts/${{ matrix.binary }}-${{ matrix.triple }}.tar.gz -C artifacts ${{ matrix.binary }}
134+
135+
- name: Upload ${{ matrix.binary }}
136+
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
137+
with:
138+
name: ${{ matrix.binary }}-${{ matrix.triple }}
139+
path: artifacts/*.tar.gz
140+
retention-days: 5
141+
if-no-files-found: error

‎flake.nix‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,17 @@
4747
testGuestPkgs = import nixpkgs-test-guest { inherit system; };
4848
commonDevShellPackages = with pkgs; [
4949
actionlint
50+
cargo-auditable
5051
cargo-deny
5152
cargo-nextest
5253
# Assemble Debian artifacts on macOS and Linux.
5354
dpkg
55+
git
5456
# Required to find packages.
5557
pkg-config
5658
# Coverage.
5759
lcov
60+
syft
5861
uv
5962
zizmor
6063
];

0 commit comments

Comments
 (0)