[feat] package: reduce rebuilds
All checks were successful
/ check (push) Successful in 2s
/ build (push) Successful in 55s

Only copy Rust sources to reduce rebuilds if only nix stuff (or CI)
changed.
This commit is contained in:
Jalil David Salamé Messina 2024-06-16 13:50:55 +02:00
parent ee65b5dcac
commit 841c357e2d
Signed by: jalil
GPG key ID: F016B9E770737A0B

View file

@ -6,13 +6,30 @@
cargoToml = readToml ./Cargo.toml; cargoToml = readToml ./Cargo.toml;
pname = cargoToml.package.name; pname = cargoToml.package.name;
inherit (cargoToml.package) version description; inherit (cargoToml.package) version description;
src = lib.cleanSourceWith {
src = ./.;
name = "${pname}-source";
# Adapted from <https://github.com/ipetkov/crane/blob/master/lib/filterCargoSources.nix>
# no need to pull in crane for just this
filter = orig_path: type: let
path = toString orig_path;
base = baseNameOf path;
parentDir = baseNameOf (dirOf path);
matchesSuffix = lib.any (suffix: lib.hasSuffix suffix base) [
# Rust sources
".rs"
# TOML files are often used to configure cargo based tools (e.g. .cargo/config.toml)
".toml"
];
isCargoLock = base == "Cargo.lock";
# .cargo/config.toml is captured above
isOldStyleCargoConfig = parentDir == ".cargo" && base == "config";
in
type == "directory" || matchesSuffix || isCargoLock || isOldStyleCargoConfig;
};
in in
rustPlatform.buildRustPackage { rustPlatform.buildRustPackage {
inherit pname version; inherit pname version src;
src = builtins.path {
path = ./.;
name = "${pname}-source";
};
cargoLock.lockFile = ./Cargo.lock; cargoLock.lockFile = ./Cargo.lock;
useNextest = true; useNextest = true;