Skip to content

Commit 6da7e0c

Browse files
committed
fix(nix): fall back to libiconv install_name_tool rewrite when dead_strip_dylibs doesn't strip it
1 parent 687df0c commit 6da7e0c

2 files changed

Lines changed: 16 additions & 7 deletions

File tree

‎nix/darwin-x64-package.nix‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ in
6363
# End-user Intel Macs have no /nix/store, so fail the build if the
6464
# binary links anything outside the macOS system paths.
6565
postInstall = ''
66-
if otool -L $out/bin/ccusage | tail -n +2 | awk '{print $1}' | grep -Ev '^(/usr/lib/|/System/Library/)'; then
66+
for lib in $(otool -L "$out/bin/ccusage" | tail -n +2 | awk '{print $1}' | grep -E '^/nix/store/[^/]+-libiconv-'); do
67+
install_name_tool -change "$lib" /usr/lib/libiconv.2.dylib "$out/bin/ccusage"
68+
done
69+
if otool -L "$out/bin/ccusage" | tail -n +2 | awk '{print $1}' | grep -Ev '^(/usr/lib/|/System/Library/)'; then
6770
echo "error: ccusage-darwin-x64 links dylibs that do not exist on end-user machines" >&2
6871
exit 1
6972
fi

‎package.nix‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,18 @@ craneLib.buildPackage (
5555
// {
5656
inherit cargoArtifacts;
5757
postInstall = lib.optionalString stdenv.isDarwin ''
58-
# ccusage does not use libiconv (no iconv symbols); it used to be pulled in
59-
# via buildInputs and recorded as an unused /nix/store dylib dependency
60-
# that crashed non-Nix Macs (#1251). With libiconv dropped the binary links
61-
# only system dylibs. Keep this gate so any future stray /nix/store dylib
62-
# fails the build instead of shipping. grep prints the offending entries.
63-
if otool -L $out/bin/ccusage | tail -n +2 | awk '{print $1}' | grep -Ev '^(/usr/lib/|/System/Library/)'; then
58+
# The nixpkgs Darwin stdenv cc-wrapper injects -liconv into the link even
59+
# when libiconv is absent from buildInputs. dead_strip_dylibs (set in
60+
# RUSTFLAGS) drops it locally, but in CI the cc-wrapper's -liconv may
61+
# arrive after the linker has resolved dead_strip_dylibs. Rewrite the
62+
# install name as a robust fallback so the safety gate below doesn't fail
63+
# on a dylib that carries no referenced symbols.
64+
for lib in $(otool -L "$out/bin/ccusage" | tail -n +2 | awk '{print $1}' | grep -E '^/nix/store/[^/]+-libiconv-'); do
65+
install_name_tool -change "$lib" /usr/lib/libiconv.2.dylib "$out/bin/ccusage"
66+
done
67+
# Every remaining dylib MUST be a macOS system path. grep prints the
68+
# offending entries when it matches — fail the build for any matches.
69+
if otool -L "$out/bin/ccusage" | tail -n +2 | awk '{print $1}' | grep -Ev '^(/usr/lib/|/System/Library/)'; then
6470
echo "error: ccusage links dylibs that do not exist on end-user machines" >&2
6571
exit 1
6672
fi

0 commit comments

Comments
 (0)