Also update README example 2

This commit is contained in:
Ivan Petkov 2022-05-12 16:16:21 -07:00
parent 8f2570a7cc
commit a233d51034
No known key found for this signature in database
GPG Key ID: BB6F9EFC065832B6

View File

@ -175,12 +175,7 @@ Here's how we can set up our flake to achieve our goals:
# Also run the crate tests under cargo-tarpaulin so that we can keep # Also run the crate tests under cargo-tarpaulin so that we can keep
# track of code coverage # track of code coverage
myCrateCoverage = craneLib.cargoTarpaulin (commonArgs // { myCrateCoverage = craneLib.cargoTarpaulin (commonArgs // {
# In this case we are choosing to only run our tarpaulin tests after inherit cargoArtifacts;
# we've checked everything with clippy first. If we do not want this
# we can uncomment the next line and delete the second one.
# inherit cargoArtifacts;
cargoArtifacts = myCrateClippy;
}); });
in in
{ {
@ -236,40 +231,56 @@ build.
}; };
craneLib = crane.lib.${system}; craneLib = crane.lib.${system};
src = ./.; # Common derivation arguments used for all builds
commonArgs = {
src = ./.;
buildInputs = with pkgs; [
# Add extra build inputs here, etc.
# openssl
];
nativeBuildInputs = with pkgs; [
# Add extra native build inputs here, etc.
# pkg-config
];
};
# Build *just* the cargo dependencies, so we can reuse # Build *just* the cargo dependencies, so we can reuse
# all of that work (e.g. via cachix) when running in CI # all of that work (e.g. via cachix) when running in CI
cargoArtifacts = craneLib.buildDepsOnly { cargoArtifacts = craneLib.buildDepsOnly (commonArgs // {
inherit src; # Additional arguments specific to this derivation can be added here.
}; # Be warned that using `//` will not do a deep copy of nested
# structures
pname = "mycrate-deps";
});
# First, run clippy (and deny all warnings) on the crate source. # First, run clippy (and deny all warnings) on the crate source.
my-crate-clippy = craneLib.cargoClippy { myCrateClippy = craneLib.cargoClippy (commonArgs // {
inherit cargoArtifacts src; # Again we apply some extra arguments only to this derivation
# and not every where else. In this case we add some clippy flags
inherit cargoArtifacts;
cargoClippyExtraArgs = "-- --deny warnings"; cargoClippyExtraArgs = "-- --deny warnings";
}; });
# Next, we want to run the tests and collect code-coverage, _but only if # Next, we want to run the tests and collect code-coverage, _but only if
# the clippy checks pass_ so we do not waste any extra cycles. # the clippy checks pass_ so we do not waste any extra cycles.
my-crate-coverage = craneLib.cargoTarpaulin { myCrateCoverage = craneLib.cargoTarpaulin (commonArgs // {
inherit src; cargoArtifacts = myCrateClippy;
cargoArtifacts = my-crate-clippy; });
};
# Build the actual crate itself, _but only if the previous tests pass_. # Build the actual crate itself, _but only if the previous tests pass_.
my-crate = craneLib.buildPackage { myCrate = craneLib.buildPackage (commonArgs // {
cargoArtifacts = my-crate-coverage; cargoArtifacts = myCrateCoverage;
inherit src; });
};
in in
{ {
defaultPackage = my-crate; defaultPackage = myCrate;
checks = { checks = {
inherit inherit
# Build the crate as part of `nix flake check` for convenience # Build the crate as part of `nix flake check` for convenience
my-crate myCrate
my-crate-coverage; myCrateCoverage;
}; };
}); });
} }