Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set target using config file #2335

Merged
merged 1 commit into from
Feb 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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