push sheeet
Some checks failed
Periodic Merges (6h) / master → staging-nixos (push) Failing after 12m50s
Periodic Merges (6h) / master → staging-next (push) Failing after 12m54s
Periodic Merges (24h) / merge-base(master,staging) → haskell-updates (push) Failing after 11m54s
Periodic Merges (6h) / staging-next → staging (push) Failing after 12m13s
Periodic Merges (24h) / staging-next-25.05 → staging-25.05 (push) Failing after 13m24s
Periodic Merges (24h) / release-25.05 → staging-next-25.05 (push) Failing after 14m28s

This commit is contained in:
Dark Steveneq
2025-10-09 14:15:47 +02:00
commit 646b892680
49168 changed files with 5897842 additions and 0 deletions

View File

@@ -0,0 +1,96 @@
# New rust versions should first go to staging.
# Things to check after updating:
# 1. Rustc should produce rust binaries on x86_64-linux, aarch64-linux and x86_64-darwin:
# i.e. nix-shell -p fd or @GrahamcOfBorg build fd on github
# This testing can be also done by other volunteers as part of the pull
# request review, in case platforms cannot be covered.
# 2. The LLVM version used for building should match with rust upstream.
# Check the version number in the src/llvm-project git submodule in:
# https://github.com/rust-lang/rust/blob/<version-tag>/.gitmodules
{
stdenv,
lib,
newScope,
callPackage,
pkgsBuildTarget,
pkgsBuildBuild,
pkgsBuildHost,
pkgsHostTarget,
pkgsTargetTarget,
makeRustPlatform,
wrapRustcWith,
llvmPackages,
llvm,
wrapCCWith,
overrideCC,
fetchpatch,
}@args:
let
llvmSharedFor =
pkgSet:
pkgSet.llvmPackages.libllvm.override (
{
enableSharedLibraries = true;
}
// lib.optionalAttrs (stdenv.targetPlatform.useLLVM or false) {
# Force LLVM to compile using clang + LLVM libs when targeting pkgsLLVM
stdenv = pkgSet.stdenv.override {
allowedRequisites = null;
cc = pkgSet.pkgsBuildHost.llvmPackages.clangUseLLVM;
};
}
);
in
import ./default.nix
{
rustcVersion = "1.89.0";
rustcSha256 = "sha256-JXb59EDdmbAVG9KPWaoKxhAtXE8+1O+KgQyN0FBXJQ0=";
llvmSharedForBuild = llvmSharedFor pkgsBuildBuild;
llvmSharedForHost = llvmSharedFor pkgsBuildHost;
llvmSharedForTarget = llvmSharedFor pkgsBuildTarget;
inherit llvmPackages;
# For use at runtime
llvmShared = llvmSharedFor pkgsHostTarget;
# Note: the version MUST be the same version that we are building. Upstream
# ensures that each released compiler can compile itself:
# https://github.com/NixOS/nixpkgs/pull/351028#issuecomment-2438244363
bootstrapVersion = "1.89.0";
# fetch hashes by running `print-hashes.sh ${bootstrapVersion}`
bootstrapHashes = {
i686-unknown-linux-gnu = "676ef74ce8ce3137ca66e3941b0221516e1713862053d8aa219e91b491417dd9";
x86_64-unknown-linux-gnu = "542f517d0624cbee516627221482b166bf0ffe5fd560ec32beb778c01f5c99b6";
x86_64-unknown-linux-musl = "35695721d53d7eb83ce0153be4c399babf5afd8597bed84f3386d9aac2b4b391";
arm-unknown-linux-gnueabihf = "e618d08b1547c143cfbfc040023914f4a33a4fcf7addff6778d7cfccbd444c5e";
armv7-unknown-linux-gnueabihf = "09a295d2d6821a404ca3bf5d1163b9642139105618d0583241b05b7dbf6e22dc";
aarch64-unknown-linux-gnu = "26d6de84ac59da702aa8c2f903e3c344e3259da02e02ce92ad1c735916b29a4a";
aarch64-unknown-linux-musl = "b5fdcad8289adf94c45727c33773a05acca994b01b333cf7a508f95fa6adc454";
x86_64-apple-darwin = "8590528cade978ecb5249184112887489c9d77ae846539e3ef4d04214a6d8663";
aarch64-apple-darwin = "87baeb57fb29339744ac5f99857f0077b12fa463217fc165dfd8f77412f38118";
powerpc64-unknown-linux-gnu = "30d97f8d757c6ff171815c8af36eed85e44401a58c5e04f25b721c7776ed8337";
powerpc64le-unknown-linux-gnu = "80db8e203357a050780fb8a2cdc027b81d5ae1634fa999c3be69cf8a2e10bbf6";
riscv64gc-unknown-linux-gnu = "3885629641fd670e50c9e6553bdc6505457ef2163757a27dbf33fbc6351b2161";
s390x-unknown-linux-gnu = "696dad74886467a5092ee8bd2265aaab85039fc563803166966c7cae389e2ef7";
loongarch64-unknown-linux-gnu = "171696c45e4a91ccf17a239f00d5a3a8bbd40125d7a274506e1630423d714bec";
loongarch64-unknown-linux-musl = "86e5d8b0f0c868559de3ec2a0902d0e516a710adb845c8904595c54807e821c2";
x86_64-unknown-freebsd = "4baf0d5a44e64eecc91dc7ab89d8b0a8f8607e1d39b6989767861b34459a0396";
};
selectRustPackage = pkgs: pkgs.rust_1_89;
}
(
removeAttrs args [
"llvmPackages"
"llvm"
"wrapCCWith"
"overrideCC"
"pkgsHostTarget"
"fetchpatch"
]
)

View File

