Skip to content

Commit 0e67a76

Browse files
committed
Removed Build Dependency on ruzstd and tar on Non-Windows Platforms
Changed mozmake Installation to occur only on Windows Changed MozillaBuild detection and integration to occur only on Windows
1 parent 5caf1fd commit 0e67a76

File tree

2 files changed

+60
-44
lines changed

2 files changed

+60
-44
lines changed

mozjs/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ libz-sys = "1.0"
3636
[build-dependencies]
3737
bindgen = { version = "0.62", default-features = false, features = ["runtime", "which-rustfmt"] }
3838
cc = "1.0"
39-
tar = "0.4.38"
4039
walkdir = "2"
40+
41+
[target.'cfg(windows)'.build-dependencies]
4142
ruzstd = "0.3.0"
43+
tar = "0.4.38"

mozjs/build.rs

Lines changed: 57 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44

55
extern crate bindgen;
66
extern crate cc;
7+
#[cfg(windows)]
78
extern crate ruzstd;
9+
#[cfg(windows)]
810
extern crate tar;
911
extern crate walkdir;
1012

11-
use ruzstd::StreamingDecoder;
1213
use std::env;
1314
use std::ffi::{OsStr, OsString};
1415
use std::fs;
@@ -17,7 +18,6 @@ use std::io::Read;
1718
use std::path::{Path, PathBuf};
1819
use std::process::Command;
1920
use std::str;
20-
use tar::Archive;
2121
use walkdir::WalkDir;
2222

2323
const ENV_VARS: &'static [&'static str] = &[
@@ -100,6 +100,7 @@ fn find_make() -> OsString {
100100
}
101101
}
102102

103+
#[cfg(windows)]
103104
fn install_mozmake(mozbuild_dir: &Path) {
104105
let mozbuild_dir = Path::new(mozbuild_dir);
105106
let mozmake_tar_zst_path = mozbuild_dir.join("mozmake.tar.zst");
@@ -115,13 +116,13 @@ fn install_mozmake(mozbuild_dir: &Path) {
115116
let mozmake_tar_zst =
116117
File::open(&mozmake_tar_zst_path).expect("Failed to open mozmake.tar.zst");
117118
let mut mozmake_compressed =
118-
StreamingDecoder::new(mozmake_tar_zst).expect("Failed to decode mozmake.tar.zst");
119+
ruzstd::StreamingDecoder::new(mozmake_tar_zst).expect("Failed to decode mozmake.tar.zst");
119120
let mut mozmake_uncompressed = Vec::new();
120121

121122
mozmake_compressed
122123
.read_to_end(&mut mozmake_uncompressed)
123124
.expect("Failed to decode mozmake.tar.zst");
124-
let mut archive = Archive::new(&*mozmake_uncompressed);
125+
let mut archive = tar::Archive::new(&*mozmake_uncompressed);
125126
archive
126127
.unpack(mozbuild_dir.join("bin"))
127128
.expect("Failed to unpack mozmake.tar");
@@ -193,22 +194,25 @@ fn build_jsapi(build_dir: &Path) {
193194
PathBuf::from(&mozbuild_env)
194195
}
195196
});
197+
198+
#[cfg(windows)]
199+
{
200+
if let Some(mozbuild_dir) = &mozbuild {
201+
// Add mozmake to PATH
202+
let path = env::var_os("PATH").unwrap();
203+
let mut paths = Vec::new();
204+
paths.push(mozbuild_dir.join("bin").join("mozmake").into());
205+
paths.extend(env::split_paths(&path));
206+
let new_path = env::join_paths(paths).unwrap();
207+
env::set_var("PATH", &new_path);
208+
209+
// Install mozmake if not installed
210+
if !mozbuild_dir.join("MOZMAKE_LOCK").exists() {
211+
install_mozmake(&mozbuild_dir);
212+
}
196213

197-
if let Some(mozbuild_dir) = &mozbuild {
198-
// Add mozmake to PATH
199-
let path = env::var_os("PATH").unwrap();
200-
let mut paths = Vec::new();
201-
paths.push(mozbuild_dir.join("bin").join("mozmake").into());
202-
paths.extend(env::split_paths(&path));
203-
let new_path = env::join_paths(paths).unwrap();
204-
env::set_var("PATH", &new_path);
205-
206-
// Install mozmake if not installed
207-
if !mozbuild_dir.join("MOZMAKE_LOCK").exists() {
208-
install_mozmake(&mozbuild_dir);
214+
make = OsString::from("mozmake");
209215
}
210-
211-
make = OsString::from("mozmake");
212216
}
213217

214218
let mut cmd = Command::new(make);
@@ -238,36 +242,46 @@ fn build_jsapi(build_dir: &Path) {
238242
.env("SRC_DIR", &cargo_manifest_dir.join("mozjs"))
239243
.env("NO_RUST_PANIC_HOOK", "1");
240244

241-
if let Some(mozbuild_dir) = mozbuild {
242-
// Create script that runs mozmake
243-
let script_path = build_dir.join("mozbuild.sh");
244-
let script = cmd_to_string(&cmd);
245-
fs::write(&script_path, script).expect("Failed to write to mozbuild.sh");
246-
247-
let start_shell = mozbuild_dir.join("start-shell.bat");
248-
let mut shell = Command::new(start_shell.as_os_str());
249-
shell
250-
.arg("-here")
251-
.arg("-use-full-path")
252-
.arg(script_path.display().to_string());
253-
254-
for (key, value) in cmd.get_envs() {
255-
if let Some(value) = value {
256-
shell.env(key, value);
245+
#[cfg(not(windows))]
246+
{
247+
let result = cmd.status().expect("Failed to run `make`");
248+
assert!(result.success());
249+
}
250+
251+
#[cfg(windows)]
252+
{
253+
if let Some(mozbuild_dir) = mozbuild {
254+
// Create script that runs mozmake
255+
let script_path = build_dir.join("mozbuild.sh");
256+
let script = cmd_to_string(&cmd);
257+
fs::write(&script_path, script).expect("Failed to write to mozbuild.sh");
258+
259+
let start_shell = mozbuild_dir.join("start-shell.bat");
260+
let mut shell = Command::new(start_shell.as_os_str());
261+
shell
262+
.arg("-here")
263+
.arg("-use-full-path")
264+
.arg(script_path.display().to_string());
265+
266+
for (key, value) in cmd.get_envs() {
267+
if let Some(value) = value {
268+
shell.env(key, value);
269+
}
257270
}
258-
}
259271

260-
if let Some(current_dir) = cmd.get_current_dir() {
261-
shell.current_dir(current_dir);
262-
}
272+
if let Some(current_dir) = cmd.get_current_dir() {
273+
shell.current_dir(current_dir);
274+
}
263275

264-
let result = shell.status().expect("Failed to run `make`");
265-
assert!(result.success());
266-
} else {
267-
let result = cmd.status().expect("Failed to run `make`");
268-
assert!(result.success());
276+
let result = shell.status().expect("Failed to run `make`");
277+
assert!(result.success());
278+
} else {
279+
let result = cmd.status().expect("Failed to run `make`");
280+
assert!(result.success());
281+
}
269282
}
270283

284+
271285
println!(
272286
"cargo:rustc-link-search=native={}/js/src/build",
273287
build_dir.display()

0 commit comments

Comments
 (0)