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: 79156bf13a ("rustc: move crt-static default override to wrapper (#291829)")
This commit is contained in:
Alyssa Ross 2024-03-02 13:03:26 +01:00
parent 18bc3c64e6
commit 6f8fa05acf
No known key found for this signature in database
GPG Key ID: F9DBED4859B271C0
3 changed files with 8 additions and 7 deletions

View File

@ -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)}
''

View File

@ -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

View File

@ -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