From 0b9d54cfc7f5fd2cc5bded8d9199e2ca5647e943 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Tue, 4 Oct 2016 00:34:10 -0500 Subject: [PATCH] per target rustflags "backport" of rust-lang/cargo#3157 --- CHANGELOG.md | 5 +++++ src/main.rs | 37 +++++++++++++++++++++++++++---------- src/sysroot.rs | 13 ++++--------- 3 files changed, 36 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 61dd6b7..f7d91d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +### Added + +- Xargo now supports per-target rustflags: `target.thumbv7em-none-eabihf.rustflags` in + .cargo/config. + ## [v0.1.11] - 2016-09-30 ### Fixed diff --git a/src/main.rs b/src/main.rs index e5adaef..be4b299 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,6 +21,7 @@ use std::{env, fs, mem}; use cargo::core::shell::{ColorConfig, Verbosity}; use cargo::util::{self, CargoResult, ChainError, Config, Filesystem}; use rustc_cfg::Cfg; +use rustc_version::Channel; mod sysroot; @@ -47,26 +48,35 @@ fn run(config_opt: &mut Option) -> CargoResult<()> { is not set") })); + let meta = rustc_version::version_meta_for(&config.rustc_info().verbose_version); + if meta.channel != Channel::Nightly { + return Err(util::human("Only the nightly channel is currently supported")); + } + let (mut cargo, target, verbose, is_cargo_doc, verb) = try!(parse_args()); - let rustflags = &try!(rustflags(config)); + let target = if let Some(target) = target { + Some(target) + } else { + if let Some(triple) = try!(config.get_string("build.target")) { + try!(Target::from(&triple.val)) + } else { + None + } + }; + + let rustflags = &try!(rustflags(config, target.as_ref().map(|t| &t.triple), &meta.host)); let profiles = &try!(parse_cargo_toml(config)); let mut with_sysroot = false; match verb.as_ref().map(|s| &**s) { // All these commands shouldn't trigger a sysroot rebuild - Some("clean") | Some("new") | Some("init") | Some("update") | Some("search") => {}, + Some("clean") | Some("new") | Some("init") | Some("update") | Some("search") => {} _ => { if let Some(target) = target { - try!(sysroot::create(config, &target, root, verbose, rustflags, profiles)); + try!(sysroot::create(config, &target, root, verbose, rustflags, profiles, meta)); with_sysroot = true; - } else if let Some(triple) = try!(config.get_string("build.target")) { - if let Some(target) = try!(Target::from(&triple.val)) { - try!(sysroot::create(config, &target, root, verbose, rustflags, profiles)); - with_sysroot = true; - } } - } } @@ -201,13 +211,20 @@ fn parse_args() -> CargoResult<(Command, Option, bool, bool, Option CargoResult> { +fn rustflags(config: &Config, target: Option<&String>, host: &String) -> CargoResult> { // First try RUSTFLAGS from the environment if let Some(a) = env::var("RUSTFLAGS").ok() { let args = a.split(" ").map(str::trim).filter(|s| !s.is_empty()).map(str::to_string); return Ok(args.collect()); } + // Then the target.*.rustflags value + if let Some(args) = + try!(config.get_list(&format!("target.{}.rustflags", target.unwrap_or(host)))) { + let args = args.val.into_iter().map(|a| a.0); + return Ok(args.collect()); + } + // Then the build.rustflags value if let Some(args) = try!(config.get_list("build.rustflags")) { let args = args.val.into_iter().map(|a| a.0); diff --git a/src/sysroot.rs b/src/sysroot.rs index b8434da..6e3cf51 100644 --- a/src/sysroot.rs +++ b/src/sysroot.rs @@ -8,8 +8,8 @@ use cargo::util::{self, CargoResult, ChainError, Config, FileLock, Filesystem}; use chrono::NaiveDate; use curl::http; use flate2::read::GzDecoder; -use rustc_version::{self, Channel}; use tar::Archive; +use rustc_version::VersionMeta; use tempdir::TempDir; use term::color::GREEN; use toml::Value; @@ -65,14 +65,9 @@ pub fn create(config: &Config, root: &Filesystem, verbose: bool, rustflags: &[String], - profiles: &Option) + profiles: &Option, + meta: VersionMeta) -> CargoResult<()> { - let meta = rustc_version::version_meta_for(&config.rustc_info().verbose_version); - - if meta.channel != Channel::Nightly { - return Err(util::human("Only the nightly channel is currently supported")); - } - let commit_date = try!(meta.commit_date .as_ref() .and_then(|s| NaiveDate::parse_from_str(s, "%Y-%m-%d").ok()) @@ -127,7 +122,7 @@ fn update_source(config: &Config, .timeout(0) .connect_timeout(30 * MS) .low_speed_limit(10 * B_PER_S) - .low_speed_timeout(30 * S);; + .low_speed_timeout(30 * S); let url = format!("https://static.rust-lang.org/dist/{}/{}", date.format("%Y-%m-%d"),