Skip to content

Commit 548d181

Browse files
committed
fix(tmachine): link libstdc++ statically and verify static musl binaries
Replace the library search-order workaround in the musl toolchain with an explicit request: build-artifacts-binaries sets CXXSTDLIB=static:-bundle=stdc++ for its musl build, so z3-sys asks for a static libstdc++ on every build host. CXXSTDLIB applies to every target and Darwin has no libstdc++, so it cannot go into the shared toolchain environment. The bundled form, static=stdc++, fails because rustc cannot find libstdc++.a on its own search path. Run tasks/scripts/verify-static-binary.sh on the musl CLI, sandbox and prover, as the release does, so a dynamically linked binary fails the local build. Signed-off-by: Evan Lezar <[email protected]>
1 parent 902ee65 commit 548d181

2 files changed

Lines changed: 16 additions & 9 deletions

File tree

‎nix/toolchain/linux.nix‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,7 @@ let
2727
"-B${sysroot}/usr/lib"
2828
"-L${sysroot}/usr/lib"
2929
]
30-
++ pkgs.lib.optionals isMusl (
31-
# z3-sys asks for a dynamic libstdc++. Search the directory holding only
32-
# the static archive first so musl binaries stay fully static; otherwise
33-
# the compiler wrapper can resolve libstdc++.so and produce a static
34-
# executable that needs a shared library and crashes at startup.
35-
[ "-L${stdenv.cc.cc}/${stdenv.hostPlatform.config}/lib" ]
36-
++ map (package: "-L${pkgs.lib.getLib package}/lib") packages
37-
);
30+
++ pkgs.lib.optionals isMusl (map (package: "-L${pkgs.lib.getLib package}/lib") packages);
3831
runtimeFlags = pkgs.lib.optionals (!isMusl) [
3932
"-Wl,--dynamic-linker=${
4033
{

‎tests/artifacts.nix‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,20 +214,34 @@ rec {
214214
binaries = pkgs.writeShellApplication {
215215
name = "build-artifacts-binaries";
216216
runtimeInputs = [
217+
pkgs.binutils-unwrapped
217218
pkgs.coreutils
219+
pkgs.file
220+
pkgs.gawk
218221
pkgs.git
222+
pkgs.gnugrep
223+
pkgs.gnused
219224
rustToolchain
220225
];
221226
runtimeEnv = toolchainEnv;
222227
text = ''
223228
root=$(git rev-parse --show-toplevel)
224229
cd "$root"
225230
226-
cargo build --target ${muslToolchain.target} \
231+
# z3-sys links libstdc++ dynamically unless CXXSTDLIB says otherwise, and
232+
# the musl binaries must be fully static. CXXSTDLIB applies to every
233+
# target, so set it only for the musl build: Darwin has no libstdc++.
234+
CXXSTDLIB=static:-bundle=stdc++ cargo build --target ${muslToolchain.target} \
227235
-p openshell-cli \
228236
-p openshell-sandbox \
229237
-p openshell-prover-cli
230238
239+
# Fail as the release does if a musl binary is not fully static.
240+
tasks/scripts/verify-static-binary.sh \
241+
target/${muslToolchain.target}/debug/openshell \
242+
target/${muslToolchain.target}/debug/openshell-sandbox \
243+
target/${muslToolchain.target}/debug/openshell-prover
244+
231245
cargo build --target ${gnuToolchain.target} \
232246
-p openshell-gateway \
233247
-p openshell-supervisor

0 commit comments

Comments
 (0)