2022-01-03 01:48:32 +03:00
|
|
|
{ crateNameFromCargoToml
|
2023-02-19 20:46:57 +03:00
|
|
|
, lib
|
2022-01-03 01:48:32 +03:00
|
|
|
, mkCargoDerivation
|
2021-12-31 01:46:35 +03:00
|
|
|
, mkDummySrc
|
2022-01-09 04:52:10 +03:00
|
|
|
, vendorCargoDeps
|
2021-12-31 01:46:35 +03:00
|
|
|
}:
|
|
|
|
|
2022-07-23 21:10:45 +03:00
|
|
|
{ cargoBuildCommand ? "cargoWithProfile build"
|
2022-10-10 01:04:37 +03:00
|
|
|
, cargoCheckCommand ? "cargoWithProfile check"
|
2023-08-27 22:17:58 +03:00
|
|
|
, cargoExtraArgs ? "--locked"
|
2022-07-23 21:10:45 +03:00
|
|
|
, cargoTestCommand ? "cargoWithProfile test"
|
2023-11-30 03:43:47 +03:00
|
|
|
, cargoTestExtraArgs ? "--no-run"
|
2022-01-03 01:48:32 +03:00
|
|
|
, ...
|
|
|
|
}@args:
|
2021-12-31 01:46:35 +03:00
|
|
|
let
|
|
|
|
crateName = crateNameFromCargoToml args;
|
2022-01-05 04:45:31 +03:00
|
|
|
cleanedArgs = builtins.removeAttrs args [
|
|
|
|
"cargoBuildCommand"
|
|
|
|
"cargoCheckCommand"
|
2022-10-10 01:04:37 +03:00
|
|
|
"cargoCheckExtraArgs"
|
2022-01-05 04:45:31 +03:00
|
|
|
"cargoExtraArgs"
|
|
|
|
"cargoTestCommand"
|
2022-10-10 01:04:37 +03:00
|
|
|
"cargoTestExtraArgs"
|
2023-09-22 07:08:53 +03:00
|
|
|
"outputHashes"
|
2022-09-27 09:25:09 +03:00
|
|
|
"dummySrc"
|
2024-01-27 20:52:30 +03:00
|
|
|
"outputs"
|
2022-01-05 04:45:31 +03:00
|
|
|
];
|
2022-01-17 05:24:13 +03:00
|
|
|
|
2022-11-28 06:23:35 +03:00
|
|
|
# Run tests by default to ensure we cache any dev-dependencies
|
|
|
|
doCheck = args.doCheck or true;
|
|
|
|
|
|
|
|
cargoCheckExtraArgs = args.cargoCheckExtraArgs or (if doCheck then "--all-targets" else "");
|
|
|
|
|
2023-02-19 20:46:57 +03:00
|
|
|
dummySrc =
|
|
|
|
if args ? dummySrc then
|
|
|
|
lib.warnIf
|
|
|
|
(args ? src && args.src != null)
|
|
|
|
"buildDepsOnly will ignore `src` when `dummySrc` is specified"
|
|
|
|
args.dummySrc
|
|
|
|
else
|
|
|
|
mkDummySrc args;
|
2022-01-03 01:48:32 +03:00
|
|
|
in
|
2022-01-05 04:45:31 +03:00
|
|
|
mkCargoDerivation (cleanedArgs // {
|
2022-11-28 06:23:35 +03:00
|
|
|
inherit doCheck;
|
|
|
|
|
2022-01-17 05:24:13 +03:00
|
|
|
src = dummySrc;
|
2022-01-05 04:45:31 +03:00
|
|
|
pnameSuffix = "-deps";
|
|
|
|
pname = args.pname or crateName.pname;
|
2022-01-03 01:48:32 +03:00
|
|
|
version = args.version or crateName.version;
|
2021-12-31 01:46:35 +03:00
|
|
|
|
2022-01-03 01:48:32 +03:00
|
|
|
cargoArtifacts = null;
|
2022-01-09 04:52:10 +03:00
|
|
|
cargoVendorDir = args.cargoVendorDir or (vendorCargoDeps args);
|
2021-12-31 01:46:35 +03:00
|
|
|
|
2024-10-13 02:28:15 +03:00
|
|
|
env = (args.env or { }) // {
|
|
|
|
# Export a marker variable in case any scripts or hooks want to customize
|
|
|
|
# how they run depending on if they are running here or with the "real"
|
|
|
|
# project sources.
|
|
|
|
# NB: *just* in case someone tries to set this to something specific, honor it
|
|
|
|
CRANE_BUILD_DEPS_ONLY = args.env.CRANE_BUILD_DEPS_ONLY or 1;
|
|
|
|
};
|
|
|
|
|
2022-01-03 01:48:32 +03:00
|
|
|
# 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 ''
|
2022-10-10 01:04:37 +03:00
|
|
|
${cargoCheckCommand} ${cargoExtraArgs} ${cargoCheckExtraArgs}
|
2022-01-03 01:48:32 +03:00
|
|
|
${cargoBuildCommand} ${cargoExtraArgs}
|
|
|
|
'';
|
|
|
|
|
|
|
|
checkPhaseCargoCommand = args.checkPhaseCargoCommand or ''
|
2022-10-10 01:04:37 +03:00
|
|
|
${cargoTestCommand} ${cargoExtraArgs} ${cargoTestExtraArgs}
|
2022-01-03 01:48:32 +03:00
|
|
|
'';
|
|
|
|
|
|
|
|
# No point in building this if not for the cargo artifacts
|
2022-01-09 04:14:05 +03:00
|
|
|
doInstallCargoArtifacts = true;
|
2022-01-03 01:48:32 +03:00
|
|
|
})
|