1{
2 rustcVersion,
3 rustcSha256,
4 enableRustcDev ? true,
5 bootstrapVersion,
6 bootstrapHashes,
7 selectRustPackage,
8 rustcPatches ? [ ],
9 llvmShared,
10 llvmSharedForBuild,
11 llvmSharedForHost,
12 llvmSharedForTarget,
13 llvmPackages, # Exposed through rustc for LTO in Firefox
14}:
15{
16 stdenv,
17 lib,
18 newScope,
19 callPackage,
20 pkgsBuildBuild,
21 pkgsBuildHost,
22 pkgsBuildTarget,
23 pkgsTargetTarget,
24 makeRustPlatform,
25 wrapRustcWith,
26}:
27
28let
29 # Use `import` to make sure no packages sneak in here.
30 lib' = import ../../../build-support/rust/lib {
31 inherit
32 lib
33 stdenv
34 pkgsBuildHost
35 pkgsBuildTarget
36 pkgsTargetTarget
37 ;
38 };
39 # Allow faster cross compiler generation by reusing Build artifacts
40 fastCross =
41 (stdenv.buildPlatform == stdenv.hostPlatform) && (stdenv.hostPlatform != stdenv.targetPlatform);
42in
43{
44 lib = lib';
45
46 # Backwards compat before `lib` was factored out.
47 inherit (lib')
48 toTargetArch
49 toTargetOs
50 toRustTarget
51 toRustTargetSpec
52 IsNoStdTarget
53 toRustTargetForUseInEnvVars
54 envVars
55 ;
56
57 # This just contains tools for now. But it would conceivably contain
58 # libraries too, say if we picked some default/recommended versions to build
59 # by Hydra.
60 #
61 # In the end game, rustc, the rust standard library (`core`, `std`, etc.),
62 # and cargo would themselves be built with `buildRustCreate` like
63 # everything else. Tools and `build.rs` and procedural macro dependencies
64 # would be taken from `buildRustPackages` (and `bootstrapRustPackages` for
65 # anything provided prebuilt or their build-time dependencies to break
66 # cycles / purify builds). In this way, nixpkgs would be in control of all
67 # bootstrapping.
68 packages = {
69 prebuilt = callPackage ./bootstrap.nix {
70 version = bootstrapVersion;
71 hashes = bootstrapHashes;
72 };
73 stable = lib.makeScope newScope (
74 self:
75 let
76 # Like `buildRustPackages`, but may also contain prebuilt binaries to
77 # break cycle. Just like `bootstrapTools` for nixpkgs as a whole,
78 # nothing in the final package set should refer to this.
79 bootstrapRustPackages =
80 if fastCross then
81 pkgsBuildBuild.rustPackages
82 else
83 self.buildRustPackages.overrideScope (
84 _: _:
85 lib.optionalAttrs (stdenv.buildPlatform == stdenv.hostPlatform)
86 (selectRustPackage pkgsBuildHost).packages.prebuilt
87 );
88 bootRustPlatform = makeRustPlatform bootstrapRustPackages;
89 in
90 {
91 # Packages suitable for build-time, e.g. `build.rs`-type stuff.
92 buildRustPackages = (selectRustPackage pkgsBuildHost).packages.stable;
93 # Analogous to stdenv
94 rustPlatform = makeRustPlatform self.buildRustPackages;
95 rustc-unwrapped = self.callPackage ./rustc.nix ({
96 version = rustcVersion;
97 sha256 = rustcSha256;
98 inherit enableRustcDev;
99 inherit
100 llvmShared
101 llvmSharedForBuild
102 llvmSharedForHost
103 llvmSharedForTarget
104 llvmPackages
105 fastCross
106 ;
107
108 patches = rustcPatches;
109
110 # Use boot package set to break cycle
111 inherit (bootstrapRustPackages) cargo rustc rustfmt;
112 });
113 rustc = wrapRustcWith {
114 inherit (self) rustc-unwrapped;
115 sysroot = if fastCross then self.rustc-unwrapped else null;
116 };
117 rustfmt = self.callPackage ./rustfmt.nix {
118 inherit (self.buildRustPackages) rustc;
119 };
120 cargo =
121 if (!fastCross) then
122 self.callPackage ./cargo.nix {
123 # Use boot package set to break cycle
124 rustPlatform = bootRustPlatform;
125 }
126 else
127 self.callPackage ./cargo_cross.nix { };
128 cargo-auditable = self.callPackage ./cargo-auditable.nix { };
129 cargo-auditable-cargo-wrapper = self.callPackage ./cargo-auditable-cargo-wrapper.nix { };
130 clippy-unwrapped = self.callPackage ./clippy.nix { };
131 clippy = if !fastCross then self.clippy-unwrapped else self.callPackage ./clippy-wrapper.nix { };
132 }
133 );
134 };
135}