Skip to content

Commit

Permalink
feat(rust-crane): add options for changing build, check and test carg…
Browse files Browse the repository at this point in the history
…o subcommands (#1072)
  • Loading branch information
yusdacra authored Nov 17, 2024
1 parent 44d4141 commit 607c990
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
14 changes: 8 additions & 6 deletions modules/dream2nix/rust-crane/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,19 @@
cargoVendorDir = "$TMPDIR/nix-vendor";
installCargoArtifactsMode = "use-zstd";

checkCargoCommand = cfg.checkCommand;
buildCargoCommand = cfg.buildCommand;
cargoBuildProfile = cfg.buildProfile;
cargoTestProfile = cfg.testProfile;
cargoBuildFlags = cfg.buildFlags;
testCargoCommand = cfg.testCommand;
cargoTestProfile = cfg.testProfile;
cargoTestFlags = cfg.testFlags;
doCheck = cfg.runTests;

# Make sure cargo only builds & tests the package we want
cargoBuildCommand = "cargo build \${cargoBuildFlags:-} --profile \${cargoBuildProfile} --package ${pname}";
cargoTestCommand = "cargo test \${cargoTestFlags:-} --profile \${cargoTestProfile} --package ${pname}";
# Make sure cargo only checks & builds & tests the package we want
cargoCheckCommand = "cargo \${checkCargoCommand} \${cargoBuildFlags:-} --profile \${cargoBuildProfile} --package ${pname}";
cargoBuildCommand = "cargo \${buildCargoCommand} \${cargoBuildFlags:-} --profile \${cargoBuildProfile} --package ${pname}";
cargoTestCommand = "cargo \${testCargoCommand} \${cargoTestFlags:-} --profile \${cargoTestProfile} --package ${pname}";
};

# The deps-only derivation will use this as a prefix to the `pname`
Expand All @@ -79,8 +83,6 @@
inherit (config.rust-cargo-lock) cargoLock;
pname = l.mkOverride 99 pname;
pnameSuffix = depsNameSuffix;
# Make sure cargo only checks the package we want
cargoCheckCommand = "cargo check \${cargoBuildFlags:-} --profile \${cargoBuildProfile} --package ${pname}";
dream2nixVendorDir = config.rust-cargo-vendor.vendoredSources;
};

Expand Down
30 changes: 23 additions & 7 deletions modules/dream2nix/rust-crane/interface.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,40 @@ in {
description = "Whether to run tests via `cargo test`";
default = true;
};
buildProfile = {
checkCommand = {
type = t.str;
description = "The profile to use when running `cargo build` and `cargo check`";
default = "release";
description = "The cargo subcommand to use when checking the crate (instead of 'check' in 'cargo check')";
default = "check";
example = "clippy";
};
testProfile = {
buildCommand = {
type = t.str;
description = "The cargo subcommand to use when building the crate (instead of 'build' in 'cargo build')";
default = "build";
};
buildProfile = {
type = t.str;
description = "The profile to use when running `cargo test`";
description = "The profile to use when building & checking";
default = "release";
};
buildFlags = {
type = t.listOf t.str;
description = "Flags to add when running `cargo build` and `cargo check`";
description = "Flags to add when building & checking";
default = [];
};
testCommand = {
type = t.str;
description = "The cargo subcommand to use when testing the crate (instead of 'test' in 'cargo test')";
default = "test";
};
testProfile = {
type = t.str;
description = "The profile to use when testing the crate";
default = "release";
};
testFlags = {
type = t.listOf t.str;
description = "Flags to add when running `cargo test`";
description = "Flags to add when testing the crate";
default = [];
};
depsDrv = {
Expand Down

0 comments on commit 607c990

Please sign in to comment.