Skip to content

Consider cargo-hack #1680

Description

@makubacki

Makefile.toml has a task to run check and test with --no-default-features:

patina/Makefile.toml

Lines 190 to 205 in 75938f3

[tasks.check-no-default-features-code]
description = "Checks rust code compiles without default features."
private = true
command = "cargo"
args = ["check", "--no-default-features", "@@split(CARGO_MAKE_TASK_ARGS, )"]
[tasks.check-no-default-features-tests]
description = "Checks rust test code compiles without default features."
private = true
command = "cargo"
args = ["test", "--no-run", "--no-default-features", "@@split(CARGO_MAKE_TASK_ARGS, )"]
[tasks.check-no-default-features]
description = "Checks rust code and tests compile without default features to catch feature-gate regressions."
clear = true
run_task = [{ name = ["check-no-default-features-code", "check-no-default-features-tests"], parallel = true }]

This runs against the workspace (e.g. cargo make check-no-default-features -> cargo test --no-run --no-default-features for tests). Cargo unifies the feature set across the build graph. Some crates like patina/components/patina_acpi/Cargo.toml enable the alloc feature:

[dependencies]
log = { workspace = true }
memoffset = { workspace = true }
mockall = { workspace = true, optional = true }
zerocopy = { workspace = true }
zerocopy-derive = { workspace = true }
patina = { workspace = true, features = ["alloc"] }
patina_test = { workspace = true }

In general, the idea is to run check and test with --no-default-features per-crate going forward.


In that direction, the existing duckscript could be updated to enumerate packages, however, this issue proposes that we consider cargo-hack.

It provides a simple interface to do exactly this:

cargo-hack is basically wrapper of cargo that propagates subcommand and most of the passed flags to cargo, but provides additional flags and changes the behavior of some existing flags.

I've already integrated it into Makefile.toml and it is simple to use:

[tasks.check-no-default-features-code]
description = "Checks that each workspace crate compiles without its default features."
private = true
command = "cargo"
args = ["hack", "check", "--workspace", "--no-default-features", "@@split(CARGO_MAKE_TASK_ARGS, )"]

[tasks.check-no-default-features-tests]
description = "Checks that each workspace crate's test code compiles without its default features."
private = true
command = "cargo"
args = ["hack", "test", "--no-run", "--workspace", "--no-default-features", "@@split(CARGO_MAKE_TASK_ARGS, )"]

[tasks.check-no-default-features]
description = "Checks rust code and tests compile without default features to catch feature-gate regressions."
clear = true
run_task = [{ name = ["check-no-default-features-code", "check-no-default-features-tests"], parallel = true }]

However, this would require a new tool dependency in rust-toolchain.toml.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

Status
Backlog

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions