Pass -Zepoch flag when epoch feature exists
authorManish Goregaokar <manishsmail@gmail.com>
Mon, 5 Feb 2018 16:29:31 +0000 (11:29 -0500)
committerManish Goregaokar <manishsmail@gmail.com>
Tue, 6 Feb 2018 03:02:25 +0000 (22:02 -0500)
src/cargo/core/features.rs
src/cargo/core/manifest.rs
src/cargo/ops/cargo_rustc/mod.rs
src/cargo/util/toml/mod.rs

index 10597e55ee6251fe81decd558f6fb64577f2f0c4..f5b6c7e720d835987cc8a2a3738be3c2725713b6 100644 (file)
@@ -40,6 +40,7 @@
 //! we'll be sure to update this documentation!
 
 use std::env;
+use std::fmt;
 use std::str::FromStr;
 
 use util::errors::CargoResult;
@@ -53,6 +54,14 @@ pub enum Epoch {
     Epoch2018,
 }
 
+impl fmt::Display for Epoch {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        match *self {
+            Epoch::Epoch2015 => f.write_str("2015"),
+            Epoch::Epoch2018 => f.write_str("2018"),
+        }
+    }
+}
 impl FromStr for Epoch {
     type Err = ();
     fn from_str(s: &str) -> Result<Self, ()> {
@@ -225,6 +234,10 @@ impl Features {
             bail!("{}", msg);
         }
     }
+
+    pub fn is_enabled(&self, feature: &Feature) -> bool {
+        feature.is_enabled(self)
+    }
 }
 
 /// A parsed representation of all unstable flags that Cargo accepts.
index 98d87abd0b41dc1eae768abbd081cfcd05f8ccdf..18eb96b5ff8f2caafc0daf08e268e40760a9a1c4 100644 (file)
@@ -359,6 +359,10 @@ impl Manifest {
             }
         }
     }
+
+    pub fn epoch(&self) -> Epoch {
+        self.epoch
+    }
 }
 
 impl VirtualManifest {
index 7a413194e206edf7fd77bfcce24dcaaeade77756..b3294857608893a61a8bb84dde9d2878b3cc0fc0 100644 (file)
@@ -9,7 +9,7 @@ use std::sync::Arc;
 use same_file::is_same_file;
 use serde_json;
 
-use core::{Package, PackageId, PackageSet, Target, Resolve};
+use core::{Feature, Package, PackageId, PackageSet, Target, Resolve};
 use core::{Profile, Profiles, Workspace};
 use core::manifest::Lto;
 use core::shell::ColorChoice;
@@ -804,6 +804,11 @@ fn build_base_args<'a, 'cfg>(cx: &mut Context<'a, 'cfg>,
             cmd.arg("-C").arg(format!("panic={}", panic));
         }
     }
+    let manifest = unit.pkg.manifest();
+
+    if manifest.features().is_enabled(Feature::epoch()) {
+        cmd.arg(format!("-Zepoch={}", manifest.epoch()));
+    }
 
     // Disable LTO for host builds as prefer_dynamic and it are mutually
     // exclusive.
index 623d794af82b3242a209e00aa08f69b79700c4aa..e66ac74943b8f4e2acbf20f1537488c192baf155 100644 (file)
@@ -727,7 +727,7 @@ impl TomlManifest {
                 bail!("the `epoch` key must be one of: `2015`, `2018`")
             }
         } else {
-            Epoch::Epoch2015
+                Epoch::Epoch2015
         };
         let mut manifest = Manifest::new(summary,
                                          targets,