1{ rustcVersion
2, rustcSha256
3, enableRustcDev ? true
4, bootstrapVersion
5, bootstrapHashes
6, selectRustPackage
7, rustcPatches ? []
8, llvmBootstrapForDarwin
9, llvmShared
10, llvmSharedForBuild
11, llvmSharedForHost
12, llvmSharedForTarget
13, llvmPackages # Exposed through rustc for LTO in Firefox
14}:
15{ stdenv, lib
16, buildPackages
17, newScope, callPackage
18, CoreFoundation, Security, SystemConfiguration
19, pkgsBuildTarget, pkgsBuildBuild
20, makeRustPlatform
21}:
22
23let
24 # Use `import` to make sure no packages sneak in here.
25 lib' = import ../../../build-support/rust/lib { inherit lib; };
26in
27{
28 lib = lib';
29
30 # Backwards compat before `lib` was factored out.
31 inherit (lib') toTargetArch toTargetOs toRustTarget toRustTargetSpec IsNoStdTarget;
32
33 # This just contains tools for now. But it would conceivably contain
34 # libraries too, say if we picked some default/recommended versions to build
35 # by Hydra.
36 #
37 # In the end game, rustc, the rust standard library (`core`, `std`, etc.),
38 # and cargo would themselves be built with `buildRustCreate` like
39 # everything else. Tools and `build.rs` and procedural macro dependencies
40 # would be taken from `buildRustPackages` (and `bootstrapRustPackages` for
41 # anything provided prebuilt or their build-time dependencies to break
42 # cycles / purify builds). In this way, nixpkgs would be in control of all
43 # bootstrapping.
44 packages = {
45 prebuilt = callPackage ./bootstrap.nix {
46 version = bootstrapVersion;
47 hashes = bootstrapHashes;
48 };
49 stable = lib.makeScope newScope (self: let
50 # Like `buildRustPackages`, but may also contain prebuilt binaries to
51 # break cycle. Just like `bootstrapTools` for nixpkgs as a whole,
52 # nothing in the final package set should refer to this.
53 bootstrapRustPackages = self.buildRustPackages.overrideScope' (_: _:
54 lib.optionalAttrs (stdenv.buildPlatform == stdenv.hostPlatform)
55 (selectRustPackage buildPackages).packages.prebuilt);
56 bootRustPlatform = makeRustPlatform bootstrapRustPackages;
57 in {
58 # Packages suitable for build-time, e.g. `build.rs`-type stuff.
59 buildRustPackages = (selectRustPackage buildPackages).packages.stable;
60 # Analogous to stdenv
61 rustPlatform = makeRustPlatform self.buildRustPackages;
62 rustc = self.callPackage ./rustc.nix ({
63 version = rustcVersion;
64 sha256 = rustcSha256;
65 inherit enableRustcDev;
66 inherit llvmShared llvmSharedForBuild llvmSharedForHost llvmSharedForTarget llvmPackages;
67
68 patches = rustcPatches;
69
70 # Use boot package set to break cycle
71 inherit (bootstrapRustPackages) cargo rustc;
72 rustPlatform = bootRustPlatform;
73 } // lib.optionalAttrs (stdenv.cc.isClang && stdenv.hostPlatform == stdenv.buildPlatform) {
74 stdenv = llvmBootstrapForDarwin.stdenv;
75 pkgsBuildBuild = pkgsBuildBuild // { targetPackages.stdenv = llvmBootstrapForDarwin.stdenv; };
76 pkgsBuildHost = pkgsBuildBuild // { targetPackages.stdenv = llvmBootstrapForDarwin.stdenv; };
77 pkgsBuildTarget = pkgsBuildTarget // { targetPackages.stdenv = llvmBootstrapForDarwin.stdenv; };
78 });
79 rustfmt = self.callPackage ./rustfmt.nix {
80 inherit Security;
81 inherit (self.buildRustPackages) rustc;
82 };
83 cargo = self.callPackage ./cargo.nix {
84 # Use boot package set to break cycle
85 rustPlatform = bootRustPlatform;
86 inherit CoreFoundation Security;
87 };
88 cargo-auditable = self.callPackage ./cargo-auditable.nix { };
89 cargo-auditable-cargo-wrapper = self.callPackage ./cargo-auditable-cargo-wrapper.nix { };
90 clippy = self.callPackage ./clippy.nix {
91 # We want to use self, not buildRustPackages, so that
92 # buildPackages.clippy uses the cross compiler and supports
93 # linting for the target platform.
94 rustPlatform = makeRustPlatform self;
95 inherit Security;
96 };
97 });
98 };
99}