pytrainer: unpin python 3.10
[NixPkgs.git] / pkgs / build-support / rust / hooks / default.nix
blob7b55af079ee81fcc4db876787bab6bd425836764
1 { buildPackages
2 , callPackage
3 , cargo
4 , cargo-nextest
5 , clang
6 , lib
7 , makeSetupHook
8 , maturin
9 , rust
10 , rustc
11 , stdenv
13 # This confusingly-named parameter indicates the *subdirectory of
14 # `target/` from which to copy the build artifacts.  It is derived
15 # from a stdenv platform (or a JSON file).
16 , target ? stdenv.hostPlatform.rust.cargoShortTarget
20   cargoBuildHook = callPackage ({ }:
21     makeSetupHook {
22       name = "cargo-build-hook.sh";
23       propagatedBuildInputs = [ cargo ];
24       substitutions = {
25         inherit (rust.envVars) rustHostPlatformSpec setEnv;
26       };
27     } ./cargo-build-hook.sh) {};
29   cargoCheckHook = callPackage ({ }:
30     makeSetupHook {
31       name = "cargo-check-hook.sh";
32       propagatedBuildInputs = [ cargo ];
33       substitutions = {
34         inherit (rust.envVars) rustHostPlatformSpec setEnv;
35       };
36     } ./cargo-check-hook.sh) {};
38   cargoInstallHook = callPackage ({ }:
39     makeSetupHook {
40       name = "cargo-install-hook.sh";
41       propagatedBuildInputs = [ ];
42       substitutions = {
43         targetSubdirectory = target;
44       };
45     } ./cargo-install-hook.sh) {};
47   cargoNextestHook = callPackage ({ }:
48     makeSetupHook {
49       name = "cargo-nextest-hook.sh";
50       propagatedBuildInputs = [ cargo cargo-nextest ];
51       substitutions = {
52         inherit (rust.envVars) rustHostPlatformSpec;
53       };
54     } ./cargo-nextest-hook.sh) {};
56   cargoSetupHook = callPackage ({ }:
57     makeSetupHook {
58       name = "cargo-setup-hook.sh";
59       propagatedBuildInputs = [ ];
60       substitutions = {
61         defaultConfig = ../fetchcargo-default-config.toml;
63         # Specify the stdenv's `diff` by abspath to ensure that the user's build
64         # inputs do not cause us to find the wrong `diff`.
65         diff = "${lib.getBin buildPackages.diffutils}/bin/diff";
67         cargoConfig = ''
68           [target."${stdenv.buildPlatform.rust.rustcTarget}"]
69           "linker" = "${rust.envVars.ccForBuild}"
70           ${lib.optionalString (stdenv.buildPlatform.config != stdenv.hostPlatform.config) ''
71             [target."${stdenv.hostPlatform.rust.rustcTarget}"]
72             "linker" = "${rust.envVars.ccForHost}"
73           ''}
74           "rustflags" = [ "-C", "target-feature=${if stdenv.hostPlatform.isStatic then "+" else "-"}crt-static" ]
75         '';
76       };
77     } ./cargo-setup-hook.sh) {};
79   maturinBuildHook = callPackage ({ pkgsHostTarget }:
80     makeSetupHook {
81       name = "maturin-build-hook.sh";
82       propagatedBuildInputs = [
83         pkgsHostTarget.maturin
84         pkgsHostTarget.cargo
85         pkgsHostTarget.rustc
86       ];
87       substitutions = {
88         inherit (rust.envVars) rustTargetPlatformSpec setEnv;
89       };
90     } ./maturin-build-hook.sh) {};
92     bindgenHook = callPackage ({}: makeSetupHook {
93       name = "rust-bindgen-hook";
94       substitutions = {
95         libclang = clang.cc.lib;
96         inherit clang;
97       };
98     }
99     ./rust-bindgen-hook.sh) {};