core/pkgs/build-support/rust/hooks/default.nix

81 lines
2.8 KiB
Nix
Raw Normal View History

2024-05-13 21:24:10 +00:00
{ buildPackages, callPackage, cargo, cargo-nextest, clang, lib, makeSetupHook
, maturin, rust, rustc, stdenv
2024-05-02 00:46:19 +00:00
# This confusingly-named parameter indicates the *subdirectory of
# `target/` from which to copy the build artifacts. It is derived
# from a stdenv platform (or a JSON file).
2024-05-13 21:24:10 +00:00
, target ? stdenv.hostPlatform.rust.cargoShortTarget }:
2024-05-02 00:46:19 +00:00
{
cargoBuildHook = callPackage ({ }:
makeSetupHook {
name = "cargo-build-hook.sh";
propagatedBuildInputs = [ cargo ];
2024-05-13 21:24:10 +00:00
substitutions = { inherit (rust.envVars) rustHostPlatformSpec setEnv; };
} ./cargo-build-hook.sh) { };
2024-05-02 00:46:19 +00:00
cargoCheckHook = callPackage ({ }:
makeSetupHook {
name = "cargo-check-hook.sh";
propagatedBuildInputs = [ cargo ];
2024-05-13 21:24:10 +00:00
substitutions = { inherit (rust.envVars) rustHostPlatformSpec; };
} ./cargo-check-hook.sh) { };
2024-05-02 00:46:19 +00:00
cargoInstallHook = callPackage ({ }:
makeSetupHook {
name = "cargo-install-hook.sh";
propagatedBuildInputs = [ ];
2024-05-13 21:24:10 +00:00
substitutions = { targetSubdirectory = target; };
} ./cargo-install-hook.sh) { };
2024-05-02 00:46:19 +00:00
cargoNextestHook = callPackage ({ }:
makeSetupHook {
name = "cargo-nextest-hook.sh";
propagatedBuildInputs = [ cargo cargo-nextest ];
2024-05-13 21:24:10 +00:00
substitutions = { inherit (rust.envVars) rustHostPlatformSpec; };
} ./cargo-nextest-hook.sh) { };
2024-05-02 00:46:19 +00:00
cargoSetupHook = callPackage ({ }:
makeSetupHook {
name = "cargo-setup-hook.sh";
propagatedBuildInputs = [ ];
substitutions = {
defaultConfig = ../fetchcargo-default-config.toml;
# Specify the stdenv's `diff` by abspath to ensure that the user's build
# inputs do not cause us to find the wrong `diff`.
diff = "${lib.getBin buildPackages.diffutils}/bin/diff";
cargoConfig = ''
[target."${stdenv.buildPlatform.rust.rustcTarget}"]
"linker" = "${rust.envVars.linkerForBuild}"
2024-05-13 21:24:10 +00:00
${lib.optionalString
(stdenv.buildPlatform.config != stdenv.hostPlatform.config) ''
2024-05-02 00:46:19 +00:00
[target."${stdenv.hostPlatform.rust.rustcTarget}"]
"linker" = "${rust.envVars.linkerForHost}"
''}
2024-05-13 21:24:10 +00:00
"rustflags" = [ "-C", "target-feature=${
if stdenv.hostPlatform.isStatic then "+" else "-"
}crt-static" ]
2024-05-02 00:46:19 +00:00
'';
};
2024-05-13 21:24:10 +00:00
} ./cargo-setup-hook.sh) { };
2024-05-02 00:46:19 +00:00
maturinBuildHook = callPackage ({ pkgsHostTarget }:
makeSetupHook {
name = "maturin-build-hook.sh";
2024-05-13 21:24:10 +00:00
propagatedBuildInputs =
[ pkgsHostTarget.maturin pkgsHostTarget.cargo pkgsHostTarget.rustc ];
substitutions = { inherit (rust.envVars) rustTargetPlatformSpec setEnv; };
} ./maturin-build-hook.sh) { };
2024-05-02 00:46:19 +00:00
2024-05-13 21:24:10 +00:00
bindgenHook = callPackage ({ }:
makeSetupHook {
2024-05-02 00:46:19 +00:00
name = "rust-bindgen-hook";
substitutions = {
libclang = clang.cc.lib;
inherit clang;
};
2024-05-13 21:24:10 +00:00
} ./rust-bindgen-hook.sh) { };
2024-05-02 00:46:19 +00:00
}