Inline Cargo.{toml,lock} checks in buildDepsOnly

This commit is contained in:
Ivan Petkov 2022-01-16 18:24:13 -08:00
parent aeb598b174
commit 8f6b608ca1
No known key found for this signature in database
GPG Key ID: BB6F9EFC065832B6
2 changed files with 17 additions and 22 deletions

View File

@ -18,9 +18,24 @@ let
"cargoExtraArgs"
"cargoTestCommand"
];
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;
cargoToml = path + /Cargo.toml;
cargoLock = path + /Cargo.lock;
dummySrc =
if builtins.pathExists cargoToml && builtins.pathExists cargoLock
then mkDummySrc args
else throwMsg;
in
mkCargoDerivation (cleanedArgs // {
src = mkDummySrc args;
src = dummySrc;
pnameSuffix = "-deps";
pname = args.pname or crateName.pname;
version = args.version or crateName.version;

View File

@ -3,26 +3,6 @@
, mkCargoDerivation
, vendorCargoDeps
}:
let
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
then buildDepsOnly args
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
- set `cargoArtifacts = buildDepsOnly { src = ./some/path/to/cargo/root; }`
- set `cargoArtifacts = null` to skip reusing cargo artifacts altogether
''
else null;
in
{ cargoBuildCommand ? "cargo build --workspace --release"
, cargoTestCommand ? "cargo test --workspace --release"
@ -55,7 +35,7 @@ mkCargoDerivation (cleanedArgs // memoizedArgs // {
# 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 // memoizedArgs);
cargoArtifacts = args.cargoArtifacts or (buildDepsOnly args // memoizedArgs);
buildPhaseCargoCommand = args.buildPhaseCargoCommand or ''
${cargoBuildCommand} ${cargoExtraArgs}