crane/lib/buildDepsOnly.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

38 lines
1.1 KiB
Nix

{ crateNameFromCargoToml
, mkCargoDerivation
, mkDummySrc
, vendorCargoDepsFromArgs
}:
{ cargoExtraArgs ? ""
, cargoCheckCommand ? "cargo check --workspace --release"
, cargoBuildCommand ? "cargo build --workspace --release"
, cargoTestCommand ? "cargo test --workspace --release"
, ...
}@args:
let
crateName = crateNameFromCargoToml args;
in
mkCargoDerivation (args // {
src = mkDummySrc args;
pname = args.pname or "${crateName.pname}-deps";
version = args.version or crateName.version;
cargoArtifacts = null;
cargoVendorDir = args.cargoVendorDir or vendorCargoDepsFromArgs args;
# First we run `cargo check` to cache cargo's internal artifacts, fingerprints, etc. for all deps.
# Then we run `cargo build` to actually compile the deps and cache the results
buildPhaseCargoCommand = args.buildPhaseCargoCommand or ''
${cargoCheckCommand} ${cargoExtraArgs}
${cargoBuildCommand} ${cargoExtraArgs}
'';
checkPhaseCargoCommand = args.checkPhaseCargoCommand or ''
${cargoTestCommand} ${cargoExtraArgs}
'';
# No point in building this if not for the cargo artifacts
doCopyTargetToOutput = true;
})