From 744205065cfe06f35e299ebecb4f710ad0bc8534 Mon Sep 17 00:00:00 2001 From: fpgaminer Date: Sat, 30 Jan 2016 00:31:42 -0800 Subject: [PATCH] Set target using config file --- src/cargo/ops/cargo_compile.rs | 3 +++ src/doc/config.md | 1 + tests/test_cargo_cross_compile.rs | 36 +++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index b4cebffd6e5..ba7716f12b5 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -412,6 +412,7 @@ fn source_ids_from_config(config: &Config, cur_path: &Path) /// configured options are: /// /// * build.jobs +/// * build.target /// * target.$target.ar /// * target.$target.linker /// * target.$target.libfoo.metadata @@ -432,6 +433,8 @@ fn scrape_build_config(config: &Config, None => None, }; let jobs = jobs.or(cfg_jobs).unwrap_or(::num_cpus::get() as u32); + let cfg_target = try!(config.get_string("build.target")).map(|s| s.0); + let target = target.or(cfg_target); let mut base = ops::BuildConfig { jobs: jobs, requested_target: target.clone(), diff --git a/src/doc/config.md b/src/doc/config.md index b45ae23ad28..d911e87bf2f 100644 --- a/src/doc/config.md +++ b/src/doc/config.md @@ -84,6 +84,7 @@ timeout = 60000 # Timeout for each HTTP request, in milliseconds jobs = 1 # number of jobs to run by default (default to # cpus) rustc = "rustc" # the rust compiler tool rustdoc = "rustdoc" # the doc generator tool +target = "triple" # build for the target triple target-dir = "target" # path of where to place all generated artifacts ``` diff --git a/tests/test_cargo_cross_compile.rs b/tests/test_cargo_cross_compile.rs index 06686bf9087..6536c526e0d 100644 --- a/tests/test_cargo_cross_compile.rs +++ b/tests/test_cargo_cross_compile.rs @@ -78,6 +78,42 @@ test!(simple_cross { execs().with_status(0)); }); +test!(simple_cross_config { + if disabled() { return } + + let p = project("foo") + .file(".cargo/config", &format!(r#" + [build] + target = "{}" + "#, alternate())) + .file("Cargo.toml", r#" + [package] + name = "foo" + version = "0.0.0" + authors = [] + build = "build.rs" + "#) + .file("build.rs", &format!(r#" + fn main() {{ + assert_eq!(std::env::var("TARGET").unwrap(), "{}"); + }} + "#, alternate())) + .file("src/main.rs", &format!(r#" + use std::env; + fn main() {{ + assert_eq!(env::consts::ARCH, "{}"); + }} + "#, alternate_arch())); + + let target = alternate(); + assert_that(p.cargo_process("build").arg("-v"), + execs().with_status(0)); + assert_that(&p.target_bin(&target, "foo"), existing_file()); + + assert_that(process(&p.target_bin(&target, "foo")), + execs().with_status(0)); +}); + test!(simple_deps { if disabled() { return }