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
# track of code coverage
myCrateCoverage = craneLib.cargoTarpaulin (commonArgs // {
# In this case we are choosing to only run our tarpaulin tests after
# 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;
inherit cargoArtifacts;
});
in
{
@ -236,40 +231,56 @@ build.
};
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
# all of that work (e.g. via cachix) when running in CI
cargoArtifacts = craneLib.buildDepsOnly {
inherit src;
};
cargoArtifacts = craneLib.buildDepsOnly (commonArgs // {
# 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.
my-crate-clippy = craneLib.cargoClippy {
inherit cargoArtifacts src;
myCrateClippy = craneLib.cargoClippy (commonArgs // {
# 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";
};
});
# 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.
my-crate-coverage = craneLib.cargoTarpaulin {
inherit src;
cargoArtifacts = my-crate-clippy;
};
myCrateCoverage = craneLib.cargoTarpaulin (commonArgs // {
cargoArtifacts = myCrateClippy;
});
# Build the actual crate itself, _but only if the previous tests pass_.
my-crate = craneLib.buildPackage {
cargoArtifacts = my-crate-coverage;
inherit src;
};
myCrate = craneLib.buildPackage (commonArgs // {
cargoArtifacts = myCrateCoverage;
});
in
{
defaultPackage = my-crate;
defaultPackage = myCrate;
checks = {
inherit
# Build the crate as part of `nix flake check` for convenience
my-crate
my-crate-coverage;
myCrate
myCrateCoverage;
};
});
}