Move cargo features to top-level
authorAleksey Kladov <aleksey.kladov@gmail.com>
Sun, 17 Sep 2017 17:58:14 +0000 (20:58 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Sun, 17 Sep 2017 17:58:57 +0000 (20:58 +0300)
This should allow to add Cargo-features to virtual manifest as well.

src/cargo/util/toml/mod.rs
tests/cargo-features.rs

index 7b802c317c8c41e26d4011e697cd060f64f20d70..1fe1771e51bb312d1eb5dca521a1aa50622e97be 100644 (file)
@@ -222,6 +222,8 @@ pub struct TomlManifest {
     patch: Option<HashMap<String, HashMap<String, TomlDependency>>>,
     workspace: Option<TomlWorkspace>,
     badges: Option<HashMap<String, HashMap<String, String>>>,
+    #[serde(rename = "cargo-features")]
+    cargo_features: Option<Vec<String>>,
 }
 
 #[derive(Deserialize, Serialize, Clone, Debug, Default)]
@@ -389,8 +391,6 @@ pub struct TomlProject {
     include: Option<Vec<String>>,
     publish: Option<bool>,
     workspace: Option<String>,
-    #[serde(rename = "cargo-features")]
-    cargo_features: Option<Vec<String>>,
     #[serde(rename = "im-a-teapot")]
     im_a_teapot: Option<bool>,
 
@@ -472,6 +472,7 @@ impl TomlManifest {
             patch: None,
             workspace: None,
             badges: self.badges.clone(),
+            cargo_features: self.cargo_features.clone(),
         };
 
         fn map_deps(deps: Option<&HashMap<String, TomlDependency>>)
@@ -649,7 +650,7 @@ impl TomlManifest {
         let profiles = build_profiles(&me.profile);
         let publish = project.publish.unwrap_or(true);
         let empty = Vec::new();
-        let cargo_features = project.cargo_features.as_ref().unwrap_or(&empty);
+        let cargo_features = me.cargo_features.as_ref().unwrap_or(&empty);
         let features = Features::new(&cargo_features, &mut warnings)?;
         let mut manifest = Manifest::new(summary,
                                          targets,
index 8ffc63d581e3c567dd22bf8b72ad14804089f636..55387fa7bc968db1ebfb925c5e4c01e6de90dbe5 100644 (file)
@@ -52,11 +52,12 @@ switch to nightly channel you can add
 fn unknown_feature() {
     let p = project("foo")
         .file("Cargo.toml", r#"
+            cargo-features = ["foo"]
+
             [package]
             name = "a"
             version = "0.0.1"
             authors = []
-            cargo-features = ["foo"]
         "#)
         .file("src/lib.rs", "");
     assert_that(p.cargo_process("build"),
@@ -73,11 +74,12 @@ Caused by:
 fn stable_feature_warns() {
     let p = project("foo")
         .file("Cargo.toml", r#"
+            cargo-features = ["test-dummy-stable"]
+
             [package]
             name = "a"
             version = "0.0.1"
             authors = []
-            cargo-features = ["test-dummy-stable"]
         "#)
         .file("src/lib.rs", "");
     assert_that(p.cargo_process("build"),
@@ -94,12 +96,13 @@ necessary to be listed in the manifest
 fn nightly_feature_requires_nightly() {
     let p = project("foo")
         .file("Cargo.toml", r#"
+            cargo-features = ["test-dummy-unstable"]
+
             [package]
             name = "a"
             version = "0.0.1"
             authors = []
             im-a-teapot = true
-            cargo-features = ["test-dummy-unstable"]
         "#)
         .file("src/lib.rs", "");
     assert_that(p.cargo_process("build")
@@ -135,12 +138,13 @@ fn nightly_feature_requires_nightly_in_dep() {
         "#)
         .file("src/lib.rs", "")
         .file("a/Cargo.toml", r#"
+            cargo-features = ["test-dummy-unstable"]
+
             [package]
             name = "a"
             version = "0.0.1"
             authors = []
             im-a-teapot = true
-            cargo-features = ["test-dummy-unstable"]
         "#)
         .file("a/src/lib.rs", "");
     assert_that(p.cargo_process("build")
@@ -173,12 +177,13 @@ Caused by:
 fn cant_publish() {
     let p = project("foo")
         .file("Cargo.toml", r#"
+            cargo-features = ["test-dummy-unstable"]
+
             [package]
             name = "a"
             version = "0.0.1"
             authors = []
             im-a-teapot = true
-            cargo-features = ["test-dummy-unstable"]
         "#)
         .file("src/lib.rs", "");
     assert_that(p.cargo_process("build")
@@ -204,12 +209,13 @@ Caused by:
 fn z_flags_rejected() {
     let p = project("foo")
         .file("Cargo.toml", r#"
+            cargo-features = ["test-dummy-unstable"]
+
             [package]
             name = "a"
             version = "0.0.1"
             authors = []
             im-a-teapot = true
-            cargo-features = ["test-dummy-unstable"]
         "#)
         .file("src/lib.rs", "");
     assert_that(p.cargo_process("build")
@@ -242,11 +248,12 @@ error: unknown `-Z` flag specified: arg
 fn publish_rejected() {
     let p = project("foo")
         .file("Cargo.toml", r#"
+            cargo-features = ["test-dummy-unstable"]
+
             [package]
             name = "a"
             version = "0.0.1"
             authors = []
-            cargo-features = ["test-dummy-unstable"]
         "#)
         .file("src/lib.rs", "");
     assert_that(p.cargo_process("package")