2021-12-31 01:49:52 +03:00
|
|
|
{ buildDepsOnly
|
2021-12-31 01:46:35 +03:00
|
|
|
, crateNameFromCargoToml
|
2022-01-03 01:48:32 +03:00
|
|
|
, mkCargoDerivation
|
2022-01-09 04:52:10 +03:00
|
|
|
, vendorCargoDeps
|
2021-12-27 03:18:22 +03:00
|
|
|
}:
|
|
|
|
|
2022-07-21 05:27:52 +03:00
|
|
|
{ cargoBuildCommand ? "cargo build --release"
|
|
|
|
, cargoTestCommand ? "cargo test --release"
|
2022-01-03 01:48:32 +03:00
|
|
|
, cargoExtraArgs ? ""
|
2021-12-27 05:06:19 +03:00
|
|
|
, ...
|
|
|
|
}@args:
|
2021-12-29 02:15:10 +03:00
|
|
|
let
|
2022-01-03 01:48:32 +03:00
|
|
|
crateName = crateNameFromCargoToml args;
|
2022-01-05 04:45:31 +03:00
|
|
|
cleanedArgs = builtins.removeAttrs args [
|
|
|
|
"cargoBuildCommand"
|
|
|
|
"cargoExtraArgs"
|
|
|
|
"cargoTestCommand"
|
|
|
|
];
|
2021-12-27 03:18:22 +03:00
|
|
|
|
2022-01-05 05:25:39 +03:00
|
|
|
# Avoid recomputing values when passing args down
|
|
|
|
memoizedArgs = {
|
|
|
|
pname = args.pname or crateName.pname;
|
|
|
|
version = args.version or crateName.version;
|
|
|
|
|
|
|
|
# A directory of vendored cargo sources which can be consumed without network
|
|
|
|
# access. Directory structure should basically follow the output of `cargo vendor`.
|
|
|
|
# This can be inferred automatically if the `src` root has a Cargo.lock file.
|
2022-01-09 04:52:10 +03:00
|
|
|
cargoVendorDir = args.cargoVendorDir or (vendorCargoDeps args);
|
2022-01-05 05:25:39 +03:00
|
|
|
};
|
|
|
|
in
|
|
|
|
mkCargoDerivation (cleanedArgs // memoizedArgs // {
|
2022-01-05 01:40:24 +03:00
|
|
|
doCheck = args.doCheck or true;
|
|
|
|
|
2022-01-03 21:28:56 +03:00
|
|
|
# A directory to an existing cargo `target` directory, which will be reused
|
|
|
|
# at the start of the derivation. Useful for caching incremental cargo builds.
|
|
|
|
# This can be inferred automatically if the `src` root has both a Cargo.toml
|
|
|
|
# and Cargo.lock file.
|
2022-01-17 05:24:13 +03:00
|
|
|
cargoArtifacts = args.cargoArtifacts or (buildDepsOnly args // memoizedArgs);
|
2021-12-31 01:46:35 +03:00
|
|
|
|
2022-01-03 01:48:32 +03:00
|
|
|
buildPhaseCargoCommand = args.buildPhaseCargoCommand or ''
|
|
|
|
${cargoBuildCommand} ${cargoExtraArgs}
|
|
|
|
'';
|
|
|
|
|
|
|
|
checkPhaseCargoCommand = args.checkPhaseCargoCommand or ''
|
|
|
|
${cargoTestCommand} ${cargoExtraArgs}
|
|
|
|
'';
|
|
|
|
})
|