Skip to content

Commit 176137f

Browse files
ewelsclaude
andauthored
fix: use build.rustflags config to avoid SIGILL in build scripts (#90)
RUSTFLAGS applies to all rustc invocations including build scripts. When targeting x86-64-v4 (AVX-512), the libz-sys build script was compiled with AVX-512 instructions and crashed on CI runners that lack AVX-512 support. Switch to cargo --config build.rustflags which only applies to target crate compilation, not host build scripts. Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent b7a47eb commit 176137f

3 files changed

Lines changed: 21 additions & 14 deletions

File tree

.github/workflows/ci.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
os: ubuntu-latest
2424
- name: linux-x86_64-v3
2525
os: ubuntu-latest
26-
rustflags: "-C target-cpu=x86-64-v3"
26+
target_cpu: x86-64-v3
2727
- name: macos-aarch64
2828
os: macos-latest
2929
steps:
@@ -46,14 +46,18 @@ jobs:
4646
- uses: Swatinem/rust-cache@c19371144df3bb44fab255c43d04cbc2ab54d1c4 # ratchet:Swatinem/rust-cache@v2.9.1
4747

4848
- name: Build
49-
run: cargo build --release
49+
run: >
50+
cargo build --release
51+
${TARGET_CPU:+--config "build.rustflags=['-C', 'target-cpu=$TARGET_CPU']"}
5052
env:
51-
RUSTFLAGS: ${{ matrix.rustflags || '' }}
53+
TARGET_CPU: ${{ matrix.target_cpu || '' }}
5254

5355
- name: Test
54-
run: cargo test --release
56+
run: >
57+
cargo test --release
58+
${TARGET_CPU:+--config "build.rustflags=['-C', 'target-cpu=$TARGET_CPU']"}
5559
env:
56-
RUSTFLAGS: ${{ matrix.rustflags || '' }}
60+
TARGET_CPU: ${{ matrix.target_cpu || '' }}
5761

5862
fmt:
5963
name: Formatting

.github/workflows/release.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ jobs:
6565
- name: linux-x86_64-v3
6666
os: ubuntu-latest
6767
target: x86_64-unknown-linux-gnu
68-
rustflags: "-C target-cpu=x86-64-v3"
68+
target_cpu: x86-64-v3
6969

7070
# Linux x86_64 with AVX-512 (x86-64-v4)
7171
- name: linux-x86_64-v4
7272
os: ubuntu-latest
7373
target: x86_64-unknown-linux-gnu
74-
rustflags: "-C target-cpu=x86-64-v4"
74+
target_cpu: x86-64-v4
7575

7676
# Linux aarch64 (native arm64 runner, baseline)
7777
- name: linux-aarch64
@@ -82,7 +82,7 @@ jobs:
8282
- name: linux-aarch64-neoverse-v1
8383
os: ubuntu-24.04-arm
8484
target: aarch64-unknown-linux-gnu
85-
rustflags: "-C target-cpu=neoverse-v1"
85+
target_cpu: neoverse-v1
8686

8787
# macOS x86_64 (cross-compiled on Apple Silicon runner)
8888
- name: macos-x86_64
@@ -98,7 +98,7 @@ jobs:
9898
- name: macos-aarch64-apple-m1
9999
os: macos-latest
100100
target: aarch64-apple-darwin
101-
rustflags: "-C target-cpu=apple-m1"
101+
target_cpu: apple-m1
102102

103103
steps:
104104
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # ratchet:actions/checkout@v6.0.2
@@ -122,9 +122,11 @@ jobs:
122122
run: brew install bzip2 xz
123123

124124
- name: Build
125-
run: cargo build --release --target ${{ matrix.target }}
125+
run: >
126+
cargo build --release --target ${{ matrix.target }}
127+
${TARGET_CPU:+--config "build.rustflags=['-C', 'target-cpu=$TARGET_CPU']"}
126128
env:
127-
RUSTFLAGS: ${{ matrix.rustflags || '' }}
129+
TARGET_CPU: ${{ matrix.target_cpu || '' }}
128130

129131
- name: Package
130132
id: package

Dockerfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ COPY Cargo.toml Cargo.lock build.rs ./
2121
COPY cpp/ cpp/
2222
COPY src/ src/
2323

24-
RUN RUSTFLAGS="${CPU_TARGET:+-C target-cpu=$CPU_TARGET}" \
25-
GIT_SHORT_HASH="${GIT_SHORT_HASH}" \
26-
cargo build --release && strip target/release/rustqc
24+
RUN GIT_SHORT_HASH="${GIT_SHORT_HASH}" \
25+
cargo build --release \
26+
${CPU_TARGET:+--config "build.rustflags=['-C', 'target-cpu=$CPU_TARGET']"} \
27+
&& strip target/release/rustqc
2728

2829
# ---- Runtime stage ----
2930
FROM debian:bookworm-slim

0 commit comments

Comments
 (0)