core/pkgs/by-name/ru/rust/binary.nix

112 lines
2.8 KiB
Nix
Raw Permalink Normal View History

2024-08-17 16:37:49 +00:00
{
lib,
stdenv,
makeWrapper,
wrapRustc,
bash,
darwin,
zlib,
autoPatchelfHook,
gcc,
version,
src,
platform,
versionType,
2024-05-02 00:46:19 +00:00
}:
let
inherit (lib) optionalString;
inherit (darwin.apple_sdk.frameworks) Security;
bootstrapping = versionType == "bootstrap";
2024-08-17 16:37:49 +00:00
installComponents = "rustc,rust-std-${platform}" + (optionalString bootstrapping ",cargo");
2024-05-02 00:46:19 +00:00
in
rec {
rustc-unwrapped = stdenv.mkDerivation {
pname = "rustc-${versionType}";
inherit version;
inherit src;
2024-08-17 16:37:49 +00:00
meta = {
2024-05-02 00:46:19 +00:00
homepage = "https://www.rust-lang.org/";
2024-08-17 16:37:49 +00:00
sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ];
description = "Safe, concurrent, practical language";
maintainers = [ ];
license = [
lib.licenses.mit
lib.licenses.asl20
];
2024-05-02 00:46:19 +00:00
};
nativeBuildInputs = lib.optional (!stdenv.isDarwin) autoPatchelfHook;
2024-08-17 16:37:49 +00:00
buildInputs =
[ bash ]
++ lib.optional (!stdenv.isDarwin && !stdenv.isFreeBSD) gcc.cc.lib
++ lib.optional (!stdenv.isDarwin) zlib
2024-05-02 00:46:19 +00:00
++ 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 = "https://doc.rust-lang.org/cargo/";
sourceProvenance = with sourceTypes; [ binaryNativeCode ];
2024-08-17 16:37:49 +00:00
description = "Rust package manager";
2024-05-02 00:46:19 +00:00
maintainers = with maintainers; [ qknight ];
2024-08-17 16:37:49 +00:00
license = [
licenses.mit
licenses.asl20
];
2024-05-02 00:46:19 +00:00
};
2024-08-17 16:37:49 +00:00
nativeBuildInputs = [ makeWrapper ] ++ lib.optional (!stdenv.isDarwin) autoPatchelfHook;
buildInputs =
[ bash ]
++ lib.optional (!stdenv.isDarwin && !stdenv.isFreeBSD) gcc.cc.lib
2024-05-02 00:46:19 +00:00
++ 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"
'';
};
}