Skip to content

Commit

Permalink
Updates flake to fully embrace crane
Browse files Browse the repository at this point in the history
Crane is different from naersk in some important ways.

The new flake structure can now be easily extended to more examples,
and should make implementation of all CI workflows much simpler.
  • Loading branch information
jkaye2012 committed Jan 29, 2025
1 parent 76d947a commit 50301a3
Showing 1 changed file with 58 additions and 4 deletions.
62 changes: 58 additions & 4 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,47 @@
fenix' = fenix.packages.${system};
crane' = (crane.mkLib pkgs).overrideToolchain fenix'.complete.toolchain;
manifest = (pkgs.lib.importTOML ./Cargo.toml).package;

src = crane'.cleanCargoSource ./.;

buildExample =
{
src,
subdir,
args ? { },
}:
crane'.buildPackage {
inherit src;
cargoLock = ./${subdir}/Cargo.lock;
cargoToml = ./${subdir}/Cargo.toml;

postUnpack = ''
cd $sourceRoot/${subdir}
sourceRoot="."
'';
}
// args;

refined = crane'.buildPackage {
inherit src;
cargoTestExtraArgs = "--all-features";
};

refined-doc = crane'.cargoDoc {
inherit src;
cargoArtifacts = refined;
cargoDocExtraArgs = "--all-features";
};

refined-example-quickstart = buildExample {
inherit src;
subdir = "examples/quickstart";
};

refined-example-axum = buildExample {
inherit src;
subdir = "examples/axum";
};
in
{
devShells.${system}.default = pkgs.mkShell {
Expand All @@ -43,10 +84,23 @@
];
};

# TODO: ensure that docs and examples can be built
packages.${system}.default = crane'.buildPackage {
src = crane'.cleanCargoSource ./.;
cargoTestExtraArgs = "--all-features";
checks.${system} = {
inherit
refined
refined-doc
refined-example-axum
refined-example-quickstart
;
};

packages.${system} = rec {
inherit
refined
refined-doc
refined-example-axum
refined-example-quickstart
;
default = refined;
};
}
);
Expand Down

0 comments on commit 50301a3

Please sign in to comment.