Add a NUM_JOBS env var to builds

Closes #539
This commit is contained in:
Alex Crichton 2014-09-09 15:01:31 -07:00
parent 5c55068218
commit 2d5d7b4e47
3 changed files with 5 additions and 0 deletions

View file

@ -151,6 +151,8 @@ impl<'a, 'b> Context<'a, 'b> {
self.build_requirements(pkg, target, Target, &mut HashSet::new());
}
self.compilation.extra_env.insert("NUM_JOBS".to_string(),
Some(self.config.jobs().to_string()));
self.compilation.root_output = self.layout(KindTarget).proxy().dest().clone();
self.compilation.deps_output = self.layout(KindTarget).proxy().deps().clone();

View file

@ -71,6 +71,8 @@ commands.
* `OUT_DIR` - the folder in which all output should be placed.
* `TARGET` - the target triple that is being compiled for. Native code should be
compiled for this triple.
* `NUM_JOBS` - the parallelism specified as the top-level parallelism. This can
be useful to pass a `-j` parameter to a system like `make`.
* `DEP_<name>_OUT_DIR` - This variable is present for all immediate dependencies
of the package being built. The `<name>` will be the
package's name, in uppercase, with `-` characters

View file

@ -791,6 +791,7 @@ test!(custom_build_env_vars {
.file("src/foo.rs", format!(r#"
use std::os;
fn main() {{
let _ncpus = os::getenv("NUM_JOBS").unwrap();
let out = os::getenv("OUT_DIR").unwrap();
assert!(out.as_slice().starts_with(r"{0}"));
assert!(Path::new(out).is_dir());