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-03 21:28:56 +03:00
|
|
|
, vendorCargoDepsFromArgs
|
2021-12-27 03:18:22 +03:00
|
|
|
}:
|
2021-12-29 02:27:49 +03:00
|
|
|
let
|
2021-12-31 01:46:35 +03:00
|
|
|
cargoArtifactsFromArgs = args:
|
|
|
|
if args ? src
|
|
|
|
then
|
|
|
|
let
|
|
|
|
path = args.src;
|
|
|
|
cargoToml = path + /Cargo.toml;
|
|
|
|
cargoLock = path + /Cargo.lock;
|
|
|
|
in
|
|
|
|
if builtins.pathExists cargoToml && builtins.pathExists cargoLock
|
2022-01-01 22:12:13 +03:00
|
|
|
then buildDepsOnly args
|
2021-12-31 01:46:35 +03:00
|
|
|
else
|
|
|
|
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
|
2021-12-31 01:49:52 +03:00
|
|
|
- set `cargoArtifacts = buildDepsOnly { src = ./some/path/to/cargo/root; }`
|
2021-12-31 01:46:35 +03:00
|
|
|
- set `cargoArtifacts = null` to skip reusing cargo artifacts altogether
|
|
|
|
''
|
|
|
|
else null;
|
2021-12-29 02:27:49 +03:00
|
|
|
in
|
2021-12-27 03:18:22 +03:00
|
|
|
|
2022-01-03 21:28:56 +03:00
|
|
|
{ cargoBuildCommand ? "cargo build --workspace --release"
|
2022-01-03 01:48:32 +03:00
|
|
|
, cargoTestCommand ? "cargo test --workspace --release"
|
|
|
|
, 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;
|
|
|
|
in
|
|
|
|
mkCargoDerivation (args // {
|
|
|
|
pname = args.pname or crateName.pname;
|
|
|
|
version = args.version or crateName.version;
|
2021-12-27 03:18:22 +03:00
|
|
|
|
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.
|
|
|
|
cargoArtifacts = args.cargoArtifacts or (cargoArtifactsFromArgs args);
|
|
|
|
|
|
|
|
# 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.
|
|
|
|
cargoVendorDir = args.cargoVendorDir or (vendorCargoDepsFromArgs args);
|
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}
|
|
|
|
'';
|
|
|
|
})
|