Skip to content

Commit

Permalink
Support namespaced features
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Jul 18, 2022
1 parent 58f6f3b commit d3baa33
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Note: In this file, do not use the hard wrap in the middle of a sentence for com

## [Unreleased]

- Support namespaced features (features with `dep:` prefix). ([#154](https://github.com/taiki-e/cargo-hack/pull/154))

- Add metadata for cargo binstall.

## [0.5.14] - 2022-06-02
Expand Down
12 changes: 11 additions & 1 deletion src/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,19 @@ impl Features {

let mut features = Vec::with_capacity(package.features.len());
let mut optional_deps = vec![];
let mut namespaced_features = vec![]; // features with `dep:` prefix

for names in package.features.values() {
for name in names {
if let Some(name) = name.strip_prefix("dep:") {
namespaced_features.push(name);
}
}
}
for name in package.optional_deps() {
optional_deps.push(name);
if !namespaced_features.contains(&name) {
optional_deps.push(name);
}
}
for name in package.features.keys() {
if !optional_deps.contains(&&**name) {
Expand Down
16 changes: 16 additions & 0 deletions tests/fixtures/namespaced_features/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "namespaced_features"
version = "0.0.0"
edition = "2021"
publish = false

[workspace]
resolver = "2"

[features]
easytime = ["dep:easytime"]

[dependencies]
easytime = { version = "0.2", optional = true, default-features = false }

[dev-dependencies]
Empty file.
12 changes: 12 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1393,3 +1393,15 @@ fn keep_going() {
",
));
}

#[test]
fn namespaced_features() {
cargo_hack(["check", "--feature-powerset"])
.assert_success2("namespaced_features", Some(60))
.stderr_contains(
"
running `cargo check --no-default-features` on namespaced_features (1/2)
running `cargo check --no-default-features --features easytime` on namespaced_features (2/2)
",
);
}

0 comments on commit d3baa33

Please sign in to comment.