2024-01-02 11:29:13 +00:00
|
|
|
{ lib, stdenv, makeWrapper, wrapRustc, bash, curl, darwin, zlib
|
2022-09-09 14:08:57 +00:00
|
|
|
, autoPatchelfHook, gcc
|
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 {
|
2024-01-02 11:29:13 +00:00
|
|
|
rustc-unwrapped = 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; {
|
2024-01-02 11:29:13 +00:00
|
|
|
homepage = "https://www.rust-lang.org/";
|
|
|
|
sourceProvenance = with sourceTypes; [ binaryNativeCode ];
|
2024-06-20 14:57:18 +00:00
|
|
|
description = "Safe, concurrent, practical language";
|
2020-04-24 23:36:52 +00:00
|
|
|
maintainers = with maintainers; [ qknight ];
|
|
|
|
license = [ licenses.mit licenses.asl20 ];
|
|
|
|
};
|
|
|
|
|
2024-09-26 11:04:55 +00:00
|
|
|
nativeBuildInputs = lib.optional (!stdenv.hostPlatform.isDarwin) autoPatchelfHook;
|
2020-04-24 23:36:52 +00:00
|
|
|
buildInputs = [ bash ]
|
2024-09-26 11:04:55 +00:00
|
|
|
++ lib.optional (!stdenv.hostPlatform.isDarwin && !stdenv.hostPlatform.isFreeBSD) gcc.cc.lib
|
|
|
|
++ lib.optional (!stdenv.hostPlatform.isDarwin) zlib
|
|
|
|
++ lib.optional stdenv.hostPlatform.isDarwin Security;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
'';
|
|
|
|
|
2022-10-30 15:09:59 +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-08-10 07:59:29 +00:00
|
|
|
dontStrip = true;
|
2022-10-30 15:09:59 +00:00
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
setupHooks = ./setup-hook.sh;
|
2024-10-11 05:15:48 +00:00
|
|
|
|
|
|
|
passthru = rec {
|
|
|
|
tier1TargetPlatforms = [
|
|
|
|
# Platforms with host tools from
|
|
|
|
# https://doc.rust-lang.org/nightly/rustc/platform-support.html
|
|
|
|
"x86_64-darwin" "i686-darwin" "aarch64-darwin"
|
|
|
|
"i686-freebsd" "x86_64-freebsd"
|
|
|
|
"x86_64-solaris"
|
|
|
|
"aarch64-linux" "armv6l-linux" "armv7l-linux" "i686-linux"
|
|
|
|
"loongarch64-linux" "powerpc64-linux" "powerpc64le-linux"
|
|
|
|
"riscv64-linux" "s390x-linux" "x86_64-linux"
|
|
|
|
"aarch64-netbsd" "armv7l-netbsd" "i686-netbsd" "powerpc-netbsd"
|
|
|
|
"x86_64-netbsd"
|
|
|
|
"i686-openbsd" "x86_64-openbsd"
|
|
|
|
"i686-windows" "x86_64-windows"
|
|
|
|
];
|
|
|
|
targetPlatforms = tier1TargetPlatforms ++ [
|
|
|
|
# Platforms without host tools from
|
|
|
|
# https://doc.rust-lang.org/nightly/rustc/platform-support.html
|
|
|
|
"armv7a-darwin"
|
|
|
|
"armv5tel-linux" "armv7a-linux" "m68k-linux" "mips-linux"
|
|
|
|
"mips64-linux" "mipsel-linux" "mips64el-linux" "riscv32-linux"
|
|
|
|
"armv6l-netbsd" "mipsel-netbsd" "riscv64-netbsd"
|
|
|
|
"x86_64-redox"
|
|
|
|
"wasm32-wasi"
|
|
|
|
];
|
|
|
|
badTargetPlatforms = [
|
|
|
|
# Rust is currently unable to target the n32 ABI
|
|
|
|
lib.systems.inspect.patterns.isMips64n32
|
|
|
|
];
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2024-01-02 11:29:13 +00:00
|
|
|
rustc = wrapRustc rustc-unwrapped;
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
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; {
|
2024-01-02 11:29:13 +00:00
|
|
|
homepage = "https://doc.rust-lang.org/cargo/";
|
|
|
|
sourceProvenance = with sourceTypes; [ binaryNativeCode ];
|
2024-06-20 14:57:18 +00:00
|
|
|
description = "Rust package manager";
|
2020-04-24 23:36:52 +00:00
|
|
|
maintainers = with maintainers; [ qknight ];
|
|
|
|
license = [ licenses.mit licenses.asl20 ];
|
|
|
|
};
|
|
|
|
|
2022-09-09 14:08:57 +00:00
|
|
|
nativeBuildInputs = [ makeWrapper ]
|
2024-09-26 11:04:55 +00:00
|
|
|
++ lib.optional (!stdenv.hostPlatform.isDarwin) autoPatchelfHook;
|
2022-09-09 14:08:57 +00:00
|
|
|
buildInputs = [ bash ]
|
2024-09-26 11:04:55 +00:00
|
|
|
++ lib.optional (!stdenv.hostPlatform.isDarwin && !stdenv.hostPlatform.isFreeBSD) gcc.cc.lib
|
|
|
|
++ lib.optional stdenv.hostPlatform.isDarwin Security;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
postPatch = ''
|
|
|
|
patchShebangs .
|
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
patchShebangs ./install.sh
|
|
|
|
./install.sh --prefix=$out \
|
|
|
|
--components=cargo
|
|
|
|
|
|
|
|
wrapProgram "$out/bin/cargo" \
|
|
|
|
--suffix PATH : "${rustc}/bin"
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
}
|