Skip to content

Commit

Permalink
Fix SYSROOT detection on latest nightly
Browse files Browse the repository at this point in the history
Rust changed the way the SYSROOT is determined in: rust-lang/rust#103660

Before this change the SYSROOT was determined based on the rustc
executable. Now it is determined based on the librustc_driver-*.so file.
This pr fixes the detection by copying the library to the derivation as
we have done it for the rustc executable.
  • Loading branch information
bkchr authored and nbp committed Jan 26, 2023
1 parent d38863d commit f6fe850
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions rust-overlay.nix
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,20 @@ let
if [ -e $target ]; then
cp --remove-destination "$(realpath -e $target)" $target
fi
# The SYSROOT is determined by using the librustc_driver-*.so.
# So, we need to point to the *.so files in our derivation.
chmod u+w $target
patchelf --set-rpath "$out/lib" $target || true

This comment has been minimized.

Copy link
@ggreif

ggreif Apr 25, 2023

This assumes that shared libraries are in ELF format, right? When running this on darwin I get

/nix/store/d26zy25lzkd9m9538alsh06ysq8vis1v-rust-src/lib/rustlib/src:
src: is a link instead of a directory
/private/tmp/nix-build-rust-1.67.0-nightly-2022-11-10-c1a859b25.drv-0/.attr-0l2nkwhif96f51f4amnlf414lhl4rv9vh8iffyp431v6s28gsr90: line 18: patchelf: command not found

patchelf is in nixpkgs, but I guess it won't do the right thing on .dylibs.

This comment has been minimized.

Copy link
@ggreif

ggreif Apr 25, 2023

This comment has been minimized.

Copy link
@ggreif

ggreif Apr 25, 2023

I can see two hits for the .dylib:

$ find /nix/store/7fz4ldg6zlq6f63cn0fdyfag4gvbfs8p-rust-1.67.0-nightly-2022-11-10-c1a859b25 -name "librustc_driver*"
/nix/store/7fz4ldg6zlq6f63cn0fdyfag4gvbfs8p-rust-1.67.0-nightly-2022-11-10-c1a859b25/lib/librustc_driver-bbce27cb88265850.dylib
$ find /nix/store/3lw1xvjm0kb2xa5kdw4qp1ibg3h7z4dl-rust/ -name "librustc_driver*"
/nix/store/3lw1xvjm0kb2xa5kdw4qp1ibg3h7z4dl-rust/lib/librustc_driver-bbce27cb88265850.dylib

the former is symlinked to the latter:

$ ls -l /nix/store/7fz4ldg6zlq6f63cn0fdyfag4gvbfs8p-rust-1.67.0-nightly-2022-11-10-c1a859b25/lib/librustc_driver-bbce27cb88265850.dylib
lrwxr-xr-x 1 root wheel 91 Jan  1  1970 /nix/store/7fz4ldg6zlq6f63cn0fdyfag4gvbfs8p-rust-1.67.0-nightly-2022-11-10-c1a859b25/lib/librustc_driver-bbce27cb88265850.dylib -> /nix/store/3lw1xvjm0kb2xa5kdw4qp1ibg3h7z4dl-rust/lib/librustc_driver-bbce27cb88265850.dylib

This comment has been minimized.

Copy link
@ggreif

ggreif Apr 25, 2023

What worked for me was hardlinking that specific .dylib:

sudo ln -f /nix/store/3lw1xvjm0kb2xa5kdw4qp1ibg3h7z4dl-rust/lib/librustc_driver-bbce27cb88265850.dylib /nix/store/7fz4ldg6zlq6f63cn0fdyfag4gvbfs8p-rust-1.67.0-nightly-2022-11-10-c1a859b25/lib/

This comment has been minimized.

Copy link
@ggreif

ggreif Apr 25, 2023

This is #304, basically.

done
# Here we copy the librustc_driver-*.so to our derivation.
# The SYSROOT is determined based on the path of this library.
if ls $out/lib/librustc_driver-*.so &> /dev/null; then
RUSTC_DRIVER_PATH=$(realpath -e $out/lib/librustc_driver-*.so)
rm $out/lib/librustc_driver-*.so

This comment has been minimized.

Copy link
@ggreif

ggreif Apr 25, 2023

I think a cp -f (or ln -f) below would make this rm unnecessary.

cp $RUSTC_DRIVER_PATH $out/lib/
fi
'';

# Export the manifest file as part of the nix-support files such
Expand Down

0 comments on commit f6fe850

Please sign in to comment.