Skip to content

Commit

Permalink
Set target using config file
Browse files Browse the repository at this point in the history
  • Loading branch information
fpgaminer committed Jan 30, 2016
1 parent 4b447ed commit 7442050
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/cargo/ops/cargo_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(),
Expand Down
1 change: 1 addition & 0 deletions src/doc/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down
36 changes: 36 additions & 0 deletions tests/test_cargo_cross_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down

0 comments on commit 7442050

Please sign in to comment.