Skip to content

Commit af76a35

Browse files
committed
fix(ci): use zig toolchain end-to-end for musl z3 builds
Configure Linux musl release jobs to compile and link with zig wrappers, normalize cc-rs target flags, disable Rust self-contained musl linking, and link z3 against libc++ via CXXSTDLIB=c++. This avoids glibc symbol leaks from host g++ while keeping the build off Docker.
1 parent fd17d8d commit af76a35

File tree

3 files changed

+61
-40
lines changed

3 files changed

+61
-40
lines changed

.github/workflows/release-dev.yml

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,8 @@ jobs:
150150
# ---------------------------------------------------------------------------
151151
# Build CLI binaries (Linux musl — static, native on each arch)
152152
#
153-
# Builds run directly on the CI host (glibc Ubuntu). The system g++ is
154-
# used for C++ compilation (z3) with _FORTIFY_SOURCE disabled to avoid
155-
# glibc-specific hardened symbols that do not exist in musl.
153+
# Builds run directly on the CI host (glibc Ubuntu). Zig provides musl
154+
# C/C++ toolchains for bundled-z3 and ring, and is also used as the linker.
156155
# ---------------------------------------------------------------------------
157156
build-cli-linux:
158157
name: Build CLI (Linux ${{ matrix.arch }})
@@ -163,9 +162,11 @@ jobs:
163162
- arch: amd64
164163
runner: build-amd64
165164
target: x86_64-unknown-linux-musl
165+
zig_target: x86_64-linux-musl
166166
- arch: arm64
167167
runner: build-arm64
168168
target: aarch64-unknown-linux-musl
169+
zig_target: aarch64-linux-musl
169170
runs-on: ${{ matrix.runner }}
170171
timeout-minutes: 60
171172
container:
@@ -202,27 +203,36 @@ jobs:
202203
- name: Add Rust musl target
203204
run: mise x -- rustup target add ${{ matrix.target }}
204205

205-
- name: Set up musl C++ wrapper
206+
- name: Set up zig musl wrappers
206207
run: |
207208
set -euo pipefail
208-
# System g++ with _FORTIFY_SOURCE disabled. FORTIFY_SOURCE makes
209-
# g++ emit glibc-specific hardened calls (__printf_chk, __memcpy_chk)
210-
# that do not exist in musl, causing linker failures. Disabling it
211-
# produces standard POSIX calls that resolve against musl.
212-
printf '#!/bin/sh\nexec g++ -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0 "$@"\n' \
213-
> /usr/local/bin/musl-g++
214-
chmod +x /usr/local/bin/musl-g++
215-
216-
# Point both CC and CXX at wrappers that disable _FORTIFY_SOURCE.
217-
# CC must be set explicitly or cc-rs probes for aarch64-linux-musl-gcc
218-
# which does not exist on the Ubuntu CI host.
219-
printf '#!/bin/sh\nexec cc -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0 "$@"\n' \
220-
> /usr/local/bin/musl-cc
221-
chmod +x /usr/local/bin/musl-cc
209+
ZIG="$(mise which zig)"
210+
ZIG_TARGET="${{ matrix.zig_target }}"
211+
mkdir -p /tmp/zig-musl
212+
213+
# cc-rs injects --target=<rust-triple> (for example
214+
# aarch64-unknown-linux-musl), which zig does not parse. Strip any
215+
# caller-provided --target and use the wrapper's zig-native target.
216+
for tool in cc c++; do
217+
printf '#!/bin/bash\nargs=()\nfor arg in "$@"; do\n case "$arg" in\n --target=*) ;;\n *) args+=("$arg") ;;\n esac\ndone\nexec "%s" %s --target=%s "${args[@]}"\n' \
218+
"$ZIG" "$tool" "$ZIG_TARGET" > "/tmp/zig-musl/${tool}"
219+
chmod +x "/tmp/zig-musl/${tool}"
220+
done
222221
223222
TARGET_ENV=$(echo "${{ matrix.target }}" | tr '-' '_')
224-
echo "CC_${TARGET_ENV}=/usr/local/bin/musl-cc" >> "$GITHUB_ENV"
225-
echo "CXX_${TARGET_ENV}=/usr/local/bin/musl-g++" >> "$GITHUB_ENV"
223+
TARGET_ENV_UPPER=${TARGET_ENV^^}
224+
225+
# Use zig for C/C++ compilation and final linking.
226+
echo "CC_${TARGET_ENV}=/tmp/zig-musl/cc" >> "$GITHUB_ENV"
227+
echo "CXX_${TARGET_ENV}=/tmp/zig-musl/c++" >> "$GITHUB_ENV"
228+
echo "CARGO_TARGET_${TARGET_ENV_UPPER}_LINKER=/tmp/zig-musl/cc" >> "$GITHUB_ENV"
229+
230+
# Let zig own CRT/startfiles to avoid duplicate _start symbols.
231+
echo "CARGO_TARGET_${TARGET_ENV_UPPER}_RUSTFLAGS=-Clink-self-contained=no" >> "$GITHUB_ENV"
232+
233+
# z3 built with zig c++ uses libc++ symbols (std::__1::*).
234+
# Override z3-sys default (stdc++) so Rust links the matching runtime.
235+
echo "CXXSTDLIB=c++" >> "$GITHUB_ENV"
226236
227237
- name: Scope workspace to CLI crates
228238
run: |

