mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-13 21:25:30 +03:00

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.
98 lines
2.6 KiB
Nix
98 lines
2.6 KiB
Nix
{ lib, stdenv, makeWrapper, wrapRustc, bash, curl, darwin, zlib
|
|
, autoPatchelfHook, gcc
|
|
, version
|
|
, src
|
|
, platform
|
|
, versionType
|
|
}:
|
|
|
|
let
|
|
inherit (lib) optionalString;
|
|
inherit (darwin.apple_sdk.frameworks) Security;
|
|
|
|
bootstrapping = versionType == "bootstrap";
|
|
|
|
installComponents
|
|
= "rustc,rust-std-${platform}"
|
|
+ (optionalString bootstrapping ",cargo")
|
|
;
|
|
in
|
|
|
|
rec {
|
|
rustc-unwrapped = stdenv.mkDerivation {
|
|
pname = "rustc-${versionType}";
|
|
|
|
inherit version;
|
|
inherit src;
|
|
|
|
meta = with lib; {
|
|
homepage = "http://www.rust-lang.org/";
|
|
description = "A safe, concurrent, practical language";
|
|
maintainers = with maintainers; [ qknight ];
|
|
license = [ licenses.mit licenses.asl20 ];
|
|
};
|
|
|
|
nativeBuildInputs = lib.optional (!stdenv.isDarwin) autoPatchelfHook;
|
|
buildInputs = [ bash ]
|
|
++ lib.optionals (!stdenv.isDarwin) [ gcc.cc.lib zlib ]
|
|
++ lib.optional stdenv.isDarwin Security;
|
|
|
|
postPatch = ''
|
|
patchShebangs .
|
|
'';
|
|
|
|
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
|
|
# are very hard to track down. For details, see
|
|
# https://github.com/rust-lang/rust/issues/34722#issuecomment-232164943
|
|
'';
|
|
|
|
# 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.
|
|
dontStrip = true;
|
|
|
|
setupHooks = ./setup-hook.sh;
|
|
};
|
|
|
|
rustc = wrapRustc rustc-unwrapped;
|
|
|
|
cargo = stdenv.mkDerivation {
|
|
pname = "cargo-${versionType}";
|
|
|
|
inherit version;
|
|
inherit src;
|
|
|
|
meta = with lib; {
|
|
homepage = "http://www.rust-lang.org/";
|
|
description = "A safe, concurrent, practical language";
|
|
maintainers = with maintainers; [ qknight ];
|
|
license = [ licenses.mit licenses.asl20 ];
|
|
};
|
|
|
|
nativeBuildInputs = [ makeWrapper ]
|
|
++ lib.optional (!stdenv.isDarwin) autoPatchelfHook;
|
|
buildInputs = [ bash ]
|
|
++ lib.optional (!stdenv.isDarwin) gcc.cc.lib
|
|
++ lib.optional stdenv.isDarwin Security;
|
|
|
|
postPatch = ''
|
|
patchShebangs .
|
|
'';
|
|
|
|
installPhase = ''
|
|
patchShebangs ./install.sh
|
|
./install.sh --prefix=$out \
|
|
--components=cargo
|
|
|
|
wrapProgram "$out/bin/cargo" \
|
|
--suffix PATH : "${rustc}/bin"
|
|
'';
|
|
};
|
|
}
|