Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkgs/development/compilers/rust/1_72.nix
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ import ./default.nix {
rustcPatches = [ ];
}

(builtins.removeAttrs args [ "pkgsBuildTarget" "pkgsBuildBuild" "pkgsBuildHost" "llvmPackages_16" "llvm_16"])
(builtins.removeAttrs args [ "pkgsBuildTarget" "pkgsBuildHost" "llvmPackages_16" "llvm_16"])
14 changes: 14 additions & 0 deletions pkgs/development/compilers/rust/cargo_cross.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{ 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"
''
14 changes: 10 additions & 4 deletions pkgs/development/compilers/rust/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@
, buildPackages
, newScope, callPackage
, CoreFoundation, Security, SystemConfiguration
, pkgsBuildBuild
, makeRustPlatform
}:

let
# Use `import` to make sure no packages sneak in here.
lib' = import ../../../build-support/rust/lib { inherit lib; };
# Allow faster cross compiler generation by reusing Build artifacts
fastCross = (stdenv.buildPlatform == stdenv.hostPlatform) && (stdenv.hostPlatform != stdenv.targetPlatform);
in
{
lib = lib';
Expand Down Expand Up @@ -48,7 +51,10 @@ in
# 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 = self.buildRustPackages.overrideScope (_: _:
bootstrapRustPackages = if fastCross
then pkgsBuildBuild.rustPackages
else
self.buildRustPackages.overrideScope (_: _:
lib.optionalAttrs (stdenv.buildPlatform == stdenv.hostPlatform)
(selectRustPackage buildPackages).packages.prebuilt);
bootRustPlatform = makeRustPlatform bootstrapRustPackages;
Expand All @@ -61,7 +67,7 @@ in
version = rustcVersion;
sha256 = rustcSha256;
inherit enableRustcDev;
inherit llvmShared llvmSharedForBuild llvmSharedForHost llvmSharedForTarget llvmPackages;
inherit llvmShared llvmSharedForBuild llvmSharedForHost llvmSharedForTarget llvmPackages fastCross;

patches = rustcPatches;

Expand All @@ -72,11 +78,11 @@ in
inherit Security;
inherit (self.buildRustPackages) rustc;
};
cargo = self.callPackage ./cargo.nix {
cargo = if (!fastCross) then self.callPackage ./cargo.nix {
# Use boot package set to break cycle
rustPlatform = bootRustPlatform;
inherit CoreFoundation Security;
};
} 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 = self.callPackage ./clippy.nix {
Expand Down
44 changes: 40 additions & 4 deletions pkgs/development/compilers/rust/rustc.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
, wezterm
, firefox
, thunderbird
# This only builds std for target and reuses the rustc from build.
, fastCross
, lndir
, makeWrapper
}:

let
Expand Down Expand Up @@ -87,13 +91,13 @@ in stdenv.mkDerivation rec {
# (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) [
] ++ optionals (stdenv.buildPlatform != stdenv.targetPlatform && !fastCross) [
(rust.toRustTargetSpec stdenv.buildPlatform)

# (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) [
] ++ optionals (stdenv.hostPlatform != stdenv.targetPlatform && !fastCross) [
(rust.toRustTargetSpec stdenv.hostPlatform)
])}"

Expand Down Expand Up @@ -132,6 +136,37 @@ in stdenv.mkDerivation rec {
"--set rust.jemalloc"
];

# 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/${rust.toRustTargetSpec stdenv.hostPlatform}/stage0-{std,rustc}/${rust.toRustTargetSpec stdenv.hostPlatform}/release/
ln -s ${rustc}/lib/rustlib/${rust.toRustTargetSpec stdenv.hostPlatform}/libstd-*.so build/${rust.toRustTargetSpec stdenv.hostPlatform}/stage0-std/${rust.toRustTargetSpec stdenv.hostPlatform}/release/libstd.so
ln -s ${rustc}/lib/rustlib/${rust.toRustTargetSpec stdenv.hostPlatform}/librustc_driver-*.so build/${rust.toRustTargetSpec stdenv.hostPlatform}/stage0-rustc/${rust.toRustTargetSpec stdenv.hostPlatform}/release/librustc.so
ln -s ${rustc}/bin/rustc build/${rust.toRustTargetSpec stdenv.hostPlatform}/stage0-rustc/${rust.toRustTargetSpec stdenv.hostPlatform}/release/rustc-main
touch build/${rust.toRustTargetSpec stdenv.hostPlatform}/stage0-std/${rust.toRustTargetSpec stdenv.hostPlatform}/release/.libstd.stamp
touch build/${rust.toRustTargetSpec stdenv.hostPlatform}/stage0-rustc/${rust.toRustTargetSpec stdenv.hostPlatform}/release/.librustc.stamp
python ./x.py --keep-stage=0 --stage=1 build library/std

runHook postBuild
" else null;

installPhase = if fastCross then ''
runHook preInstall

python ./x.py --keep-stage=0 --stage=1 install library/std
mkdir -v $out/bin $doc $man
makeWrapper ${rustc}/bin/rustc $out/bin/rustc --add-flags "--sysroot $out"
makeWrapper ${rustc}/bin/rustdoc $out/bin/rustdoc --add-flags "--sysroot $out"
ln -s ${rustc}/lib/rustlib/{manifest-rust-std-,}${rust.toRustTargetSpec stdenv.hostPlatform} $out/lib/rustlib/
echo rust-std-${rust.toRustTargetSpec stdenv.hostPlatform} >> $out/lib/rustlib/components
lndir ${rustc.doc} $doc
lndir ${rustc.man} $man

runHook postInstall
'' else null;

# The bootstrap.py will generated a Makefile that then executes the build.
# The BOOTSTRAP_ARGS used by this Makefile must include all flags to pass
# to the bootstrap builder.
Expand Down Expand Up @@ -179,7 +214,8 @@ in stdenv.mkDerivation rec {
nativeBuildInputs = [
file python3 rustc cmake
which libffi removeReferencesTo pkg-config xz
];
]
++ optionals fastCross [ lndir makeWrapper ];

buildInputs = [ openssl ]
++ optionals stdenv.isDarwin [ libiconv Security ]
Expand All @@ -188,7 +224,7 @@ in stdenv.mkDerivation rec {
outputs = [ "out" "man" "doc" ];
setOutputFlags = false;

postInstall = lib.optionalString enableRustcDev ''
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
Expand Down