2021-02-05 17:12:51 +00:00
|
|
|
{ lib, stdenv, makeWrapper, bash, curl, darwin, zlib
|
2020-04-24 23:36:52 +00:00
|
|
|
, version
|
|
|
|
, src
|
|
|
|
, platform
|
|
|
|
, versionType
|
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
2021-02-05 17:12:51 +00:00
|
|
|
inherit (lib) optionalString;
|
2020-04-24 23:36:52 +00:00
|
|
|
inherit (darwin.apple_sdk.frameworks) Security;
|
|
|
|
|
|
|
|
bootstrapping = versionType == "bootstrap";
|
|
|
|
|
|
|
|
installComponents
|
|
|
|
= "rustc,rust-std-${platform}"
|
|
|
|
+ (optionalString bootstrapping ",cargo")
|
|
|
|
;
|
|
|
|
in
|
|
|
|
|
|
|
|
rec {
|
|
|
|
rustc = stdenv.mkDerivation {
|
2022-04-15 01:41:22 +00:00
|
|
|
pname = "rustc-${versionType}";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
inherit version;
|
|
|
|
inherit src;
|
|
|
|
|
2021-02-05 17:12:51 +00:00
|
|
|
meta = with lib; {
|
2020-04-24 23:36:52 +00:00
|
|
|
homepage = "http://www.rust-lang.org/";
|
|
|
|
description = "A safe, concurrent, practical language";
|
|
|
|
maintainers = with maintainers; [ qknight ];
|
|
|
|
license = [ licenses.mit licenses.asl20 ];
|
|
|
|
};
|
|
|
|
|
|
|
|
buildInputs = [ bash ]
|
2021-02-05 17:12:51 +00:00
|
|
|
++ lib.optional stdenv.isDarwin Security;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
postPatch = ''
|
|
|
|
patchShebangs .
|
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
./install.sh --prefix=$out \
|
|
|
|
--components=${installComponents}
|
|
|
|
|
2020-11-06 00:33:48 +00:00
|
|
|
${optionalString (stdenv.isLinux && bootstrapping) (''
|
2020-04-24 23:36:52 +00:00
|
|
|
patchelf \
|
|
|
|
--set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) \
|
|
|
|
"$out/bin/rustc"
|
2021-02-05 17:12:51 +00:00
|
|
|
'' + optionalString (lib.versionAtLeast version "1.46")
|
2020-11-06 00:33:48 +00:00
|
|
|
# rustc bootstrap needs libz starting from 1.46
|
|
|
|
''
|
|
|
|
ln -s ${zlib}/lib/libz.so.1 $out/lib/libz.so.1
|
|
|
|
ln -s ${zlib}/lib/libz.so $out/lib/libz.so
|
|
|
|
'' + ''
|
2020-04-24 23:36:52 +00:00
|
|
|
patchelf \
|
|
|
|
--set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) \
|
|
|
|
"$out/bin/rustdoc"
|
|
|
|
patchelf \
|
|
|
|
--set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) \
|
|
|
|
"$out/bin/cargo"
|
2020-11-06 00:33:48 +00:00
|
|
|
'')}
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
# 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
|
|
|
|
'';
|
|
|
|
|
|
|
|
setupHooks = ./setup-hook.sh;
|
|
|
|
};
|
|
|
|
|
|
|
|
cargo = stdenv.mkDerivation {
|
2022-04-15 01:41:22 +00:00
|
|
|
pname = "cargo-${versionType}";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
inherit version;
|
|
|
|
inherit src;
|
|
|
|
|
2021-02-05 17:12:51 +00:00
|
|
|
meta = with lib; {
|
2020-04-24 23:36:52 +00:00
|
|
|
homepage = "http://www.rust-lang.org/";
|
|
|
|
description = "A safe, concurrent, practical language";
|
|
|
|
maintainers = with maintainers; [ qknight ];
|
|
|
|
license = [ licenses.mit licenses.asl20 ];
|
|
|
|
};
|
|
|
|
|
2021-03-09 03:18:52 +00:00
|
|
|
nativeBuildInputs = [ makeWrapper ];
|
|
|
|
buildInputs = [ bash ] ++ lib.optional stdenv.isDarwin Security;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
postPatch = ''
|
|
|
|
patchShebangs .
|
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
patchShebangs ./install.sh
|
|
|
|
./install.sh --prefix=$out \
|
|
|
|
--components=cargo
|
|
|
|
|
|
|
|
${optionalString (stdenv.isLinux && bootstrapping) ''
|
|
|
|
patchelf \
|
|
|
|
--set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) \
|
|
|
|
"$out/bin/cargo"
|
|
|
|
''}
|
|
|
|
|
|
|
|
wrapProgram "$out/bin/cargo" \
|
|
|
|
--suffix PATH : "${rustc}/bin"
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
}
|