2023-11-16 11:19:36 +00:00
|
|
|
{ lib, runCommand, rustc-unwrapped, sysroot ? null }:
|
rustc: add a compiler wrapper
We keep running into situations where we can't get the right
combination of rustc flags through build systems into rustc.
RUSTFLAGS is the only variable supported across build systems, but if
RUSTFLAGS is set, Cargo will ignore all other ways of specifying rustc
flags, including the target-specific ones, which we need to make
dynamic musl builds work. (This is why pkgsCross.musl64.crosvm is
currently broken — it works if you unset separateDebugInfo, which
causes RUSTFLAGS not to be set.)
So, we need to do the same thing we do for C and C++ compilers, and
add a compiler wrapper so we can inject the flags we need, regardless
of the build system.
Currently the wrapper only supports a single mechanism for injecting
flags — the NIX_RUSTFLAGS environment variable. As time goes on,
we'll probably want to add additional features, like target-specific
environment variables.
2023-10-18 11:02:45 +00:00
|
|
|
|
|
|
|
runCommand "${rustc-unwrapped.pname}-wrapper-${rustc-unwrapped.version}" {
|
|
|
|
preferLocalBuild = true;
|
|
|
|
strictDeps = true;
|
|
|
|
inherit (rustc-unwrapped) outputs;
|
|
|
|
|
|
|
|
env = {
|
2023-11-16 11:19:36 +00:00
|
|
|
sysroot = lib.optionalString (sysroot != null) "--sysroot ${sysroot}";
|
2024-02-28 22:10:07 +00:00
|
|
|
|
|
|
|
# Upstream rustc still assumes that musl = static[1]. The fix for
|
|
|
|
# this is to disable crt-static by default for non-static musl
|
|
|
|
# targets.
|
|
|
|
#
|
|
|
|
# Even though Cargo will build build.rs files for the build platform,
|
|
|
|
# cross-compiling _from_ musl appears to work fine, so we only need
|
|
|
|
# to do this when rustc's target platform is dynamically linked musl.
|
|
|
|
#
|
|
|
|
# [1]: https://github.com/rust-lang/compiler-team/issues/422
|
|
|
|
#
|
|
|
|
# WARNING: using defaultArgs is dangerous, as it will apply to all
|
|
|
|
# targets used by this compiler (host and target). This means
|
|
|
|
# that it can't be used to set arguments that should only be
|
|
|
|
# applied to the target. It's fine to do this for -crt-static,
|
|
|
|
# because rustc does not support +crt-static host platforms
|
|
|
|
# anyway.
|
|
|
|
defaultArgs = lib.optionalString
|
|
|
|
(with rustc-unwrapped.stdenv.targetPlatform; isMusl && !isStatic)
|
|
|
|
"-C target-feature=-crt-static";
|
rustc: add a compiler wrapper
We keep running into situations where we can't get the right
combination of rustc flags through build systems into rustc.
RUSTFLAGS is the only variable supported across build systems, but if
RUSTFLAGS is set, Cargo will ignore all other ways of specifying rustc
flags, including the target-specific ones, which we need to make
dynamic musl builds work. (This is why pkgsCross.musl64.crosvm is
currently broken — it works if you unset separateDebugInfo, which
causes RUSTFLAGS not to be set.)
So, we need to do the same thing we do for C and C++ compilers, and
add a compiler wrapper so we can inject the flags we need, regardless
of the build system.
Currently the wrapper only supports a single mechanism for injecting
flags — the NIX_RUSTFLAGS environment variable. As time goes on,
we'll probably want to add additional features, like target-specific
environment variables.
2023-10-18 11:02:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
passthru = {
|
2024-08-15 09:05:15 +00:00
|
|
|
inherit (rustc-unwrapped)
|
|
|
|
pname version src llvm llvmPackages
|
|
|
|
tier1TargetPlatforms targetPlatforms badTargetPlatforms;
|
rustc: add a compiler wrapper
We keep running into situations where we can't get the right
combination of rustc flags through build systems into rustc.
RUSTFLAGS is the only variable supported across build systems, but if
RUSTFLAGS is set, Cargo will ignore all other ways of specifying rustc
flags, including the target-specific ones, which we need to make
dynamic musl builds work. (This is why pkgsCross.musl64.crosvm is
currently broken — it works if you unset separateDebugInfo, which
causes RUSTFLAGS not to be set.)
So, we need to do the same thing we do for C and C++ compilers, and
add a compiler wrapper so we can inject the flags we need, regardless
of the build system.
Currently the wrapper only supports a single mechanism for injecting
flags — the NIX_RUSTFLAGS environment variable. As time goes on,
we'll probably want to add additional features, like target-specific
environment variables.
2023-10-18 11:02:45 +00:00
|
|
|
unwrapped = rustc-unwrapped;
|
|
|
|
};
|
|
|
|
|
|
|
|
meta = rustc-unwrapped.meta // {
|
|
|
|
description = "${rustc-unwrapped.meta.description} (wrapper script)";
|
|
|
|
priority = 10;
|
|
|
|
};
|
|
|
|
} ''
|
|
|
|
mkdir -p $out/bin
|
|
|
|
ln -s ${rustc-unwrapped}/bin/* $out/bin
|
2024-03-02 12:03:26 +00:00
|
|
|
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}
|
rustc: add a compiler wrapper
We keep running into situations where we can't get the right
combination of rustc flags through build systems into rustc.
RUSTFLAGS is the only variable supported across build systems, but if
RUSTFLAGS is set, Cargo will ignore all other ways of specifying rustc
flags, including the target-specific ones, which we need to make
dynamic musl builds work. (This is why pkgsCross.musl64.crosvm is
currently broken — it works if you unset separateDebugInfo, which
causes RUSTFLAGS not to be set.)
So, we need to do the same thing we do for C and C++ compilers, and
add a compiler wrapper so we can inject the flags we need, regardless
of the build system.
Currently the wrapper only supports a single mechanism for injecting
flags — the NIX_RUSTFLAGS environment variable. As time goes on,
we'll probably want to add additional features, like target-specific
environment variables.
2023-10-18 11:02:45 +00:00
|
|
|
${lib.concatMapStrings (output: "ln -s ${rustc-unwrapped.${output}} \$${output}\n")
|
|
|
|
(lib.remove "out" rustc-unwrapped.outputs)}
|
|
|
|
''
|