crane/lib/mkCargoDerivation.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

79 lines
2.2 KiB
Nix
Raw Normal View History

{ cargo
, cargoHelperFunctionsHook
, configureCargoCommonVarsHook
, configureCargoVendoredDepsHook
, inheritCargoArtifactsHook
, installCargoArtifactsHook
, lib
, stdenv
}:
args@{
# A directory to an existing cargo `target` directory, which will be reused
# at the start of the derivation. Useful for caching incremental cargo builds.
cargoArtifacts
# A directory of vendored cargo sources which can be consumed without network
# access. Directory structure should basically follow the output of `cargo vendor`.
, cargoVendorDir
# A command (likely a cargo invocation) to run during the derivation's build
# phase. Pre and post build hooks will automatically be run.
, buildPhaseCargoCommand
# A command (likely a cargo invocation) to run during the derivation's check
# phase. Pre and post check hooks will automatically be run.
, checkPhaseCargoCommand
# A command to run during the derivation's install
# phase. Pre and post install hooks will automatically be run.
, installPhaseCommand ? "mkdir -p $out"
, ...
}:
let
chosenStdenv = args.stdenv or stdenv;
cleanedArgs = builtins.removeAttrs args [
"buildPhaseCargoCommand"
"checkPhaseCargoCommand"
"installPhaseCommand"
"pnameSuffix"
"stdenv"
];
in
chosenStdenv.mkDerivation (cleanedArgs // {
pname = "${args.pname}${args.pnameSuffix or ""}";
# Controls whether cargo's `target` directory should be copied as an output
doInstallCargoArtifacts = args.doInstallCargoArtifacts or true;
nativeBuildInputs = (args.nativeBuildInputs or [ ]) ++ [
cargo
cargoHelperFunctionsHook
configureCargoCommonVarsHook
configureCargoVendoredDepsHook
inheritCargoArtifactsHook
installCargoArtifactsHook
];
buildPhase = args.buildPhase or ''
runHook preBuild
cargo --version
${buildPhaseCargoCommand}
runHook postBuild
'';
checkPhase = args.checkPhase or ''
runHook preCheck
${checkPhaseCargoCommand}
runHook postCheck
'';
configurePhase = args.configurePhase or ''
runHook preConfigure
echo default configurePhase, nothing to do
runHook postConfigure
'';
installPhase = args.installPhase or ''
runHook preInstall
${installPhaseCommand}
runHook postInstall
'';
})