Skip to content

Commit

Permalink
feat: add cargoLockParsed option (#270)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Ivan Petkov <[email protected]>
  • Loading branch information
figsoda and ipetkov authored Mar 20, 2023
1 parent 475de74 commit 77435da
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 16 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
["artifact dependencies" nightly feature](https://doc.rust-lang.org/cargo/reference/unstable.html#artifact-dependencies)
in case a crate is used as `bin` artifact dependency.
* Add `cargoLlvmCov` to run `cargo llvm-cov`
* Add `cargoLockParsed` option to `vendorCargoDeps` to support `Cargo.lock`
files parsed as nix attribute sets.

## [0.11.3] - 2023-02-19

Expand All @@ -21,6 +23,11 @@ in case a crate is used as `bin` artifact dependency.
* Fixed support for projects depending on crates utilising per-target workspace dependencies.

### Changed
* **Breaking** (technically): `mkCargoDerivation` will remove the following
attributes before lowering to `mkDerivation`: `cargoLock`, `cargoLockContents`
and `cargoLockParsed`. If your derivation needs these values to be present
they can be explicitly passed through via `.overrideAttrs`
`buildDepsOnly` as `dummySrc` will take priority
* A warning will now be emitted if a derivation's `pname` or `version`
attributes are not set and the value cannot be loaded from the derivation's
root `Cargo.toml`. To resolve it consider setting `pname = "...";` or `version
Expand Down
41 changes: 27 additions & 14 deletions checks/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,33 @@ in

# NB: explicitly using a github release (not crates.io release)
# which lacks a Cargo.lock file, so we can test adding our own
cargoLockOverride = myLib.buildPackage rec {
pname = "cargo-llvm-cov";
version = "0.4.14";

src = pkgs.fetchFromGitHub {
owner = "taiki-e";
repo = pname;
rev = "v${version}";
sha256 = "sha256-sNwizxYVUNyv5InR8HS+CyUsroA79h/FpouS+fMWJUI=";
};

doCheck = false; # Tests need llvm-tools installed
cargoLock = ./testCargoLockOverride.lock;
};
cargoLockOverride =
let
cargoLock = ./testCargoLockOverride.lock;
cargoLockContents = builtins.readFile cargoLock;
cargoLockParsed = builtins.fromTOML cargoLockContents;
in
pkgs.linkFarmFromDrvs "cargoLockOverride-tests" (map
(args:
myLib.buildPackage (args // rec {
pname = "cargo-llvm-cov";
version = "0.4.14";

src = pkgs.fetchFromGitHub {
owner = "taiki-e";
repo = pname;
rev = "v${version}";
sha256 = "sha256-sNwizxYVUNyv5InR8HS+CyUsroA79h/FpouS+fMWJUI=";
};

doCheck = false; # Tests need llvm-tools installed
}))
[
{ inherit cargoLock; }
{ inherit cargoLockContents; }
{ inherit cargoLockParsed; }
]
);

cargoTarpaulin = lib.optionalAttrs x64Linux (myLib.cargoTarpaulin {
src = ./simple;
Expand Down
4 changes: 4 additions & 0 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,9 @@ environment variables during the build, you can bring them back via
`.overrideAttrs`.

* `buildPhaseCargoCommand`
* `cargoLock`
* `cargoLockContents`
* `cargoLockParsed`
* `checkPhaseCargoCommand`
* `installPhaseCommand`
* `pnameSuffix`
Expand Down Expand Up @@ -1076,6 +1079,7 @@ the vendored directories (i.e. this configuration can be appended to the
* `src`: a directory which includes a Cargo.lock file at its root.
* `cargoLock`: a path to a Cargo.lock file
* `cargoLockContents`: the contents of a Cargo.lock file as a string
* `cargoLockParsed`: the parsed contents of Cargo.lock as an attribute set

At least one of the above attributes must be specified, or an error will be
raised during evaluation.
Expand Down
4 changes: 3 additions & 1 deletion lib/mkCargoDerivation.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
, crateNameFromCargoToml
, inheritCargoArtifactsHook
, installCargoArtifactsHook
, lib
, stdenv
, vendorCargoDeps
, zstd
Expand All @@ -31,6 +30,9 @@ let
chosenStdenv = args.stdenv or stdenv;
cleanedArgs = builtins.removeAttrs args [
"buildPhaseCargoCommand"
"cargoLock"
"cargoLockContents"
"cargoLockParsed"
"checkPhaseCargoCommand"
"installPhaseCommand"
"pnameSuffix"
Expand Down
2 changes: 1 addition & 1 deletion lib/vendorCargoDeps.nix
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ let
'')
(attrNames sources);

lock = builtins.fromTOML cargoLockContents;
lock = args.cargoLockParsed or (builtins.fromTOML cargoLockContents);
lockPackages = lock.package or (throw "Cargo.lock missing [[package]] definitions");

vendoredRegistries = vendorCargoRegistries {
Expand Down

0 comments on commit 77435da

Please sign in to comment.