Skip to content

Commit 4864b5c

Browse files
committed
Auto merge of #4501 - matklad:top-level-features, r=alexcrichton
Move cargo features to top-level This should allow to add Cargo-features to virtual manifest as well. I've not actually added support for features in virtual manifests just yet, because that will probably require some refactoring to avoid duplicating feature-related code between virtual and usual manifests. r? @alexcrichton
2 parents 696413c + 70edd72 commit 4864b5c

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

src/cargo/util/toml/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ pub struct TomlManifest {
222222
patch: Option<HashMap<String, HashMap<String, TomlDependency>>>,
223223
workspace: Option<TomlWorkspace>,
224224
badges: Option<HashMap<String, HashMap<String, String>>>,
225+
#[serde(rename = "cargo-features")]
226+
cargo_features: Option<Vec<String>>,
225227
}
226228

227229
#[derive(Deserialize, Serialize, Clone, Debug, Default)]
@@ -389,8 +391,6 @@ pub struct TomlProject {
389391
include: Option<Vec<String>>,
390392
publish: Option<bool>,
391393
workspace: Option<String>,
392-
#[serde(rename = "cargo-features")]
393-
cargo_features: Option<Vec<String>>,
394394
#[serde(rename = "im-a-teapot")]
395395
im_a_teapot: Option<bool>,
396396

@@ -472,6 +472,7 @@ impl TomlManifest {
472472
patch: None,
473473
workspace: None,
474474
badges: self.badges.clone(),
475+
cargo_features: self.cargo_features.clone(),
475476
};
476477

477478
fn map_deps(deps: Option<&HashMap<String, TomlDependency>>)
@@ -649,7 +650,7 @@ impl TomlManifest {
649650
let profiles = build_profiles(&me.profile);
650651
let publish = project.publish.unwrap_or(true);
651652
let empty = Vec::new();
652-
let cargo_features = project.cargo_features.as_ref().unwrap_or(&empty);
653+
let cargo_features = me.cargo_features.as_ref().unwrap_or(&empty);
653654
let features = Features::new(&cargo_features, &mut warnings)?;
654655
let mut manifest = Manifest::new(summary,
655656
targets,

tests/cargo-features.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,12 @@ switch to nightly channel you can add
5252
fn unknown_feature() {
5353
let p = project("foo")
5454
.file("Cargo.toml", r#"
55+
cargo-features = ["foo"]
56+
5557
[package]
5658
name = "a"
5759
version = "0.0.1"
5860
authors = []
59-
cargo-features = ["foo"]
6061
"#)
6162
.file("src/lib.rs", "");
6263
assert_that(p.cargo_process("build"),
@@ -73,11 +74,12 @@ Caused by:
7374
fn stable_feature_warns() {
7475
let p = project("foo")
7576
.file("Cargo.toml", r#"
77+
cargo-features = ["test-dummy-stable"]
78+
7679
[package]
7780
name = "a"
7881
version = "0.0.1"
7982
authors = []
80-
cargo-features = ["test-dummy-stable"]
8183
"#)
8284
.file("src/lib.rs", "");
8385
assert_that(p.cargo_process("build"),
@@ -94,12 +96,13 @@ necessary to be listed in the manifest
9496
fn nightly_feature_requires_nightly() {
9597
let p = project("foo")
9698
.file("Cargo.toml", r#"
99+
cargo-features = ["test-dummy-unstable"]
100+
97101
[package]
98102
name = "a"
99103
version = "0.0.1"
100104
authors = []
101105
im-a-teapot = true
102-
cargo-features = ["test-dummy-unstable"]
103106
"#)
104107
.file("src/lib.rs", "");
105108
assert_that(p.cargo_process("build")
@@ -135,12 +138,13 @@ fn nightly_feature_requires_nightly_in_dep() {
135138
"#)
136139
.file("src/lib.rs", "")
137140
.file("a/Cargo.toml", r#"
141+
cargo-features = ["test-dummy-unstable"]
142+
138143
[package]
139144
name = "a"
140145
version = "0.0.1"
141146
authors = []
142147
im-a-teapot = true
143-
cargo-features = ["test-dummy-unstable"]
144148
"#)
145149
.file("a/src/lib.rs", "");
146150
assert_that(p.cargo_process("build")
@@ -173,12 +177,13 @@ Caused by:
173177
fn cant_publish() {
174178
let p = project("foo")
175179
.file("Cargo.toml", r#"
180+
cargo-features = ["test-dummy-unstable"]
181+
176182
[package]
177183
name = "a"
178184
version = "0.0.1"
179185
authors = []
180186
im-a-teapot = true
181-
cargo-features = ["test-dummy-unstable"]
182187
"#)
183188
.file("src/lib.rs", "");
184189
assert_that(p.cargo_process("build")
@@ -204,12 +209,13 @@ Caused by:
204209
fn z_flags_rejected() {
205210
let p = project("foo")
206211
.file("Cargo.toml", r#"
212+
cargo-features = ["test-dummy-unstable"]
213+
207214
[package]
208215
name = "a"
209216
version = "0.0.1"
210217
authors = []
211218
im-a-teapot = true
212-
cargo-features = ["test-dummy-unstable"]
213219
"#)
214220
.file("src/lib.rs", "");
215221
assert_that(p.cargo_process("build")
@@ -242,11 +248,12 @@ error: unknown `-Z` flag specified: arg
242248
fn publish_rejected() {
243249
let p = project("foo")
244250
.file("Cargo.toml", r#"
251+
cargo-features = ["test-dummy-unstable"]
252+
245253
[package]
246254
name = "a"
247255
version = "0.0.1"
248256
authors = []
249-
cargo-features = ["test-dummy-unstable"]
250257
"#)
251258
.file("src/lib.rs", "");
252259
assert_that(p.cargo_process("package")

0 commit comments

Comments
 (0)