summaryrefslogtreecommitdiffstats
path: root/pkgs/development/compilers/rust/make-rust-platform.nix
blob: 254ae918bbf6593ef7c1e62e88e891e1d07f950a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
{
  lib,
  buildPackages,
  callPackages,
  cargo-auditable,
  config,
  stdenv,
  runCommand,
  generateSplicesForMkScope,
  makeScopeWithSplicing',
}@prev:

{
  rustc,
  cargo,
  cargo-auditable ? prev.cargo-auditable,
  stdenv ? prev.stdenv,
  ...
}:

(makeScopeWithSplicing' {
  otherSplices = generateSplicesForMkScope "rustPlatform";
  f =
    self:
    let
      inherit (self) callPackage;
    in
    {
      fetchCargoVendor = buildPackages.callPackage ../../../build-support/rust/fetch-cargo-vendor.nix {
        inherit cargo;
      };

      buildRustPackage = callPackage ../../../build-support/rust/build-rust-package {
        inherit
          stdenv
          rustc
          cargo
          cargo-auditable
          ;
      };

      importCargoLock = buildPackages.callPackage ../../../build-support/rust/import-cargo-lock.nix {
        inherit cargo;
      };

      rustcSrc = callPackage ./rust-src.nix {
        inherit runCommand rustc;
      };

      rustLibSrc = callPackage ./rust-lib-src.nix {
        inherit runCommand rustc;
      };

      # Useful when rebuilding std
      # e.g. when building wasm with wasm-pack
      rustVendorSrc = callPackage ./rust-vendor-src.nix {
        inherit runCommand rustc;
      };

      # Hooks
      inherit
        (callPackages ../../../build-support/rust/hooks {
          inherit
            stdenv
            ;
        })
        cargoBuildHook
        cargoCheckHook
        cargoInstallHook
        cargoNextestHook
        cargoSetupHook
        maturinBuildHook
        bindgenHook
        ;

      # Let packages reference the build derivations, e.g. for disallowedReferences.
      # Get rid of the splicing though, so `nativeBuildInputs = [ rustPlatform.rust.rustc ]` works.
      rust = {
        rustc = rustc.__spliced.hostTarget or rustc;
        cargo = cargo.__spliced.hostTarget or cargo;
      };
    };
})
// lib.optionalAttrs config.allowAliases {
  # Added in 25.05.
  fetchCargoTarball = throw "`rustPlatform.fetchCargoTarball` has been removed in 25.05, use `rustPlatform.fetchCargoVendor` instead";
}