Source code

Revision control

Other Tools

1
// This Source Code Form is subject to the terms of the Mozilla Public
2
// License, v. 2.0. If a copy of the MPL was not distributed with this
3
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
5
extern crate num_cpus;
6
extern crate glob;
7
8
use std::env;
9
use std::path;
10
use std::process::{Command, Stdio};
11
12
fn main() {
13
let out_dir = env::var("OUT_DIR").expect("Should have env var OUT_DIR");
14
let target = env::var("TARGET").expect("Should have env var TARGET");
15
16
let js_src = env::var("CARGO_MANIFEST_DIR").expect("Should have env var CARGO_MANIFEST_DIR");
17
18
env::set_var("MAKEFLAGS", format!("-j{}", num_cpus::get()));
19
20
// The Rust package used in Spidermonkey inherits the default profile from the toplevel
21
// Cargo directory. In particular, both profiles (dev or release) set panic=abort,
22
// which defines an exception handling personality that will trigger calls to abort().
23
// The Rust bindings package wants to be able to unwind at runtime, so override the
24
// profile's value here.
25
env::set_var("RUSTFLAGS", "-C panic=unwind");
26
27
env::set_current_dir(&js_src).unwrap();
28
29
let variant = if cfg!(feature = "debugmozjs") {
30
"plaindebug"
31
} else {
32
"plain"
33
};
34
35
let python = env::var("PYTHON").unwrap_or("python2.7".into());
36
let mut cmd = Command::new(&python);
37
cmd.args(&["./devtools/automation/autospider.py",
38
// Only build SpiderMonkey, don't run all the tests.
39
"--build-only",
40
// Disable Mozilla's jemalloc; Rust has its own jemalloc that we
41
// can swap in instead and everything using a single malloc is
42
// good.
43
"--no-jemalloc",
44
// Don't try to clobber the output directory. Without
45
// this option, the build will fail because the directory
46
// already exists but wasn't created by autospider.
47
"--dep",
48
"--objdir", &out_dir,
49
&variant])
50
.env("SOURCE", &js_src)
51
.env("PWD", &js_src)
52
.stdout(Stdio::inherit())
53
.stderr(Stdio::inherit());
54
println!("Running command: {:?}", cmd);
55
let result = cmd
56
.status()
57
.expect("Should spawn autospider OK");
58
assert!(result.success(), "autospider should exit OK");
59
60
println!("cargo:rustc-link-search=native={}/js/src/build", out_dir);
61
println!("cargo:rustc-link-search=native={}/js/src", out_dir);
62
println!("cargo:rustc-link-lib=static=js_static");
63
64
maybe_add_spidermonkey_rust_lib();
65
66
println!("cargo:rustc-link-search=native={}/dist/bin", out_dir);
67
println!("cargo:rustc-link-lib=nspr4");
68
69
if target.contains("windows") {
70
println!("cargo:rustc-link-lib=winmm");
71
if target.contains("gnu") {
72
println!("cargo:rustc-link-lib=stdc++");
73
}
74
} else {
75
println!("cargo:rustc-link-lib=stdc++");
76
}
77
78
println!("cargo:outdir={}", out_dir);
79
}
80
81
/// Find if Spidermonkey built the Spidermonkey Rust library, and add it to the
82
/// link if it was the case.
83
fn maybe_add_spidermonkey_rust_lib() {
84
let out_dir = env::var("OUT_DIR")
85
.expect("cargo should invoke us with the OUT_DIR env var set");
86
87
let mut target_build_dir = path::PathBuf::from(out_dir);
88
target_build_dir.push("../../");
89
90
let mut build_dir = target_build_dir.display().to_string();
91
build_dir.push_str("mozjs_sys-*/out/*/debug");
92
93
let entries = match glob::glob(&build_dir){
94
Err(_) => { return; }
95
Ok(entries) => entries
96
};
97
98
for entry in entries {
99
if let Ok(path) = entry {
100
let path = path.canonicalize()
101
.expect("Should canonicalize debug build path");
102
let path = path.to_str()
103
.expect("Should be utf8");
104
println!("cargo:rustc-link-search=native={}", path);
105
println!("cargo:rustc-link-lib=static=jsrust");
106
return;
107
}
108
}
109
}