Skip to content

Commit

Permalink
Always patch the interpreter of rustlib binaries
Browse files Browse the repository at this point in the history
When using `stable.toolchain`,
`lib/rustlib/x86_64-unknown-linux-gnu/bin/rust-lld` and other binaries
in the same directory are not patched, so they do not work. I'm not sure
exactly when Rust uses these, but it seems to break cross-compilation to
`wasm32-unknown-unknown`.

Fix it by generalizing the patching applied to the `rustc` component.
Replace the glob with a `find` invocation to avoid errors on components
that have a `lib` directory but no `lib/rustlib/*/bin`.
  • Loading branch information
marienz committed Dec 29, 2023
1 parent 72a5017 commit 9d4a490
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions lib/mk-toolchain.nix
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,27 @@ let
patchelf --set-rpath ${rpath} "$file" || true
fi
done
fi
if [ -d $out/libexec ]; then
for file in $(find $out/libexec -type f); do
for file in $(find $out/lib -path '*/bin/*' -type f); do
if isELF "$file"; then
patchelf \
--set-interpreter ${stdenv.cc.bintools.dynamicLinker} \
--set-rpath ${rpath} \
--set-rpath ${stdenv.cc.cc.lib}/lib:${rpath} \
"$file" || true
fi
done
fi
${optionalString (component == "rustc") ''
for file in $(find $out/lib/rustlib/*/bin -type f); do
if [ -d $out/libexec ]; then
for file in $(find $out/libexec -type f); do
if isELF "$file"; then
patchelf \
--set-interpreter ${stdenv.cc.bintools.dynamicLinker} \
--set-rpath ${stdenv.cc.cc.lib}/lib:${rpath} \
--set-rpath ${rpath} \
"$file" || true
fi
done
''}
fi
${optionalString (component == "llvm-tools-preview") ''
for file in $out/lib/rustlib/*/bin/*; do
Expand Down

0 comments on commit 9d4a490

Please sign in to comment.