From: Manish Goregaokar Date: Mon, 5 Feb 2018 16:29:31 +0000 (-0500) Subject: Pass -Zepoch flag when epoch feature exists X-Git-Tag: archive/raspbian/0.35.0-2+rpi1~3^2^2^2^2^2^2^2~22^2~3^2~10^2~3 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=2d1af7b56e88e3ac3de8ac9e9c57fb152d55aa3b;p=cargo.git Pass -Zepoch flag when epoch feature exists --- diff --git a/src/cargo/core/features.rs b/src/cargo/core/features.rs index 10597e55e..f5b6c7e72 100644 --- a/src/cargo/core/features.rs +++ b/src/cargo/core/features.rs @@ -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 { @@ -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. diff --git a/src/cargo/core/manifest.rs b/src/cargo/core/manifest.rs index 98d87abd0..18eb96b5f 100644 --- a/src/cargo/core/manifest.rs +++ b/src/cargo/core/manifest.rs @@ -359,6 +359,10 @@ impl Manifest { } } } + + pub fn epoch(&self) -> Epoch { + self.epoch + } } impl VirtualManifest { diff --git a/src/cargo/ops/cargo_rustc/mod.rs b/src/cargo/ops/cargo_rustc/mod.rs index 7a413194e..b32948576 100644 --- a/src/cargo/ops/cargo_rustc/mod.rs +++ b/src/cargo/ops/cargo_rustc/mod.rs @@ -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. diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index 623d794af..e66ac7494 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -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,