Skip to content

Commit

Permalink
Merge pull request #53 from japaric/target-rustflags
Browse files Browse the repository at this point in the history
per target rustflags
  • Loading branch information
Jorge Aparicio authored Oct 4, 2016
2 parents 57166c2 + 0b9d54c commit 76940a2
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 19 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 27 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -47,26 +48,35 @@ fn run(config_opt: &mut Option<Config>) -> 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;
}
}

}
}

Expand Down Expand Up @@ -201,13 +211,20 @@ fn parse_args() -> CargoResult<(Command, Option<Target>, bool, bool, Option<Stri

/// Returns the RUSTFLAGS the user has set either via the env variable or via build.rustflags
// NOTE Logic copied from cargo's Context::rustflags_args
fn rustflags(config: &Config) -> CargoResult<Vec<String>> {
fn rustflags(config: &Config, target: Option<&String>, host: &String) -> CargoResult<Vec<String>> {
// 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);
Expand Down
13 changes: 4 additions & 9 deletions src/sysroot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -65,14 +65,9 @@ pub fn create(config: &Config,
root: &Filesystem,
verbose: bool,
rustflags: &[String],
profiles: &Option<Value>)
profiles: &Option<Value>,
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())
Expand Down Expand Up @@ -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"),
Expand Down

0 comments on commit 76940a2

Please sign in to comment.