crane/lib/mkCargoDerivation.nix
Ivan Petkov dc553e3853
Remove installFromCargoArtifactsHook
* This hook was never a great implementation to begin with since it
  would simply search the cargo artifacts directory for binaries and
  libraries to install
* This isn't really great since if we have multiple builds (say one with
  debug artifacts, one with release artifacts) it isn't exactly clear
  which artifacts would get installed (or which will get clobbered).
* Now that we have installFromCargoBuildLogHook we can simplify the
  options a bit and only have one main installation method. The caller
  can always provide their own if they wish
2022-01-03 14:42:59 -08:00

65 lines
2.1 KiB
Nix

{ cargo
, configureCargoCommonVarsHook
, configureCargoVendoredDepsHook
, copyCargoTargetToOutputHook
, inheritCargoArtifactsHook
, remapSourcePathPrefixHook
, 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"
, ...
}:
stdenv.mkDerivation (args // {
# Controls whether cargo's `target` directory should be copied as an output
doCopyTargetToOutput = args.doCopyTargetToOutput or true;
# Controls instructing rustc to remap the path prefix of any sources it
# captures (for example, this can include file names in panic info). This is
# useful to omit any references to `/nix/store/...` from the final binary,
# as including them will make Nix pull in all sources when installing any binaries.
doRemapSourcePathPrefix = args.doRemapSourcePathPrefix or true;
nativeBuildInputs = (args.nativeBuildInputs or [ ]) ++ [
cargo
configureCargoCommonVarsHook
configureCargoVendoredDepsHook
copyCargoTargetToOutputHook
inheritCargoArtifactsHook
remapSourcePathPrefixHook
];
buildPhase = args.buildPhase or ''
runHook preBuild
${buildPhaseCargoCommand}
runHook postBuild
'';
checkPhase = args.checkPhase or ''
runHook preCheck
${checkPhaseCargoCommand}
runHook postCheck
'';
installPhase = args.installPhase or ''
runHook preInstall
${installPhaseCommand}
runHook postInstall
'';
})