Skip to content

Commit d3baa33

Browse files
committed
Support namespaced features
1 parent 58f6f3b commit d3baa33

File tree

5 files changed

+41
-1
lines changed

5 files changed

+41
-1
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Note: In this file, do not use the hard wrap in the middle of a sentence for com
1010

1111
## [Unreleased]
1212

13+
- Support namespaced features (features with `dep:` prefix). ([#154](https://github.com/taiki-e/cargo-hack/pull/154))
14+
1315
- Add metadata for cargo binstall.
1416

1517
## [0.5.14] - 2022-06-02

src/features.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,19 @@ impl Features {
1919

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

24+
for names in package.features.values() {
25+
for name in names {
26+
if let Some(name) = name.strip_prefix("dep:") {
27+
namespaced_features.push(name);
28+
}
29+
}
30+
}
2331
for name in package.optional_deps() {
24-
optional_deps.push(name);
32+
if !namespaced_features.contains(&name) {
33+
optional_deps.push(name);
34+
}
2535
}
2636
for name in package.features.keys() {
2737
if !optional_deps.contains(&&**name) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[package]
2+
name = "namespaced_features"
3+
version = "0.0.0"
4+
edition = "2021"
5+
publish = false
6+
7+
[workspace]
8+
resolver = "2"
9+
10+
[features]
11+
easytime = ["dep:easytime"]
12+
13+
[dependencies]
14+
easytime = { version = "0.2", optional = true, default-features = false }
15+
16+
[dev-dependencies]

tests/fixtures/namespaced_features/src/lib.rs

Whitespace-only changes.

tests/test.rs

+12
Original file line numberDiff line numberDiff line change
@@ -1393,3 +1393,15 @@ fn keep_going() {
13931393
",
13941394
));
13951395
}
1396+
1397+
#[test]
1398+
fn namespaced_features() {
1399+
cargo_hack(["check", "--feature-powerset"])
1400+
.assert_success2("namespaced_features", Some(60))
1401+
.stderr_contains(
1402+
"
1403+
running `cargo check --no-default-features` on namespaced_features (1/2)
1404+
running `cargo check --no-default-features --features easytime` on namespaced_features (2/2)
1405+
",
1406+
);
1407+
}

0 commit comments

Comments
 (0)