Skip to content

Commit 0b9d54c

Browse files
author
Jorge Aparicio
committedOct 4, 2016
per target rustflags
"backport" of rust-lang/cargo#3157
1 parent 57166c2 commit 0b9d54c

File tree

3 files changed

+36
-19
lines changed

3 files changed

+36
-19
lines changed
 

Diff for: ‎CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ This project adheres to [Semantic Versioning](http://semver.org/).
55

66
## [Unreleased]
77

8+
### Added
9+
10+
- Xargo now supports per-target rustflags: `target.thumbv7em-none-eabihf.rustflags` in
11+
.cargo/config.
12+
813
## [v0.1.11] - 2016-09-30
914

1015
### Fixed

Diff for: ‎src/main.rs

+27-10
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use std::{env, fs, mem};
2121
use cargo::core::shell::{ColorConfig, Verbosity};
2222
use cargo::util::{self, CargoResult, ChainError, Config, Filesystem};
2323
use rustc_cfg::Cfg;
24+
use rustc_version::Channel;
2425

2526
mod sysroot;
2627

@@ -47,26 +48,35 @@ fn run(config_opt: &mut Option<Config>) -> CargoResult<()> {
4748
is not set")
4849
}));
4950

51+
let meta = rustc_version::version_meta_for(&config.rustc_info().verbose_version);
52+
if meta.channel != Channel::Nightly {
53+
return Err(util::human("Only the nightly channel is currently supported"));
54+
}
55+
5056
let (mut cargo, target, verbose, is_cargo_doc, verb) = try!(parse_args());
5157

52-
let rustflags = &try!(rustflags(config));
58+
let target = if let Some(target) = target {
59+
Some(target)
60+
} else {
61+
if let Some(triple) = try!(config.get_string("build.target")) {
62+
try!(Target::from(&triple.val))
63+
} else {
64+
None
65+
}
66+
};
67+
68+
let rustflags = &try!(rustflags(config, target.as_ref().map(|t| &t.triple), &meta.host));
5369
let profiles = &try!(parse_cargo_toml(config));
5470
let mut with_sysroot = false;
5571

5672
match verb.as_ref().map(|s| &**s) {
5773
// All these commands shouldn't trigger a sysroot rebuild
58-
Some("clean") | Some("new") | Some("init") | Some("update") | Some("search") => {},
74+
Some("clean") | Some("new") | Some("init") | Some("update") | Some("search") => {}
5975
_ => {
6076
if let Some(target) = target {
61-
try!(sysroot::create(config, &target, root, verbose, rustflags, profiles));
77+
try!(sysroot::create(config, &target, root, verbose, rustflags, profiles, meta));
6278
with_sysroot = true;
63-
} else if let Some(triple) = try!(config.get_string("build.target")) {
64-
if let Some(target) = try!(Target::from(&triple.val)) {
65-
try!(sysroot::create(config, &target, root, verbose, rustflags, profiles));
66-
with_sysroot = true;
67-
}
6879
}
69-
7080
}
7181
}
7282

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

202212
/// Returns the RUSTFLAGS the user has set either via the env variable or via build.rustflags
203213
// NOTE Logic copied from cargo's Context::rustflags_args
204-
fn rustflags(config: &Config) -> CargoResult<Vec<String>> {
214+
fn rustflags(config: &Config, target: Option<&String>, host: &String) -> CargoResult<Vec<String>> {
205215
// First try RUSTFLAGS from the environment
206216
if let Some(a) = env::var("RUSTFLAGS").ok() {
207217
let args = a.split(" ").map(str::trim).filter(|s| !s.is_empty()).map(str::to_string);
208218
return Ok(args.collect());
209219
}
210220

221+
// Then the target.*.rustflags value
222+
if let Some(args) =
223+
try!(config.get_list(&format!("target.{}.rustflags", target.unwrap_or(host)))) {
224+
let args = args.val.into_iter().map(|a| a.0);
225+
return Ok(args.collect());
226+
}
227+
211228
// Then the build.rustflags value
212229
if let Some(args) = try!(config.get_list("build.rustflags")) {
213230
let args = args.val.into_iter().map(|a| a.0);

Diff for: ‎src/sysroot.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use cargo::util::{self, CargoResult, ChainError, Config, FileLock, Filesystem};
88
use chrono::NaiveDate;
99
use curl::http;
1010
use flate2::read::GzDecoder;
11-
use rustc_version::{self, Channel};
1211
use tar::Archive;
12+
use rustc_version::VersionMeta;
1313
use tempdir::TempDir;
1414
use term::color::GREEN;
1515
use toml::Value;
@@ -65,14 +65,9 @@ pub fn create(config: &Config,
6565
root: &Filesystem,
6666
verbose: bool,
6767
rustflags: &[String],
68-
profiles: &Option<Value>)
68+
profiles: &Option<Value>,
69+
meta: VersionMeta)
6970
-> CargoResult<()> {
70-
let meta = rustc_version::version_meta_for(&config.rustc_info().verbose_version);
71-
72-
if meta.channel != Channel::Nightly {
73-
return Err(util::human("Only the nightly channel is currently supported"));
74-
}
75-
7671
let commit_date = try!(meta.commit_date
7772
.as_ref()
7873
.and_then(|s| NaiveDate::parse_from_str(s, "%Y-%m-%d").ok())
@@ -127,7 +122,7 @@ fn update_source(config: &Config,
127122
.timeout(0)
128123
.connect_timeout(30 * MS)
129124
.low_speed_limit(10 * B_PER_S)
130-
.low_speed_timeout(30 * S);;
125+
.low_speed_timeout(30 * S);
131126

132127
let url = format!("https://static.rust-lang.org/dist/{}/{}",
133128
date.format("%Y-%m-%d"),

0 commit comments

Comments
 (0)
Please sign in to comment.