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, stdenv, makeWrapper, wrapRustc, bash, curl, darwin, zlib
|
2021-10-17 10:28:08 +00:00
|
|
|
, autoPatchelfHook, gcc
|
2017-05-30 13:48:06 +00:00
|
|
|
, version
|
|
|
|
, src
|
|
|
|
, platform
|
|
|
|
, versionType
|
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
2021-01-22 11:25:31 +00:00
|
|
|
inherit (lib) optionalString;
|
2017-11-01 14:37:04 +00:00
|
|
|
inherit (darwin.apple_sdk.frameworks) Security;
|
2017-05-30 13:48:06 +00:00
|
|
|
|
|
|
|
bootstrapping = versionType == "bootstrap";
|
|
|
|
|
|
|
|
installComponents
|
|
|
|
= "rustc,rust-std-${platform}"
|
2018-06-05 19:54:27 +00:00
|
|
|
+ (optionalString bootstrapping ",cargo")
|
2017-05-30 13:48:06 +00:00
|
|
|
;
|
|
|
|
in
|
|
|
|
|
|
|
|
rec {
|
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
|
|
|
rustc-unwrapped = stdenv.mkDerivation {
|
2022-03-01 10:53:13 +00:00
|
|
|
pname = "rustc-${versionType}";
|
2017-05-30 13:48:06 +00:00
|
|
|
|
|
|
|
inherit version;
|
|
|
|
inherit src;
|
|
|
|
|
2021-01-22 11:25:31 +00:00
|
|
|
meta = with lib; {
|
2023-12-25 19:52:38 +00:00
|
|
|
homepage = "https://www.rust-lang.org/";
|
2023-12-18 15:26:33 +00:00
|
|
|
sourceProvenance = with sourceTypes; [ binaryNativeCode ];
|
2017-05-30 13:48:06 +00:00
|
|
|
description = "A safe, concurrent, practical language";
|
|
|
|
maintainers = with maintainers; [ qknight ];
|
|
|
|
license = [ licenses.mit licenses.asl20 ];
|
|
|
|
};
|
|
|
|
|
2021-10-17 10:28:08 +00:00
|
|
|
nativeBuildInputs = lib.optional (!stdenv.isDarwin) autoPatchelfHook;
|
2019-06-28 18:42:12 +00:00
|
|
|
buildInputs = [ bash ]
|
2021-10-17 10:28:08 +00:00
|
|
|
++ lib.optionals (!stdenv.isDarwin) [ gcc.cc.lib zlib ]
|
2021-01-22 11:25:31 +00:00
|
|
|
++ lib.optional stdenv.isDarwin Security;
|
2017-05-30 13:48:06 +00:00
|
|
|
|
2018-02-20 09:59:26 +00:00
|
|
|
postPatch = ''
|
|
|
|
patchShebangs .
|
|
|
|
'';
|
2017-10-31 06:37:15 +00:00
|
|
|
|
2017-05-30 13:48:06 +00:00
|
|
|
installPhase = ''
|
|
|
|
./install.sh --prefix=$out \
|
|
|
|
--components=${installComponents}
|
|
|
|
|
|
|
|
# Do NOT, I repeat, DO NOT use `wrapProgram` on $out/bin/rustc
|
|
|
|
# (or similar) here. It causes strange effects where rustc loads
|
|
|
|
# the wrong libraries in a bootstrap-build causing failures that
|
2018-06-12 23:01:24 +00:00
|
|
|
# are very hard to track down. For details, see
|
2017-05-30 13:48:06 +00:00
|
|
|
# https://github.com/rust-lang/rust/issues/34722#issuecomment-232164943
|
|
|
|
'';
|
2019-08-15 15:50:28 +00:00
|
|
|
|
2022-10-19 20:51:27 +00:00
|
|
|
# The strip tool in cctools 973.0.1 and up appears to break rlibs in the
|
|
|
|
# binaries. The lib.rmeta object inside the ar archive should contain an
|
|
|
|
# .rmeta section, but it is removed. Luckily, this doesn't appear to be an
|
|
|
|
# issue for Rust builds produced by Nix.
|
2023-07-13 14:10:46 +00:00
|
|
|
dontStrip = true;
|
2022-10-19 20:51:27 +00:00
|
|
|
|
2019-08-15 15:50:28 +00:00
|
|
|
setupHooks = ./setup-hook.sh;
|
2017-05-30 13:48:06 +00:00
|
|
|
};
|
|
|
|
|
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
|
|
|
rustc = wrapRustc rustc-unwrapped;
|
|
|
|
|
2019-08-13 21:52:01 +00:00
|
|
|
cargo = stdenv.mkDerivation {
|
2022-03-01 10:53:13 +00:00
|
|
|
pname = "cargo-${versionType}";
|
2017-05-30 13:48:06 +00:00
|
|
|
|
|
|
|
inherit version;
|
|
|
|
inherit src;
|
|
|
|
|
2021-01-22 11:25:31 +00:00
|
|
|
meta = with lib; {
|
2023-12-25 19:51:26 +00:00
|
|
|
homepage = "https://doc.rust-lang.org/cargo/";
|
2023-12-18 15:26:33 +00:00
|
|
|
sourceProvenance = with sourceTypes; [ binaryNativeCode ];
|
2023-12-25 19:51:26 +00:00
|
|
|
description = "The Rust package manager";
|
2017-05-30 13:48:06 +00:00
|
|
|
maintainers = with maintainers; [ qknight ];
|
|
|
|
license = [ licenses.mit licenses.asl20 ];
|
|
|
|
};
|
|
|
|
|
2021-10-17 10:28:08 +00:00
|
|
|
nativeBuildInputs = [ makeWrapper ]
|
|
|
|
++ lib.optional (!stdenv.isDarwin) autoPatchelfHook;
|
|
|
|
buildInputs = [ bash ]
|
|
|
|
++ lib.optional (!stdenv.isDarwin) gcc.cc.lib
|
|
|
|
++ lib.optional stdenv.isDarwin Security;
|
2017-11-01 14:37:04 +00:00
|
|
|
|
2018-02-20 09:59:26 +00:00
|
|
|
postPatch = ''
|
|
|
|
patchShebangs .
|
|
|
|
'';
|
2017-05-30 13:48:06 +00:00
|
|
|
|
|
|
|
installPhase = ''
|
2018-02-03 11:57:57 +00:00
|
|
|
patchShebangs ./install.sh
|
2017-05-30 13:48:06 +00:00
|
|
|
./install.sh --prefix=$out \
|
|
|
|
--components=cargo
|
|
|
|
|
|
|
|
wrapProgram "$out/bin/cargo" \
|
|
|
|
--suffix PATH : "${rustc}/bin"
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
}
|