@@ -0,0 +1,178 @@
{
lib,
stdenv,
makeWrapper,
wrapRustc,
bash,
curl,
zlib,
autoPatchelfHook,
gcc,
version,
src,
platform,
versionType,
}:
let
inherit (lib) optionalString;
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 = "https://www.rust-lang.org/";
sourceProvenance = with sourceTypes; [ binaryNativeCode ];
description = "Safe, concurrent, practical language";
mainProgram = "rustc";
maintainers = with maintainers; [ qknight ];
license = [
licenses.mit
licenses.asl20
];
};
nativeBuildInputs = lib.optional (!stdenv.hostPlatform.isDarwin) autoPatchelfHook;
buildInputs = [
bash
]
++ lib.optional (!stdenv.hostPlatform.isDarwin && !stdenv.hostPlatform.isFreeBSD) gcc.cc.lib
++ lib.optional (!stdenv.hostPlatform.isDarwin) zlib;
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
''
+ lib.optionalString stdenv.hostPlatform.isDarwin ''
install_name_tool -change "/usr/lib/libcurl.4.dylib" \
"${lib.getLib curl}/lib/libcurl.4.dylib" "$out/bin/cargo"
'';
# 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;
passthru = rec {
targetPlatformsWithHostTools = [
# Platforms with host tools from
# https://doc.rust-lang.org/nightly/rustc/platform-support.html
"x86_64-darwin"
"aarch64-darwin"
"i686-freebsd"
"x86_64-freebsd"
"x86_64-solaris"
"aarch64-linux"
"armv6l-linux"
"armv7l-linux"
"i686-linux"
"loongarch64-linux"
"powerpc-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 = targetPlatformsWithHostTools ++ [
# Platforms without host tools from
# https://doc.rust-lang.org/nightly/rustc/platform-support.html
"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
];
};
};
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 ];
description = "Rust package manager";
maintainers = with maintainers; [ qknight ];
license = [
licenses.mit
licenses.asl20
];
};
nativeBuildInputs = [
makeWrapper
]
++ lib.optional (!stdenv.hostPlatform.isDarwin) autoPatchelfHook;
buildInputs = [
bash
]
++ lib.optional (!stdenv.hostPlatform.isDarwin && !stdenv.hostPlatform.isFreeBSD) gcc.cc.lib;
postPatch = ''
patchShebangs .
'';
installPhase = ''
patchShebangs ./install.sh
./install.sh --prefix=$out \
--components=cargo
''
+ lib.optionalString stdenv.hostPlatform.isDarwin ''
install_name_tool -change "/usr/lib/libcurl.4.dylib" \
"${lib.getLib curl}/lib/libcurl.4.dylib" "$out/bin/cargo"
''
+ ''
wrapProgram "$out/bin/cargo" \
--suffix PATH : "${rustc}/bin"
'';
};
}

View File

@@ -0,0 +1,21 @@
{
stdenv,
fetchurl,
callPackage,
version,
hashes,
}:
let
platform = stdenv.hostPlatform.rust.rustcTarget;
src = fetchurl {
url = "https://static.rust-lang.org/dist/rust-${version}-${platform}.tar.gz";
sha256 = hashes.${platform} or (throw "missing bootstrap url for platform ${platform}");
};
in
callPackage ./binary.nix {
inherit version src platform;
versionType = "bootstrap";
}

View File

@@ -0,0 +1,41 @@
{
lib,
runCommand,
makeBinaryWrapper,
rust-audit-info,
cargo,
cargo-auditable,
}:
if cargo-auditable.meta.broken then
cargo
else
runCommand "auditable-${cargo.name}"
{
nativeBuildInputs = [ makeBinaryWrapper ];
passthru.tests =
runCommand "rust-audit-info-test"
{
nativeBuildInputs = [ rust-audit-info ];
}
''
rust-audit-info ${lib.getBin rust-audit-info}/bin/rust-audit-info > $out
'';
meta = cargo-auditable.meta // {
mainProgram = "cargo";
};
}
''
mkdir -p $out/bin
makeWrapper ${cargo}/bin/cargo $out/bin/cargo \
--set CARGO_AUDITABLE_IGNORE_UNSUPPORTED 1 \
--prefix PATH : ${
lib.makeBinPath [
cargo
cargo-auditable
]
} \
--add-flags auditable
''

View File

@@ -0,0 +1,76 @@
{
lib,
buildPackages,
fetchFromGitHub,
makeRustPlatform,
installShellFiles,
stdenv,
}:
let
args = rec {
pname = "cargo-auditable";
version = "0.6.5";
src = fetchFromGitHub {
owner = "rust-secure-code";
repo = "cargo-auditable";
rev = "v${version}";
sha256 = "sha256-zjv2/qZM0vRyz45DeKRtPHaamv2iLtjpSedVTEXeDr8=";
};
cargoDeps = rustPlatform.fetchCargoVendor {
inherit pname version src;
hash = "sha256-oTPGmoGlNfPVZ6qha/oXyPJp94fT2cNlVggbIGHf2bc=";
};
checkFlags = [
# requires wasm32-unknown-unknown target
"--skip=test_wasm"
];
meta = with lib; {
description = "Tool to make production Rust binaries auditable";
mainProgram = "cargo-auditable";
homepage = "https://github.com/rust-secure-code/cargo-auditable";
changelog = "https://github.com/rust-secure-code/cargo-auditable/blob/v${version}/cargo-auditable/CHANGELOG.md";
license = with licenses; [
mit # or
asl20
];
maintainers = with maintainers; [ figsoda ];
broken = stdenv.hostPlatform != stdenv.buildPlatform;
};
};
rustPlatform = makeRustPlatform {
inherit (buildPackages) rustc;
cargo = buildPackages.cargo.override {
auditable = false;
};
};
bootstrap = rustPlatform.buildRustPackage (
args
// {
auditable = false;
}
);
in
rustPlatform.buildRustPackage.override { cargo-auditable = bootstrap; } (
args
// {
nativeBuildInputs = [
installShellFiles
];
postInstall = ''
installManPage cargo-auditable/cargo-auditable.1
'';
passthru = {
inherit bootstrap;
};
}
)

View File

