crane/lib/mkCargoDerivation.nix
Ivan Petkov 352c7ff1b8
mkCargoDerivation: add default configurePhase (#106)
This is done to avoid breaking builds by including puts happen to have
setup-hooks which try to claim the configure phase (such as `cmake`).

The old behavior can be brought back by setting `configurePhase = null;`
on the derivation.
2022-09-18 01:18:03 +00:00

79 lines
2.2 KiB
Nix

{ 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
'';
})