Skip to content

Commit

Permalink
Temp fix for oxalica#59
Browse files Browse the repository at this point in the history
  • Loading branch information
abbec committed Nov 23, 2021
1 parent 885ef5b commit a2fbfe4
Showing 1 changed file with 6 additions and 54 deletions.
60 changes: 6 additions & 54 deletions rust-overlay.nix
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,11 @@ let
# entire unpacked contents after just a little twiddling.
preferLocalBuild = true;

nativeBuildInputs = [ self.gnutar ];
nativeBuildInputs = [ self.gnutar self.autoPatchelfHook ];

# Ourselves have offset -1. In order to make these offset -1 dependencies of downstream derivation,
# they are offset 0 propagated.
propagatedBuildInputs =
propagatedNativeBuildInputs =
optional (pname == "rustc") [ self.stdenv.cc self.buildPackages.stdenv.cc ];
# This goes downstream packages' buildInputs.
depsTargetTargetPropagated =
Expand All @@ -226,60 +226,12 @@ let
runHook postInstall
'';

# This code is inspired by patchelf/setup-hook.sh to iterate over all binaries.
preFixup =
let
inherit (self.stdenv) hostPlatform;
in
optionalString hostPlatform.isLinux ''
setInterpreter() {
local dir="$1"
[ -e "$dir" ] || return 0
header "Patching interpreter of ELF executables and libraries in $dir"
local i
while IFS= read -r -d ''$'\0' i; do
if [[ "$i" =~ .build-id ]]; then continue; fi
if ! isELF "$i"; then continue; fi
echo "setting interpreter of $i"
if [[ -x "$i" ]]; then
# Handle executables
patchelf \
--set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
--set-rpath "${makeLibraryPath [ self.zlib ]}:$out/lib" \
"$i" || true
else
# Handle libraries
patchelf \
--set-rpath "${makeLibraryPath [ self.zlib ]}:$out/lib" \
"$i" || true
fi
done < <(find "$dir" -type f -print0)
}
setInterpreter $out
'' + optionalString (elem pname ["clippy-preview" "rls-preview" "miri-preview"]) ''
for f in $out/bin/*; do
${optionalString hostPlatform.isLinux ''
patchelf \
--set-rpath "${rustc}/lib:${makeLibraryPath [ self.zlib ]}:$out/lib" \
"$f" || true
''}
${optionalString hostPlatform.isDarwin ''
install_name_tool \
-add_rpath "${rustc}/lib" \
"$f" || true
''}
done
'' + optionalString (pname == "llvm-tools-preview" && hostPlatform.isLinux) ''
dir="$out/lib/rustlib/${toRustTarget hostPlatform}"
for f in "$dir"/bin/*; do
patchelf --set-rpath "$dir/lib" "$f" || true
done
'';

# rust-docs only contains tons of html files.
dontFixup = pname == "rust-docs";

preFixup = ''
addAutoPatchelfSearchPath $out/lib
'';

postFixup = ''
# Function moves well-known files from etc/
handleEtc() {
Expand Down

0 comments on commit a2fbfe4

Please sign in to comment.