Skip to content

Commit 7a41b91

Browse files
syntacticallysimongdavies
authored andcommitted
[nix] Apply binutils wrapper to Rust's ld.lld
In Rust 1.90, rustc defaults to -fuse-ld=lld, which in turn uses a bundled-with-the-compiler ld.lld driver. That driver was not being properly wrapped, leading to generated executables failing to find libraries due to missing DT_RUNPATH entries. This commit modifies the mozilla Rust overlay to wrap the ld.lld driver. Signed-off-by: Simon Davies <[email protected]>
1 parent 805dec8 commit 7a41b91

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

flake.nix

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,43 @@
1515
rustChannelOf = args: let
1616
orig = pkgs.rustChannelOf args;
1717
patchRustPkg = pkg: (pkg.overrideAttrs (oA: {
18-
buildCommand = builtins.replaceStrings
18+
buildCommand = (builtins.replaceStrings
1919
[ "rustc,rustdoc" ]
2020
[ "rustc,rustdoc,clippy-driver,cargo-clippy" ]
21-
oA.buildCommand;
21+
oA.buildCommand) + (let
22+
wrapperPath = pkgs.path + "/pkgs/build-support/bintools-wrapper/ld-wrapper.sh";
23+
baseOut = pkgs.clangStdenv.cc.bintools.out;
24+
getStdenvAttrs = drv: (drv.overrideAttrs (oA: {
25+
passthru.origAttrs = oA;
26+
})).origAttrs;
27+
baseEnv = (getStdenvAttrs pkgs.clangStdenv.cc.bintools).env;
28+
baseSubstitutedWrapper = pkgs.replaceVars wrapperPath
29+
{
30+
inherit (baseEnv)
31+
shell coreutils_bin suffixSalt mktemp rm;
32+
use_response_file_by_default = "0";
33+
prog = null;
34+
out = null;
35+
};
36+
in ''
37+
# work around a bug in the overlay
38+
${oA.postInstall}
39+
40+
# copy over helper scripts that the wrapper needs
41+
(cd "${baseOut}"; find . -type f \( -name '*.sh' -or -name '*.bash' \) -print0) | while read -d $'\0' script; do
42+
mkdir -p "$out/$(dirname "$script")"
43+
substitute "${baseOut}/$script" "$out/$script" --replace-quiet "${baseOut}" "$out"
44+
done
45+
46+
# TODO: Work out how to make this work with cross builds
47+
ldlld="$out/lib/rustlib/${pkgs.clangStdenv.targetPlatform.config}/bin/gcc-ld/ld.lld";
48+
if [ -e "$ldlld" ]; then
49+
export prog="$(readlink -f "$ldlld")"
50+
rm "$ldlld"
51+
substitute ${baseSubstitutedWrapper} "$ldlld" --subst-var "out" --subst-var "prog"
52+
chmod +x "$ldlld"
53+
fi
54+
'');
2255
})) // {
2356
targetPlatforms = [ "x86_64-linux" ];
2457
badTargetPlatforms = [ ];
@@ -116,6 +149,7 @@
116149
jq
117150
jaq
118151
gdb
152+
zlib
119153
];
120154
buildInputs = [
121155
pango

0 commit comments

Comments
 (0)