From 6f8fa05acf5e6f6b4926631de2a9a8b8b544f30d Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Sat, 2 Mar 2024 13:03:26 +0100 Subject: [PATCH] wrapRustc: wrap rustdoc We need to set -crt-static on musl for rustdoc as well, so let's unify the wrappers. Ideally, rather than wrapping rustdoc, we'd have rustdoc use the wrapped rustc, but that's currently only possible with an unstable option (--test-builder). The options set by the wrapper, -C target-feature and --sysroot, are supported by both rustdoc and rustc, but other flags maybe not be supported by both, so I've introduced different environment variables (the existing NIX_RUSTFLAGS and a new NIX_RUSTDOCFLAGS) to allow those to be set independently. This fixes cargo-auditable in pkgsMusl., which broke because its doctests stopped working when -crt-static was moved to the wrapper. Fixes: 79156bf13ae7 ("rustc: move crt-static default override to wrapper (#291829)") --- pkgs/build-support/rust/rustc-wrapper/default.nix | 10 ++++++---- pkgs/build-support/rust/rustc-wrapper/rustc-wrapper.sh | 2 +- pkgs/development/compilers/rust/rustc.nix | 3 +-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/pkgs/build-support/rust/rustc-wrapper/default.nix b/pkgs/build-support/rust/rustc-wrapper/default.nix index 2b4a84e72b24..0defa6355029 100644 --- a/pkgs/build-support/rust/rustc-wrapper/default.nix +++ b/pkgs/build-support/rust/rustc-wrapper/default.nix @@ -6,7 +6,6 @@ runCommand "${rustc-unwrapped.pname}-wrapper-${rustc-unwrapped.version}" { inherit (rustc-unwrapped) outputs; env = { - prog = "${rustc-unwrapped}/bin/rustc"; sysroot = lib.optionalString (sysroot != null) "--sysroot ${sysroot}"; # Upstream rustc still assumes that musl = static[1]. The fix for @@ -42,9 +41,12 @@ runCommand "${rustc-unwrapped.pname}-wrapper-${rustc-unwrapped.version}" { } '' mkdir -p $out/bin ln -s ${rustc-unwrapped}/bin/* $out/bin - rm $out/bin/rustc - substituteAll ${./rustc-wrapper.sh} $out/bin/rustc - chmod +x $out/bin/rustc + rm $out/bin/{rustc,rustdoc} + prog=${rustc-unwrapped}/bin/rustc extraFlagsVar=NIX_RUSTFLAGS \ + substituteAll ${./rustc-wrapper.sh} $out/bin/rustc + prog=${rustc-unwrapped}/bin/rustdoc extraFlagsVar=NIX_RUSTDOCFLAGS \ + substituteAll ${./rustc-wrapper.sh} $out/bin/rustdoc + chmod +x $out/bin/{rustc,rustdoc} ${lib.concatMapStrings (output: "ln -s ${rustc-unwrapped.${output}} \$${output}\n") (lib.remove "out" rustc-unwrapped.outputs)} '' diff --git a/pkgs/build-support/rust/rustc-wrapper/rustc-wrapper.sh b/pkgs/build-support/rust/rustc-wrapper/rustc-wrapper.sh index 63e18be2e131..e33cc3e2a025 100644 --- a/pkgs/build-support/rust/rustc-wrapper/rustc-wrapper.sh +++ b/pkgs/build-support/rust/rustc-wrapper/rustc-wrapper.sh @@ -14,7 +14,7 @@ for arg; do done extraBefore=(@defaultArgs@ "${defaultSysroot[@]}") -extraAfter=($NIX_RUSTFLAGS) +extraAfter=($@extraFlagsVar@) # Optionally print debug info. if (( "${NIX_DEBUG:-0}" >= 1 )); then diff --git a/pkgs/development/compilers/rust/rustc.nix b/pkgs/development/compilers/rust/rustc.nix index 9235519eee1f..0a4a351b1cfd 100644 --- a/pkgs/development/compilers/rust/rustc.nix +++ b/pkgs/development/compilers/rust/rustc.nix @@ -175,8 +175,7 @@ in stdenv.mkDerivation (finalAttrs: { python ./x.py --keep-stage=0 --stage=1 install library/std mkdir -v $out/bin $doc $man - ln -s ${rustc.unwrapped}/bin/rustc $out/bin - makeWrapper ${rustc.unwrapped}/bin/rustdoc $out/bin/rustdoc --add-flags "--sysroot $out" + ln -s ${rustc.unwrapped}/bin/{rustc,rustdoc} $out/bin ln -s ${rustc.unwrapped}/lib/rustlib/{manifest-rust-std-,}${stdenv.hostPlatform.rust.rustcTargetSpec} $out/lib/rustlib/ echo rust-std-${stdenv.hostPlatform.rust.rustcTargetSpec} >> $out/lib/rustlib/components lndir ${rustc.doc} $doc