From 8f6b608ca15ee2b1353eafb5c5768ec4c5db9e8c Mon Sep 17 00:00:00 2001 From: Ivan Petkov Date: Sun, 16 Jan 2022 18:24:13 -0800 Subject: [PATCH] Inline Cargo.{toml,lock} checks in `buildDepsOnly` --- lib/buildDepsOnly.nix | 17 ++++++++++++++++- lib/cargoBuild.nix | 22 +--------------------- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/lib/buildDepsOnly.nix b/lib/buildDepsOnly.nix index a8aff50..dc5b904 100644 --- a/lib/buildDepsOnly.nix +++ b/lib/buildDepsOnly.nix @@ -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; diff --git a/lib/cargoBuild.nix b/lib/cargoBuild.nix index 44e57ae..5846a8b 100644 --- a/lib/cargoBuild.nix +++ b/lib/cargoBuild.nix @@ -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}