Skip to content

Commit

Permalink
Use moztools instead of mozilla-build
Browse files Browse the repository at this point in the history
  • Loading branch information
sagudev committed Aug 17, 2023
1 parent 7316bb0 commit f46fc0c
Showing 1 changed file with 63 additions and 9 deletions.
72 changes: 63 additions & 9 deletions mozjs/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ const ENV_VARS: &'static [&'static str] = &[
"CXX",
"CXXFLAGS",
"MAKE",
"MOZ_TOOLS",
"MOZ_TOOLS_PATH",
"MOZJS_FORCE_RERUN",
"MOZTOOLS_PATH",
"PYTHON",
"STLPORT_LIBS",
];
Expand All @@ -39,6 +38,9 @@ const EXTRA_FILES: &'static [&'static str] = &[
"src/jsglue.cpp",
];

/// Which version of moztools we expect
const MOZ_TOOLS: &str = "moztools-3.2";

fn main() {
// https://github.com/servo/mozjs/issues/113
env::set_var("MOZCONFIG", "");
Expand Down Expand Up @@ -131,24 +133,76 @@ fn cc_flags() -> Vec<&'static str> {
result
}

fn cargo_target_dir() -> PathBuf {
let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());
let mut dir = out_dir.as_path();
while let Some(target_dir) = dir.parent() {
if target_dir.file_name().unwrap().to_string_lossy() == "target" {
return target_dir.to_path_buf();
}
dir = target_dir;
}
panic!("$OUT_DIR is not in target")
}

fn find_moztools() -> Option<PathBuf> {
let cargo_target_dir = cargo_target_dir();
let deps_dir = cargo_target_dir.join("dependencies");
let moztools_path = deps_dir.join(MOZ_TOOLS);

if moztools_path.exists() {
Some(moztools_path)
} else {
None
}

// to support many moztools versions
/*
if let Ok(dirs) = std::fs::read_dir(deps_dir) {
dirs.into_iter().find_map(|p| {
if let Ok(pp) = p {
if let Some(name) = pp.path().file_name() {
if name.to_string_lossy().contains("moztools") {
Some(pp.path())
} else {
None
}
} else {
None
}
} else {
None
}
})
} else {
None
}*/
}

fn build_jsapi(build_dir: &Path) {
let target = env::var("TARGET").unwrap();
let mut make = find_make();

// If MOZILLA_BUILD is specified, process that environment variable to put
// the build tools on the path and properly set the AUTOCONF environment
// variable.
if let Some(mozilla_build_path) = env::var_os("MOZILLA_BUILD") {
#[cfg(windows)]
{
let moztools = if let Some(moztools) = env::var_os("MOZ_TOOLS_PATH") {
PathBuf::from(moztools)
} else if let Some(moztools) = find_moztools() {
// moztools already in targed/dependencies/moztools-*
moztools
} else {
find_moztools().unwrap()
};
let mut paths = Vec::new();
paths.push(Path::new(&mozilla_build_path).join("msys").join("bin"));
paths.push(Path::new(&mozilla_build_path).join("bin"));
paths.push(moztools.join("msys").join("bin"));
paths.push(moztools.join("bin"));
paths.extend(env::split_paths(&env::var_os("PATH").unwrap()));
env::set_var("PATH", &env::join_paths(paths).unwrap());

if env::var_os("AUTOCONF").is_none() {
env::set_var(
"AUTOCONF",
Path::new(&mozilla_build_path)
moztools
.join("msys")
.join("local")
.join("bin")
Expand Down

0 comments on commit f46fc0c

Please sign in to comment.