Skip to content

Commit

Permalink
Follow through on the OUT_DIR promise for rustc compiles
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcrichton committed Nov 5, 2014
1 parent 2833358 commit 85a96e4
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/cargo/ops/cargo_rustc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,15 @@ fn build_deps_args(mut cmd: ProcessBuilder, target: &Target, package: &Package,
cmd = cmd.arg("-L").arg(layout.root());
cmd = cmd.arg("-L").arg(layout.deps());

let has_build_cmd = package.get_targets().iter().any(|t| {
t.get_profile().is_custom_build()
});
cmd = cmd.env("OUT_DIR", if has_build_cmd {
Some(layout.build_out(package))
} else {
None
});

// Traverse the entire dependency graph looking for -L paths to pass for
// native dependencies.
// OLD-BUILD: to-remove
Expand Down
39 changes: 39 additions & 0 deletions tests/test_cargo_compile_custom_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -753,3 +753,42 @@ test!(output_separate_lines {
{running} `rustc [..] --crate-name foo [..] -L foo -l foo:static`
", compiling = COMPILING, running = RUNNING).as_slice()));
})

test!(code_generation {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
name = "foo"
version = "0.5.0"
authors = []
build = "build.rs"
"#)
.file("src/main.rs", r#"
include!(concat!(env!("OUT_DIR"), "/hello.rs"))
fn main() {
println!("{}", message());
}
"#)
.file("build.rs", r#"
use std::os;
use std::io::File;
fn main() {
let dst = Path::new(os::getenv("OUT_DIR").unwrap());
let mut f = File::create(&dst.join("hello.rs")).unwrap();
f.write_str("
pub fn message() -> &'static str {
\"Hello, World!\"
}
").unwrap();
}
"#);
assert_that(p.cargo_process("run"),
execs().with_status(0)
.with_stdout(format!("\
{compiling} foo v0.5.0 (file://[..])
{running} `target[..]foo`
Hello, World!
", compiling = COMPILING, running = RUNNING).as_slice()));
})

0 comments on commit 85a96e4

Please sign in to comment.