2022-01-03 01:48:32 +03:00
|
|
|
{ crateNameFromCargoToml
|
|
|
|
, 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-01-16 06:56:46 +03:00
|
|
|
{ cargoBuildCommand ? "cargo build --workspace --release"
|
2022-05-09 05:44:42 +03:00
|
|
|
, cargoCheckCommand ? "cargo check --workspace --release --all-targets"
|
2022-01-16 06:56:46 +03:00
|
|
|
, cargoExtraArgs ? ""
|
2022-01-03 01:48:32 +03:00
|
|
|
, cargoTestCommand ? "cargo test --workspace --release"
|
|
|
|
, ...
|
|
|
|
}@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"
|
|
|
|
"cargoExtraArgs"
|
|
|
|
"cargoTestCommand"
|
|
|
|
];
|
2022-01-17 05:24:13 +03:00
|
|
|
|
|
|
|
throwMsg = throw ''
|
|
|
|
unable to find Cargo.toml and Cargo.lock at ${path}. please ensure one of the following:
|
|
|
|
- a Cargo.toml and Cargo.lock exists at the root of the source directory of the derivation
|
|
|
|
- set `cargoArtifacts = buildDepsOnly { src = ./some/path/to/cargo/root; }`
|
|
|
|
- set `cargoArtifacts = null` to skip reusing cargo artifacts altogether
|
|
|
|
'';
|
|
|
|
|
|
|
|
path = args.src or throwMsg;
|
2022-02-13 23:50:43 +03:00
|
|
|
cargoToml = path + "/Cargo.toml";
|
|
|
|
cargoLock = path + "/Cargo.lock";
|
2022-01-17 05:24:13 +03:00
|
|
|
dummySrc =
|
|
|
|
if builtins.pathExists cargoToml && builtins.pathExists cargoLock
|
|
|
|
then mkDummySrc args
|
|
|
|
else throwMsg;
|
2022-01-03 01:48:32 +03:00
|
|
|
in
|
2022-01-05 04:45:31 +03:00
|
|
|
mkCargoDerivation (cleanedArgs // {
|
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
|
|
|
|
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 ''
|
|
|
|
${cargoCheckCommand} ${cargoExtraArgs}
|
|
|
|
${cargoBuildCommand} ${cargoExtraArgs}
|
|
|
|
'';
|
|
|
|
|
|
|
|
checkPhaseCargoCommand = args.checkPhaseCargoCommand or ''
|
|
|
|
${cargoTestCommand} ${cargoExtraArgs}
|
|
|
|
'';
|
|
|
|
|
2022-01-05 01:40:24 +03:00
|
|
|
# Run tests by default to ensure we cache any dev-dependencies
|
|
|
|
doCheck = args.doCheck or true;
|
|
|
|
|
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
|
|
|
})
|