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