@@ -0,0 +1,105 @@
{
lib,
stdenv,
pkgsHostHost,
file,
curl,
pkg-config,
python3,
openssl,
cmake,
zlib,
installShellFiles,
makeWrapper,
rustPlatform,
rustc,
auditable ? !cargo-auditable.meta.broken,
cargo-auditable,
}:
rustPlatform.buildRustPackage.override
{
cargo-auditable = cargo-auditable.bootstrap;
}
{
pname = "cargo";
inherit (rustc.unwrapped) version src;
# the rust source tarball already has all the dependencies vendored, no need to fetch them again
cargoVendorDir = "vendor";
buildAndTestSubdir = "src/tools/cargo";
inherit auditable;
passthru = {
rustc = rustc;
inherit (rustc.unwrapped) tests;
};
# changes hash of vendor directory otherwise
dontUpdateAutotoolsGnuConfigScripts = true;
nativeBuildInputs = [
pkg-config
cmake
installShellFiles
makeWrapper
(lib.getDev pkgsHostHost.curl)
zlib
];
buildInputs = [
file
curl
python3
openssl
zlib
];
# cargo uses git-rs which is made for a version of libgit2 from recent master that
# is not compatible with the current version in nixpkgs.
#LIBGIT2_SYS_USE_PKG_CONFIG = 1;
# fixes: the cargo feature `edition` requires a nightly version of Cargo, but this is the `stable` channel
RUSTC_BOOTSTRAP = 1;
postInstall = ''
wrapProgram "$out/bin/cargo" --suffix PATH : "${rustc}/bin"
installManPage src/tools/cargo/src/etc/man/*
installShellCompletion --bash --name cargo \
src/tools/cargo/src/etc/cargo.bashcomp.sh
installShellCompletion --zsh src/tools/cargo/src/etc/_cargo
'';
checkPhase = ''
# Disable cross compilation tests
export CFG_DISABLE_CROSS_TESTS=1
cargo test
'';
# Disable check phase as there are failures (4 tests fail)
doCheck = false;
doInstallCheck = !stdenv.hostPlatform.isStatic && stdenv.hostPlatform.isElf;
installCheckPhase = ''
runHook preInstallCheck
${stdenv.cc.targetPrefix}readelf -a $out/bin/.cargo-wrapped | grep -F 'Shared library: [libcurl.so'
runHook postInstallCheck
'';
meta = with lib; {
homepage = "https://crates.io";
description = "Downloads your Rust project's dependencies and builds your project";
mainProgram = "cargo";
teams = [ teams.rust ];
license = [
licenses.mit
licenses.asl20
];
platforms = platforms.unix;
# https://github.com/alexcrichton/nghttp2-rs/issues/2
broken = stdenv.hostPlatform.isx86 && stdenv.buildPlatform != stdenv.hostPlatform;
};
}

View File

@@ -0,0 +1,24 @@
{
runCommand,
stdenv,
lib,
pkgsBuildBuild,
makeShellWrapper,
rustc,
...
}:
runCommand "${stdenv.targetPlatform.config}-cargo-${lib.getVersion pkgsBuildBuild.cargo}"
{
# Use depsBuildBuild or it tries to use target-runtimeShell
depsBuildBuild = [ makeShellWrapper ];
inherit (pkgsBuildBuild.cargo) meta;
}
''
mkdir -p $out/bin
ln -s ${pkgsBuildBuild.cargo}/share $out/share
makeWrapper "${pkgsBuildBuild.cargo}/bin/cargo" "$out/bin/cargo" \
--prefix PATH : "${rustc}/bin"
''

View File

@@ -0,0 +1,34 @@
{
lib,
runCommand,
clippy-unwrapped,
rustc-unwrapped,
makeWrapper,
}:
runCommand "${clippy-unwrapped.pname}-wrapper-${clippy-unwrapped.version}"
{
preferLocalBuild = true;
strictDeps = true;
inherit (clippy-unwrapped) outputs;
nativeBuildInputs = [ makeWrapper ];
meta = clippy-unwrapped.meta // {
description = "${clippy-unwrapped.meta.description} (wrapper script)";
priority = 10;
};
}
''
mkdir -p $out/bin
makeWrapper ${clippy-unwrapped}/bin/cargo-clippy $out/bin/cargo-clippy \
--set-default SYSROOT ${rustc-unwrapped}
makeWrapper ${clippy-unwrapped}/bin/clippy-driver $out/bin/clippy-driver \
--set-default SYSROOT ${rustc-unwrapped}
${lib.concatMapStrings (output: "ln -s ${clippy-unwrapped.${output}} \$${output}\n") (
lib.remove "out" clippy-unwrapped.outputs
)}
''

View File

@@ -0,0 +1,54 @@
{
stdenv,
lib,
rustPlatform,
rustc,
}:
rustPlatform.buildRustPackage {
pname = "clippy";
inherit (rustc) version src;
separateDebugInfo = true;
# the rust source tarball already has all the dependencies vendored, no need to fetch them again
cargoVendorDir = "vendor";
buildAndTestSubdir = "src/tools/clippy";
# changes hash of vendor directory otherwise
dontUpdateAutotoolsGnuConfigScripts = true;
buildInputs = [ rustc.llvm ];
# fixes: error: the option `Z` is only accepted on the nightly compiler
RUSTC_BOOTSTRAP = 1;
# Without disabling the test the build fails with:
# error: failed to run custom build command for `rustc_llvm v0.0.0
# (/private/tmp/nix-build-clippy-1.36.0.drv-0/rustc-1.36.0-src/src/librustc_llvm)
doCheck = false;
# Clippy uses the rustc_driver and std private libraries, and Rust's build process forces them to have
# an install name of `@rpath/...` [0] [1] instead of the standard on macOS, which is an absolute path
# to itself.
#
# [0]: https://github.com/rust-lang/rust/blob/f77f4d55bdf9d8955d3292f709bd9830c2fdeca5/src/bootstrap/builder.rs#L1543
# [1]: https://github.com/rust-lang/rust/blob/f77f4d55bdf9d8955d3292f709bd9830c2fdeca5/compiler/rustc_codegen_ssa/src/back/linker.rs#L323-L331
preFixup = lib.optionalString stdenv.hostPlatform.isDarwin ''
install_name_tool -add_rpath "${rustc.unwrapped}/lib" "$out/bin/clippy-driver"
install_name_tool -add_rpath "${rustc.unwrapped}/lib" "$out/bin/cargo-clippy"
'';
meta = with lib; {
homepage = "https://rust-lang.github.io/rust-clippy/";
description = "Bunch of lints to catch common mistakes and improve your Rust code";
mainProgram = "cargo-clippy";
maintainers = with maintainers; [ basvandijk ];
teams = [ teams.rust ];
license = with licenses; [
mit
asl20
];
platforms = platforms.unix;
};
}

View File

@@ -0,0 +1,135 @@
{
rustcVersion,
rustcSha256,
enableRustcDev ? true,
bootstrapVersion,
bootstrapHashes,
selectRustPackage,
rustcPatches ? [ ],
llvmShared,
llvmSharedForBuild,
llvmSharedForHost,
llvmSharedForTarget,
llvmPackages, # Exposed through rustc for LTO in Firefox
}:
{
stdenv,
lib,
newScope,
callPackage,
pkgsBuildBuild,
pkgsBuildHost,
pkgsBuildTarget,
pkgsTargetTarget,
makeRustPlatform,
wrapRustcWith,
}:
let
# Use `import` to make sure no packages sneak in here.
lib' = import ../../../build-support/rust/lib {
inherit
lib
stdenv
pkgsBuildHost
pkgsBuildTarget
pkgsTargetTarget
;
};
# Allow faster cross compiler generation by reusing Build artifacts
fastCross =
(stdenv.buildPlatform == stdenv.hostPlatform) && (stdenv.hostPlatform != stdenv.targetPlatform);
in
{
lib = lib';
# Backwards compat before `lib` was factored out.
inherit (lib')
toTargetArch
toTargetOs
toRustTarget
toRustTargetSpec
IsNoStdTarget
toRustTargetForUseInEnvVars
envVars
;
# This just contains tools for now. But it would conceivably contain
# libraries too, say if we picked some default/recommended versions to build
# by Hydra.
#
# In the end game, rustc, the rust standard library (`core`, `std`, etc.),
# and cargo would themselves be built with `buildRustCreate` like
# everything else. Tools and `build.rs` and procedural macro dependencies
# would be taken from `buildRustPackages` (and `bootstrapRustPackages` for
# anything provided prebuilt or their build-time dependencies to break
# cycles / purify builds). In this way, nixpkgs would be in control of all
# bootstrapping.
packages = {
prebuilt = callPackage ./bootstrap.nix {
version = bootstrapVersion;
hashes = bootstrapHashes;
};
stable = lib.makeScope newScope (
self:
let
# Like `buildRustPackages`, but may also contain prebuilt binaries to
# break cycle. Just like `bootstrapTools` for nixpkgs as a whole,
# nothing in the final package set should refer to this.
bootstrapRustPackages =
if fastCross then
pkgsBuildBuild.rustPackages
else
self.buildRustPackages.overrideScope (
_: _:
lib.optionalAttrs (stdenv.buildPlatform == stdenv.hostPlatform)
(selectRustPackage pkgsBuildHost).packages.prebuilt
);
bootRustPlatform = makeRustPlatform bootstrapRustPackages;
in
{
# Packages suitable for build-time, e.g. `build.rs`-type stuff.
buildRustPackages = (selectRustPackage pkgsBuildHost).packages.stable;
# Analogous to stdenv
rustPlatform = makeRustPlatform self.buildRustPackages;
rustc-unwrapped = self.callPackage ./rustc.nix {
version = rustcVersion;
sha256 = rustcSha256;
inherit enableRustcDev;
inherit
llvmShared
llvmSharedForBuild
llvmSharedForHost
llvmSharedForTarget
llvmPackages
fastCross
;
patches = rustcPatches;
# Use boot package set to break cycle
inherit (bootstrapRustPackages) cargo rustc rustfmt;
};
rustc = wrapRustcWith {
inherit (self) rustc-unwrapped;
sysroot = if fastCross then self.rustc-unwrapped else null;
};
rustfmt = self.callPackage ./rustfmt.nix {
inherit (self.buildRustPackages) rustc;
};
cargo =
if (!fastCross) then
self.callPackage ./cargo.nix {
# Use boot package set to break cycle
rustPlatform = bootRustPlatform;
}
else
self.callPackage ./cargo_cross.nix { };
cargo-auditable = self.callPackage ./cargo-auditable.nix { };
cargo-auditable-cargo-wrapper = self.callPackage ./cargo-auditable-cargo-wrapper.nix { };
clippy-unwrapped = self.callPackage ./clippy.nix { };
clippy = if !fastCross then self.clippy-unwrapped else self.callPackage ./clippy-wrapper.nix { };
}
);
};
}

View File

@@ -0,0 +1,85 @@
{
lib,
buildPackages,
callPackages,
cargo-auditable,
config,
stdenv,
runCommand,
generateSplicesForMkScope,
makeScopeWithSplicing',
}@prev:
{
rustc,
cargo,
cargo-auditable ? prev.cargo-auditable,
stdenv ? prev.stdenv,
...
}:
(makeScopeWithSplicing' {
otherSplices = generateSplicesForMkScope "rustPlatform";
f =
self:
let
inherit (self) callPackage;
in
{
fetchCargoVendor = buildPackages.callPackage ../../../build-support/rust/fetch-cargo-vendor.nix {
inherit cargo;
};
buildRustPackage = callPackage ../../../build-support/rust/build-rust-package {
inherit
stdenv
rustc
cargo
cargo-auditable
;
};
importCargoLock = buildPackages.callPackage ../../../build-support/rust/import-cargo-lock.nix {
inherit cargo;
};
rustcSrc = callPackage ./rust-src.nix {
inherit runCommand rustc;
};
rustLibSrc = callPackage ./rust-lib-src.nix {
inherit runCommand rustc;
};
# Useful when rebuilding std
# e.g. when building wasm with wasm-pack
rustVendorSrc = callPackage ./rust-vendor-src.nix {
inherit runCommand rustc;
};
# Hooks
inherit
(callPackages ../../../build-support/rust/hooks {
inherit
stdenv
;
})
cargoBuildHook
cargoCheckHook
cargoInstallHook
cargoNextestHook
cargoSetupHook
maturinBuildHook
bindgenHook
;
};
})
// lib.optionalAttrs config.allowAliases {
rust = {
rustc = lib.warn "rustPlatform.rust.rustc is deprecated. Use rustc instead." rustc;
cargo = lib.warn "rustPlatform.rust.cargo is deprecated. Use cargo instead." cargo;
};
# Added in 25.05.
fetchCargoTarball = throw "`rustPlatform.fetchCargoTarball` has been removed in 25.05, use `rustPlatform.fetchCargoVendor` instead";
}

View File

@@ -0,0 +1,48 @@
#!/usr/bin/env bash
set -euo pipefail
# All rust-related downloads can be found at
# https://static.rust-lang.org/dist/index.html. To find the date on
# which a particular thing was last updated, look for the *-date.txt
# file, e.g.
# https://static.rust-lang.org/dist/channel-rust-beta-date.txt
PLATFORMS=(
i686-unknown-linux-gnu
x86_64-unknown-linux-gnu
x86_64-unknown-linux-musl
arm-unknown-linux-gnueabihf
armv7-unknown-linux-gnueabihf
aarch64-unknown-linux-gnu
aarch64-unknown-linux-musl
x86_64-apple-darwin
aarch64-apple-darwin
powerpc64-unknown-linux-gnu
powerpc64le-unknown-linux-gnu
riscv64gc-unknown-linux-gnu
s390x-unknown-linux-gnu
loongarch64-unknown-linux-gnu
loongarch64-unknown-linux-musl
x86_64-unknown-freebsd
)
BASEURL=https://static.rust-lang.org/dist
VERSION=${1:-}
DATE=${2:-}
if [[ -z $VERSION ]]
then
echo "No version supplied"
exit -1
fi
if [[ -n $DATE ]]
then
BASEURL=$BASEURL/$DATE
fi
for PLATFORM in "${PLATFORMS[@]}"
do
URL="$BASEURL/rust-$VERSION-$PLATFORM.tar.gz.sha256"
SHA256=$(curl -sSfL $URL | cut -d ' ' -f 1)
echo "$PLATFORM = \"$SHA256\";"
done

View File

@@ -0,0 +1,6 @@
{ runCommand, rustc }:
runCommand "rust-lib-src" { } ''
tar --strip-components=1 -xzf ${rustc.src}
mv library $out
''

View File

@@ -0,0 +1,31 @@
{
lib,
runCommand,
rustc,
minimalContent ? true,
}:
runCommand "rust-src" { } ''
tar -xzf ${rustc.src}
mv rustc-${rustc.version}-src $out
rm -rf $out/{${
lib.concatStringsSep "," (
[
"ci"
"doc"
"etc"
"grammar"
"llvm-project"
"llvm-emscripten"
"rtstartup"
"rustllvm"
"test"
"vendor"
]
++ lib.optionals minimalContent [
"tools"
"stdarch"
]
)
}}
''

View File

@@ -0,0 +1,6 @@
{ runCommand, rustc }:
runCommand "rust-vendor-src" { } ''
tar --strip-components=1 -xzf ${rustc.src}
mv vendor $out
''

View File

@@ -0,0 +1,450 @@
{
lib,
stdenv,
removeReferencesTo,
pkgsBuildBuild,
pkgsBuildHost,
pkgsBuildTarget,
targetPackages,
llvmShared,
llvmSharedForBuild,
llvmSharedForHost,
llvmSharedForTarget,
llvmPackages,
runCommandLocal,
fetchurl,
file,
python3,
cargo,
cmake,
rustc,
rustfmt,
pkg-config,
openssl,
xz,
zlib,
bintools,
which,
libffi,
withBundledLLVM ? false,
enableRustcDev ? true,
version,
sha256,
patches ? [ ],
fd,
ripgrep,
wezterm,
firefox,
thunderbird,
# This only builds std for target and reuses the rustc from build.
fastCross,
lndir,
makeWrapper,
}:
let
inherit (lib)
optionals
optional
optionalString
concatStringsSep
;
useLLVM = stdenv.targetPlatform.useLLVM or false;
in
stdenv.mkDerivation (finalAttrs: {
pname = "${targetPackages.stdenv.cc.targetPrefix}rustc";
inherit version;
src = fetchurl {
url = "https://static.rust-lang.org/dist/rustc-${version}-src.tar.gz";
inherit sha256;
# See https://nixos.org/manual/nixpkgs/stable/#using-git-bisect-on-the-rust-compiler
passthru.isReleaseTarball = true;
};
hardeningDisable = optionals stdenv.cc.isClang [
# remove once https://github.com/NixOS/nixpkgs/issues/318674 is
# addressed properly
"zerocallusedregs"
];
__darwinAllowLocalNetworking = true;
# rustc complains about modified source files otherwise
dontUpdateAutotoolsGnuConfigScripts = true;
# Running the default `strip -S` command on Darwin corrupts the
# .rlib files in "lib/".
#
# See https://github.com/NixOS/nixpkgs/pull/34227
#
# Running `strip -S` when cross compiling can harm the cross rlibs.
# See: https://github.com/NixOS/nixpkgs/pull/56540#issuecomment-471624656
stripDebugList = [ "bin" ];
NIX_LDFLAGS = toString (
# when linking stage1 libstd: cc: undefined reference to `__cxa_begin_catch'
# This doesn't apply to cross-building for FreeBSD because the host
# uses libstdc++, but the target (used for building std) uses libc++
optional (
stdenv.hostPlatform.isLinux && !withBundledLLVM && !stdenv.targetPlatform.isFreeBSD && !useLLVM
) "--push-state --as-needed -lstdc++ --pop-state"
++
optional
(stdenv.hostPlatform.isLinux && !withBundledLLVM && !stdenv.targetPlatform.isFreeBSD && useLLVM)
"--push-state --as-needed -L${llvmPackages.libcxx}/lib -lc++ -lc++abi -lLLVM-${lib.versions.major llvmPackages.llvm.version} --pop-state"
++ optional (stdenv.hostPlatform.isDarwin && !withBundledLLVM) "-lc++ -lc++abi"
++ optional stdenv.hostPlatform.isDarwin "-rpath ${llvmSharedForHost.lib}/lib"
);
# Increase codegen units to introduce parallelism within the compiler.
RUSTFLAGS = "-Ccodegen-units=10";
RUSTDOCFLAGS = "-A rustdoc::broken-intra-doc-links";
# We need rust to build rust. If we don't provide it, configure will try to download it.
# Reference: https://github.com/rust-lang/rust/blob/master/src/bootstrap/configure.py
configureFlags =
let
prefixForStdenv = stdenv: "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}";
ccPrefixForStdenv =
stdenv: "${prefixForStdenv stdenv}${if (stdenv.cc.isClang or false) then "clang" else "cc"}";
cxxPrefixForStdenv =
stdenv: "${prefixForStdenv stdenv}${if (stdenv.cc.isClang or false) then "clang++" else "c++"}";
setBuild = "--set=target.\"${stdenv.buildPlatform.rust.rustcTargetSpec}\"";
setHost = "--set=target.\"${stdenv.hostPlatform.rust.rustcTargetSpec}\"";
setTarget = "--set=target.\"${stdenv.targetPlatform.rust.rustcTargetSpec}\"";
ccForBuild = ccPrefixForStdenv pkgsBuildBuild.targetPackages.stdenv;
cxxForBuild = cxxPrefixForStdenv pkgsBuildBuild.targetPackages.stdenv;
ccForHost = ccPrefixForStdenv pkgsBuildHost.targetPackages.stdenv;
cxxForHost = cxxPrefixForStdenv pkgsBuildHost.targetPackages.stdenv;
ccForTarget = ccPrefixForStdenv pkgsBuildTarget.targetPackages.stdenv;
cxxForTarget = cxxPrefixForStdenv pkgsBuildTarget.targetPackages.stdenv;
in
[
"--sysconfdir=${placeholder "out"}/etc"
"--release-channel=stable"
"--set=build.rustc=${rustc}/bin/rustc"
"--set=build.cargo=${cargo}/bin/cargo"
]
++ lib.optionals (!(finalAttrs.src.passthru.isReleaseTarball or false)) [
# release tarballs vendor the rustfmt source; when
# git-bisect'ing from upstream's git repo we must prevent
# attempts to download the missing source tarball
"--set=build.rustfmt=${rustfmt}/bin/rustfmt"
]
++ [
"--tools=rustc,rustdoc,rust-analyzer-proc-macro-srv"
"--enable-rpath"
"--enable-vendor"
# For Nixpkgs it makes more sense to use stdenv's linker than
# letting rustc build its own.
"--disable-lld"
"--build=${stdenv.buildPlatform.rust.rustcTargetSpec}"
"--host=${stdenv.hostPlatform.rust.rustcTargetSpec}"
# std is built for all platforms in --target.
"--target=${
concatStringsSep "," (
# Other targets that don't need any extra dependencies to build.
optionals (!fastCross) [
"wasm32-unknown-unknown"
"wasm32v1-none"
"bpfel-unknown-none"
"bpfeb-unknown-none"
]
# (build!=target): When cross-building a compiler we need to add
# the build platform as well so rustc can compile build.rs
# scripts.
++ optionals (stdenv.buildPlatform != stdenv.targetPlatform && !fastCross) [
stdenv.buildPlatform.rust.rustcTargetSpec
]
# (host!=target): When building a cross-targeting compiler we
# need to add the host platform as well so rustc can compile
# build.rs scripts.
++ optionals (stdenv.hostPlatform != stdenv.targetPlatform && !fastCross) [
stdenv.hostPlatform.rust.rustcTargetSpec
]
++ [
# `make install` only keeps the docs of the last target in the list.
# If the `targetPlatform` is not the last entry, we may end up without
# `alloc` or `std` docs (if the last target is `no_std`).
# More information: https://github.com/rust-lang/rust/issues/140922
stdenv.targetPlatform.rust.rustcTargetSpec
]
)
}"
"${setBuild}.cc=${ccForBuild}"
"${setHost}.cc=${ccForHost}"
"${setTarget}.cc=${ccForTarget}"
# The Rust compiler build identifies platforms by Rust target
# name, and later arguments override previous arguments. This
# means that when platforms differ in configuration but overlap
# in Rust target name (for instance, `pkgsStatic`), only one
# setting will be applied for any given option.
#
# This is usually mostly harmless, especially as `fastCross`
# means that we usually only compile `std` in such cases.
# However, the build does still need to link helper tools for the
# build platform in that case. This was breaking the Darwin
# `pkgsStatic` build, as it was attempting to link build tools
# with the target platforms static linker, and failing to locate
# an appropriate static library for `-liconv`.
#
# Since the static build does not link anything for the target
# platform anyway, we put the target linker first so that the
# build platform linker overrides it when the Rust target names
# overlap, allowing the helper tools to build successfully.
#
# Note that Rust does not remember these settings in the built
# compiler, so this does not compromise any functionality of the
# resulting compiler.
#
# The longerterm fix would be to get Rust to use a more nuanced
# understanding of platforms, such as by explicitly constructing
# and passing Rust JSON target definitions that let us
# distinguish the platforms in cases like these. That would also
# let us supplant various hacks around the wrappers and hooks
# that we currently need.
"${setTarget}.linker=${ccForTarget}"
"${setBuild}.linker=${ccForBuild}"
"${setHost}.linker=${ccForHost}"
"${setBuild}.cxx=${cxxForBuild}"
"${setHost}.cxx=${cxxForHost}"
"${setTarget}.cxx=${cxxForTarget}"
"${setBuild}.crt-static=${lib.boolToString stdenv.buildPlatform.isStatic}"
"${setHost}.crt-static=${lib.boolToString stdenv.hostPlatform.isStatic}"
"${setTarget}.crt-static=${lib.boolToString stdenv.targetPlatform.isStatic}"
]
++ optionals (!withBundledLLVM) [
"--enable-llvm-link-shared"
"${setBuild}.llvm-config=${llvmSharedForBuild.dev}/bin/llvm-config"
"${setHost}.llvm-config=${llvmSharedForHost.dev}/bin/llvm-config"
"${setTarget}.llvm-config=${llvmSharedForTarget.dev}/bin/llvm-config"
]
++ optionals fastCross [
# Since fastCross only builds std, it doesn't make sense (and
# doesn't work) to build a linker.
"--disable-llvm-bitcode-linker"
]
++ optionals (stdenv.targetPlatform.isLinux && !(stdenv.targetPlatform.useLLVM or false)) [
"--enable-profiler" # build libprofiler_builtins
]
++ optionals stdenv.buildPlatform.isMusl [
"${setBuild}.musl-root=${pkgsBuildBuild.targetPackages.stdenv.cc.libc}"
]
++ optionals stdenv.hostPlatform.isMusl [
"${setHost}.musl-root=${pkgsBuildHost.targetPackages.stdenv.cc.libc}"
]
++ optionals stdenv.targetPlatform.isMusl [
"${setTarget}.musl-root=${pkgsBuildTarget.targetPackages.stdenv.cc.libc}"
]
++ optionals stdenv.targetPlatform.rust.isNoStdTarget [
"--disable-docs"
]
++ optionals (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isx86_64) [
# https://github.com/rust-lang/rust/issues/92173
"--set rust.jemalloc"
]
++ optionals (useLLVM && !stdenv.targetPlatform.isFreeBSD) [
# https://github.com/NixOS/nixpkgs/issues/311930
"--llvm-libunwind=${if withBundledLLVM then "in-tree" else "system"}"
"--enable-use-libcxx"
]
++ optionals (!stdenv.hostPlatform.isx86_32) [
# This enables frame pointers for the compiler itself.
#
# Note that when compiling std, frame pointers (or at least non-leaf
# frame pointers, depending on version) are unconditionally enabled and
# cannot be overridden, so we do not touch that. (Also note this only
# applies to functions that can be immediately compiled when building
# std. Generic functions that do codegen when called in user code obey
# -Cforce-frame-pointers specified then, if any)
"--set rust.frame-pointers"
];
# if we already have a rust compiler for build just compile the target std
# library and reuse compiler
buildPhase =
if fastCross then
''
runHook preBuild
mkdir -p build/${stdenv.hostPlatform.rust.rustcTargetSpec}/stage0-{std,rustc}/${stdenv.hostPlatform.rust.rustcTargetSpec}/release/
ln -s ${rustc.unwrapped}/lib/rustlib/${stdenv.hostPlatform.rust.rustcTargetSpec}/libstd-*.so build/${stdenv.hostPlatform.rust.rustcTargetSpec}/stage0-std/${stdenv.hostPlatform.rust.rustcTargetSpec}/release/libstd.so
ln -s ${rustc.unwrapped}/lib/rustlib/${stdenv.hostPlatform.rust.rustcTargetSpec}/librustc_driver-*.so build/${stdenv.hostPlatform.rust.rustcTargetSpec}/stage0-rustc/${stdenv.hostPlatform.rust.rustcTargetSpec}/release/librustc.so
ln -s ${rustc.unwrapped}/bin/rustc build/${stdenv.hostPlatform.rust.rustcTargetSpec}/stage0-rustc/${stdenv.hostPlatform.rust.rustcTargetSpec}/release/rustc-main
touch build/${stdenv.hostPlatform.rust.rustcTargetSpec}/stage0-std/${stdenv.hostPlatform.rust.rustcTargetSpec}/release/.libstd-stamp
touch build/${stdenv.hostPlatform.rust.rustcTargetSpec}/stage0-rustc/${stdenv.hostPlatform.rust.rustcTargetSpec}/release/.librustc-stamp
python ./x.py --keep-stage=0 --stage=1 build library
runHook postBuild
''
else
null;
installPhase =
if fastCross then
''
runHook preInstall
python ./x.py --keep-stage=0 --stage=1 install library/std
mkdir -v $doc $man
ln -s ${rustc.unwrapped}/{bin,libexec} $out
rm -rf -v $out/lib/rustlib/{manifest-rust-std-,}${stdenv.hostPlatform.rust.rustcTargetSpec}
ln -s ${rustc.unwrapped}/lib/rustlib/{manifest-rust-std-,}${stdenv.hostPlatform.rust.rustcTargetSpec} $out/lib/rustlib/
ln -s ${rustc.unwrapped}/lib/rustlib/etc $out/lib/rustlib/
echo rust-std-${stdenv.hostPlatform.rust.rustcTargetSpec} >> $out/lib/rustlib/components
lndir ${rustc.doc} $doc
lndir ${rustc.man} $man
runHook postInstall
''
else
null;
# the rust build system complains that nix alters the checksums
dontFixLibtool = true;
inherit patches;
postPatch = ''
patchShebangs src/etc
# rust-lld is the name rustup uses for its bundled lld, so that it
# doesn't conflict with any system lld. This is not an
# appropriate default for Nixpkgs, where there is no rust-lld.
substituteInPlace compiler/rustc_target/src/spec/*/*.rs \
--replace-quiet '"rust-lld"' '"lld"'
${optionalString (!withBundledLLVM) "rm -rf src/llvm"}
# Useful debugging parameter
# export VERBOSE=1
''
+ lib.optionalString (stdenv.hostPlatform.isDarwin || stdenv.targetPlatform.isDarwin) ''
# Replace hardcoded path to strip with llvm-strip
# https://github.com/NixOS/nixpkgs/issues/299606
substituteInPlace compiler/rustc_codegen_ssa/src/back/link.rs \
--replace-fail "/usr/bin/strip" "${lib.getExe' llvmShared "llvm-strip"}"
''
+ lib.optionalString (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isx86_64) ''
# See https://github.com/jemalloc/jemalloc/issues/1997
# Using a value of 48 should work on both emulated and native x86_64-darwin.
export JEMALLOC_SYS_WITH_LG_VADDR=48
''
+ lib.optionalString (!(finalAttrs.src.passthru.isReleaseTarball or false)) ''
mkdir .cargo
cat > .cargo/config.toml <<\EOF
[source.crates-io]
replace-with = "vendored-sources"
[source.vendored-sources]
directory = "vendor"
EOF
''
+ lib.optionalString (stdenv.hostPlatform.isFreeBSD) ''
# lzma-sys bundles an old version of xz that doesn't build
# on modern FreeBSD, use the system one instead
substituteInPlace src/bootstrap/src/core/build_steps/tool.rs \
--replace 'cargo.env("LZMA_API_STATIC", "1");' ' '
'';
# rustc unfortunately needs cmake to compile llvm-rt but doesn't
# use it for the normal build. This disables cmake in Nix.
dontUseCmakeConfigure = true;
depsBuildBuild = [
pkgsBuildHost.stdenv.cc
pkg-config
];
depsBuildTarget = lib.optionals stdenv.targetPlatform.isMinGW [ bintools ];
nativeBuildInputs = [
file
python3
rustc
cmake
which
libffi
removeReferencesTo
pkg-config
xz
]
++ optionals fastCross [
lndir
makeWrapper
];
buildInputs = [
openssl
]
++ optionals stdenv.hostPlatform.isDarwin [
zlib
]
++ optional (!withBundledLLVM) llvmShared.lib
++ optional (useLLVM && !withBundledLLVM) llvmPackages.libunwind;
outputs = [
"out"
"man"
"doc"
];
setOutputFlags = false;
postInstall =
lib.optionalString (enableRustcDev && !fastCross) ''
# install rustc-dev components. Necessary to build rls, clippy...
python x.py dist rustc-dev
tar xf build/dist/rustc-dev*tar.gz
cp -r rustc-dev*/rustc-dev*/lib/* $out/lib/
rm $out/lib/rustlib/install.log
for m in $out/lib/rustlib/manifest-rust*
do
sort --output=$m < $m
done
''
+ ''
# remove references to llvm-config in lib/rustlib/x86_64-unknown-linux-gnu/codegen-backends/librustc_codegen_llvm-llvm.so
# and thus a transitive dependency on ncurses
find $out/lib -name "*.so" -type f -exec remove-references-to -t ${llvmShared} '{}' '+'
# remove uninstall script that doesn't really make sense for Nix.
rm $out/lib/rustlib/uninstall.sh
'';
configurePlatforms = [ ];
enableParallelBuilding = true;
setupHooks = ./setup-hook.sh;
requiredSystemFeatures = [ "big-parallel" ];
passthru = {
llvm = llvmShared;
inherit llvmPackages;
inherit (rustc) targetPlatforms targetPlatformsWithHostTools badTargetPlatforms;
tests = {
inherit fd ripgrep wezterm;
}
// lib.optionalAttrs stdenv.hostPlatform.isLinux { inherit firefox thunderbird; };
};
meta = with lib; {
homepage = "https://www.rust-lang.org/";
description = "Safe, concurrent, practical language";
maintainers = with maintainers; [ havvy ];
teams = [ teams.rust ];
license = [
licenses.mit
licenses.asl20
];
platforms = rustc.targetPlatformsWithHostTools;
# If rustc can't target a platform, we also can't build rustc for
# that platform.
badPlatforms = rustc.badTargetPlatforms;
};
})

View File

@@ -0,0 +1,67 @@
{
lib,
stdenv,
cargo,
makeWrapper,
rustPlatform,
rustc,
asNightly ? false,
}:
rustPlatform.buildRustPackage {
pname = "rustfmt" + lib.optionalString asNightly "-nightly";
inherit (rustc) version src;
# the rust source tarball already has all the dependencies vendored, no need to fetch them again
cargoVendorDir = "vendor";
buildAndTestSubdir = "src/tools/rustfmt";
# changes hash of vendor directory otherwise
dontUpdateAutotoolsGnuConfigScripts = true;
nativeBuildInputs = [
makeWrapper
];
buildInputs = [
rustc.llvm
];
# rustfmt uses the rustc_driver and std private libraries, and Rust's build process forces them to have
# an install name of `@rpath/...` [0] [1] instead of the standard on macOS, which is an absolute path
# to itself.
#
# [0]: https://github.com/rust-lang/rust/blob/f77f4d55bdf9d8955d3292f709bd9830c2fdeca5/src/bootstrap/builder.rs#L1543
# [1]: https://github.com/rust-lang/rust/blob/f77f4d55bdf9d8955d3292f709bd9830c2fdeca5/compiler/rustc_codegen_ssa/src/back/linker.rs#L323-L331
preFixup = lib.optionalString stdenv.hostPlatform.isDarwin ''
install_name_tool -add_rpath "${rustc.unwrapped}/lib" "$out/bin/rustfmt"
install_name_tool -add_rpath "${rustc.unwrapped}/lib" "$out/bin/git-rustfmt"
'';
# As of 1.0.0 and rustc 1.30 rustfmt requires a nightly compiler
RUSTC_BOOTSTRAP = 1;
# As of rustc 1.45.0, these env vars are required to build rustfmt (due to
# https://github.com/rust-lang/rust/pull/72001)
CFG_RELEASE = rustc.version;
CFG_RELEASE_CHANNEL = if asNightly then "nightly" else "stable";
postInstall = ''
wrapProgram $out/bin/cargo-fmt \
--suffix PATH : ${lib.makeBinPath [ cargo ]}
'';
meta = with lib; {
description = "Tool for formatting Rust code according to style guidelines";
homepage = "https://github.com/rust-lang-nursery/rustfmt";
license = with licenses; [
mit
asl20
];
mainProgram = "rustfmt";
maintainers = with maintainers; [
globin
basvandijk
];
};
}

View File

@@ -0,0 +1,4 @@
# Fix 'failed to open: /homeless-shelter/.cargo/.package-cache' in rust 1.36.
if [[ -z ${IN_NIX_SHELL-} && -z ${CARGO_HOME-} ]]; then
export CARGO_HOME=$TMPDIR
fi