1{ stdenv, lib
2, buildPackages
3, newScope, callPackage
4, CoreFoundation, Security
5, llvmPackages_5
6, pkgsBuildTarget, pkgsBuildBuild
7}: rec {
8 makeRustPlatform = { rustc, cargo, ... }: {
9 rust = {
10 inherit rustc cargo;
11 };
12
13 buildRustPackage = callPackage ../../../build-support/rust {
14 inherit rustc cargo;
15
16 fetchcargo = buildPackages.callPackage ../../../build-support/rust/fetchcargo.nix {
17 inherit cargo;
18 };
19 };
20
21 rustcSrc = callPackage ./rust-src.nix {
22 inherit rustc;
23 };
24 };
25
26 # This just contains tools for now. But it would conceivably contain
27 # libraries too, say if we picked some default/recommended versions from
28 # `cratesIO` to build by Hydra and/or try to prefer/bias in Cargo.lock for
29 # all vendored Carnix-generated nix.
30 #
31 # In the end game, rustc, the rust standard library (`core`, `std`, etc.),
32 # and cargo would themselves be built with `buildRustCreate` like
33 # everything else. Tools and `build.rs` and procedural macro dependencies
34 # would be taken from `buildRustPackages` (and `bootstrapRustPackages` for
35 # anything provided prebuilt or their build-time dependencies to break
36 # cycles / purify builds). In this way, nixpkgs would be in control of all
37 # bootstrapping.
38 packages = {
39 prebuilt = callPackage ./bootstrap.nix {};
40 stable = lib.makeScope newScope (self: let
41 # Like `buildRustPackages`, but may also contain prebuilt binaries to
42 # break cycle. Just like `bootstrapTools` for nixpkgs as a whole,
43 # nothing in the final package set should refer to this.
44 bootstrapRustPackages = self.buildRustPackages.overrideScope' (_: _:
45 lib.optionalAttrs (stdenv.buildPlatform == stdenv.hostPlatform)
46 buildPackages.rust.packages.prebuilt);
47 bootRustPlatform = makeRustPlatform bootstrapRustPackages;
48 in {
49 # Packages suitable for build-time, e.g. `build.rs`-type stuff.
50 buildRustPackages = buildPackages.rust.packages.stable;
51 # Analogous to stdenv
52 rustPlatform = makeRustPlatform self.buildRustPackages;
53 rustc = self.callPackage ./rustc.nix ({
54 # Use boot package set to break cycle
55 rustPlatform = bootRustPlatform;
56 } // lib.optionalAttrs (stdenv.cc.isClang && stdenv.hostPlatform == stdenv.buildPlatform) {
57 stdenv = llvmPackages_5.stdenv;
58 pkgsBuildBuild = pkgsBuildBuild // { targetPackages.stdenv = llvmPackages_5.stdenv; };
59 pkgsBuildHost = pkgsBuildBuild // { targetPackages.stdenv = llvmPackages_5.stdenv; };
60 pkgsBuildTarget = pkgsBuildTarget // { targetPackages.stdenv = llvmPackages_5.stdenv; };
61 });
62 rustfmt = self.callPackage ./rustfmt.nix { inherit Security; };
63 cargo = self.callPackage ./cargo.nix {
64 # Use boot package set to break cycle
65 rustPlatform = bootRustPlatform;
66 inherit CoreFoundation Security;
67 };
68 clippy = self.callPackage ./clippy.nix { inherit Security; };
69 rls = self.callPackage ./rls { inherit CoreFoundation Security; };
70 });
71 };
72}