.github/workflows/release-tag.yml

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,8 @@ jobs:
171171
# ---------------------------------------------------------------------------
172172
# Build CLI binaries (Linux musl — static, native on each arch)
173173
#
174-
# Builds run directly on the CI host (glibc Ubuntu). The system g++ is
175-
# used for C++ compilation (z3) with _FORTIFY_SOURCE disabled to avoid
176-
# glibc-specific hardened symbols that do not exist in musl.
174+
# Builds run directly on the CI host (glibc Ubuntu). Zig provides musl
175+
# C/C++ toolchains for bundled-z3 and ring, and is also used as the linker.
177176
# ---------------------------------------------------------------------------
178177
build-cli-linux:
179178
name: Build CLI (Linux ${{ matrix.arch }})
@@ -184,9 +183,11 @@ jobs:
184183
- arch: amd64
185184
runner: build-amd64
186185
target: x86_64-unknown-linux-musl
186+
zig_target: x86_64-linux-musl
187187
- arch: arm64
188188
runner: build-arm64
189189
target: aarch64-unknown-linux-musl
190+
zig_target: aarch64-linux-musl
190191
runs-on: ${{ matrix.runner }}
191192
timeout-minutes: 60
192193
container:
@@ -224,27 +225,36 @@ jobs:
224225
- name: Add Rust musl target
225226
run: mise x -- rustup target add ${{ matrix.target }}
226227

227-
- name: Set up musl C++ wrapper
228+
- name: Set up zig musl wrappers
228229
run: |
229230
set -euo pipefail
230-
# System g++ with _FORTIFY_SOURCE disabled. FORTIFY_SOURCE makes
231-
# g++ emit glibc-specific hardened calls (__printf_chk, __memcpy_chk)
232-
# that do not exist in musl, causing linker failures. Disabling it
233-
# produces standard POSIX calls that resolve against musl.
234-
printf '#!/bin/sh\nexec g++ -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0 "$@"\n' \
235-
> /usr/local/bin/musl-g++
236-
chmod +x /usr/local/bin/musl-g++
237-
238-
# Point both CC and CXX at wrappers that disable _FORTIFY_SOURCE.
239-
# CC must be set explicitly or cc-rs probes for aarch64-linux-musl-gcc
240-
# which does not exist on the Ubuntu CI host.
241-
printf '#!/bin/sh\nexec cc -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0 "$@"\n' \
242-
> /usr/local/bin/musl-cc
243-
chmod +x /usr/local/bin/musl-cc
231+
ZIG="$(mise which zig)"
232+
ZIG_TARGET="${{ matrix.zig_target }}"
233+
mkdir -p /tmp/zig-musl
234+
235+
# cc-rs injects --target=<rust-triple> (for example
236+
# aarch64-unknown-linux-musl), which zig does not parse. Strip any
237+
# caller-provided --target and use the wrapper's zig-native target.
238+
for tool in cc c++; do
239+
printf '#!/bin/bash\nargs=()\nfor arg in "$@"; do\n case "$arg" in\n --target=*) ;;\n *) args+=("$arg") ;;\n esac\ndone\nexec "%s" %s --target=%s "${args[@]}"\n' \
240+
"$ZIG" "$tool" "$ZIG_TARGET" > "/tmp/zig-musl/${tool}"
241+
chmod +x "/tmp/zig-musl/${tool}"
242+
done
244243
245244
TARGET_ENV=$(echo "${{ matrix.target }}" | tr '-' '_')
246-
echo "CC_${TARGET_ENV}=/usr/local/bin/musl-cc" >> "$GITHUB_ENV"
247-
echo "CXX_${TARGET_ENV}=/usr/local/bin/musl-g++" >> "$GITHUB_ENV"
245+
TARGET_ENV_UPPER=${TARGET_ENV^^}
246+
247+
# Use zig for C/C++ compilation and final linking.
248+
echo "CC_${TARGET_ENV}=/tmp/zig-musl/cc" >> "$GITHUB_ENV"
249+
echo "CXX_${TARGET_ENV}=/tmp/zig-musl/c++" >> "$GITHUB_ENV"
250+
echo "CARGO_TARGET_${TARGET_ENV_UPPER}_LINKER=/tmp/zig-musl/cc" >> "$GITHUB_ENV"
251+
252+
# Let zig own CRT/startfiles to avoid duplicate _start symbols.
253+
echo "CARGO_TARGET_${TARGET_ENV_UPPER}_RUSTFLAGS=-Clink-self-contained=no" >> "$GITHUB_ENV"
254+
255+
# z3 built with zig c++ uses libc++ symbols (std::__1::*).
256+
# Override z3-sys default (stdc++) so Rust links the matching runtime.
257+
echo "CXXSTDLIB=c++" >> "$GITHUB_ENV"
248258
249259
- name: Scope workspace to CLI crates
250260
run: |

mise.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ helm = "4.1.1"
2323
"ubi:mozilla/sccache" = { version = "0.14.0", matching = "sccache-v" }
2424
"ubi:anchore/syft" = { version = "1.42.3", matching = "syft_" }
2525
"ubi:EmbarkStudios/cargo-about" = "0.8.4"
26+
zig = "0.14.1"
2627

2728
[env]
2829
_.path = ["{{config_root}}/scripts/bin"]

0 commit comments

Comments
 (0)