Skip to content

Commit 8dcf64e

Browse files
authored
Use moztools instead of mozilla-build (#368)
* Use moztools instead of mozilla-build * Document moztools
1 parent 21dad0b commit 8dcf64e

File tree

4 files changed

+65
-19
lines changed

4 files changed

+65
-19
lines changed

.github/workflows/rust.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,10 @@ jobs:
7070
#target: [""]
7171
target: ["", "aarch64-uwp-windows-msvc", "x86_64-uwp-windows-msvc"]
7272
env:
73-
MOZILLA_BUILD: 'C:\mozilla-build'
7473
LINKER: "lld-link.exe"
7574
CC: "clang-cl"
7675
CXX: "clang-cl"
77-
PYTHON3: "C:\\mozilla-build\\python3\\python3.exe"
76+
MOZTOOLS_PATH: "${{ github.workspace }}\\target\\dependencies\\moztools-3.2"
7877
steps:
7978
- uses: actions/checkout@v3
8079
- uses: dtolnay/rust-toolchain@stable
@@ -86,8 +85,8 @@ jobs:
8685
components: rust-src
8786
- name: Install deps
8887
run: |
89-
Start-BitsTransfer -Source https://ftp.mozilla.org/pub/mozilla/libraries/win32/MozillaBuildSetup-3.4.exe -Destination ./MozillaBuildSetup.exe
90-
.\MozillaBuildSetup.exe /S | Out-Null
88+
curl -SL "https://github.com/servo/servo-build-deps/releases/download/msvc-deps/moztools-3.2.zip" --create-dirs -o target/dependencies/moztools.zip
89+
cd target/dependencies && unzip -qo moztools.zip -d .
9190
- name: Run sccache-cache
9291
uses: mozilla-actions/sccache-action@v0.0.3
9392
with:

README.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ export LIBCLANG_PATH=/usr/lib/clang/4.0/lib
2929

3030
## Windows
3131

32-
1. Install [MozillaBuild 3.4][mozbuild].
33-
[mozbuild]: <https://ftp.mozilla.org/pub/mozilla/libraries/win32/MozillaBuildSetup-3.4.exe>
32+
1. Install [MozillaBuild 3.4](https://ftp.mozilla.org/pub/mozilla/libraries/win32/MozillaBuildSetup-3.4.exe)
33+
or download and unzip [MozTools 3.2](https://github.com/servo/servo-build-deps/releases/download/msvc-deps/moztools-3.2.zip)
3434

3535
2. Download and install Clang for Windows (64 bit) from <https://releases.llvm.org/download.html>.
3636

@@ -46,10 +46,21 @@ export LIBCLANG_PATH=/usr/lib/clang/4.0/lib
4646
the dependencies above:
4747

4848
```shell
49-
set MOZILLA_BUILD=C:\mozilla-build
5049
set LIBCLANG_PATH=C:\Program Files\LLVM\lib
5150
```
5251

52+
If you installed MozillaBuild in 1.:
53+
54+
```shell
55+
set MOZILLA_BUILD=C:\mozilla-build
56+
```
57+
58+
or if you unzipped MozTools in 1.:
59+
60+
```shell
61+
set MOZTOOLS_PATH=C:\path\to\moztools-3.2
62+
```
63+
5364
## Run Cargo
5465

5566
You can now build and test the crate using cargo:

mozjs/build.rs

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ const ENV_VARS: &'static [&'static str] = &[
2525
"CXX",
2626
"CXXFLAGS",
2727
"MAKE",
28-
"MOZ_TOOLS",
29-
"MOZJS_FORCE_RERUN",
3028
"MOZTOOLS_PATH",
29+
"MOZJS_FORCE_RERUN",
3130
"PYTHON",
3231
"STLPORT_LIBS",
3332
];
@@ -39,6 +38,9 @@ const EXTRA_FILES: &'static [&'static str] = &[
3938
"src/jsglue.cpp",
4039
];
4140

41+
/// Which version of moztools we expect
42+
const MOZTOOLS_VERSION: &str = "3.2";
43+
4244
fn main() {
4345
// https://github.com/servo/mozjs/issues/113
4446
env::set_var("MOZCONFIG", "");
@@ -131,24 +133,60 @@ fn cc_flags() -> Vec<&'static str> {
131133
result
132134
}
133135

136+
fn cargo_target_dir() -> PathBuf {
137+
let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());
138+
let mut dir = out_dir.as_path();
139+
while let Some(target_dir) = dir.parent() {
140+
if target_dir.file_name().unwrap().to_string_lossy() == "target" {
141+
return target_dir.to_path_buf();
142+
}
143+
dir = target_dir;
144+
}
145+
panic!("$OUT_DIR is not in target")
146+
}
147+
148+
fn find_moztools() -> Option<PathBuf> {
149+
let cargo_target_dir = cargo_target_dir();
150+
let deps_dir = cargo_target_dir.join("dependencies");
151+
let moztools_path = deps_dir.join("moztools").join(MOZTOOLS_VERSION);
152+
153+
if moztools_path.exists() {
154+
Some(moztools_path)
155+
} else {
156+
None
157+
}
158+
}
159+
134160
fn build_jsapi(build_dir: &Path) {
135161
let target = env::var("TARGET").unwrap();
136162
let mut make = find_make();
137163

138-
// If MOZILLA_BUILD is specified, process that environment variable to put
139-
// the build tools on the path and properly set the AUTOCONF environment
140-
// variable.
141-
if let Some(mozilla_build_path) = env::var_os("MOZILLA_BUILD") {
164+
#[cfg(windows)]
165+
{
166+
let moztools = if let Some(moztools) = env::var_os("MOZTOOLS_PATH") {
167+
PathBuf::from(moztools)
168+
} else if let Some(moztools) = find_moztools() {
169+
// moztools already in target/dependencies/moztools-*
170+
moztools
171+
} else if let Some(moz_build) = env::var_os("MOZILLA_BUILD") {
172+
// For now we also support mozilla build
173+
PathBuf::from(moz_build)
174+
} else {
175+
panic!(
176+
"MozTools or MozillaBuild not found!\n \
177+
Follow instructions on: https://github.com/servo/mozjs?tab=readme-ov-file#windows"
178+
);
179+
};
142180
let mut paths = Vec::new();
143-
paths.push(Path::new(&mozilla_build_path).join("msys").join("bin"));
144-
paths.push(Path::new(&mozilla_build_path).join("bin"));
181+
paths.push(moztools.join("msys").join("bin"));
182+
paths.push(moztools.join("bin"));
145183
paths.extend(env::split_paths(&env::var_os("PATH").unwrap()));
146184
env::set_var("PATH", &env::join_paths(paths).unwrap());
147185

148186
if env::var_os("AUTOCONF").is_none() {
149187
env::set_var(
150188
"AUTOCONF",
151-
Path::new(&mozilla_build_path)
189+
moztools
152190
.join("msys")
153191
.join("local")
154192
.join("bin")

mozjs/src/jsimpls.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -531,9 +531,7 @@ impl JS::ObjectOpResult {
531531

532532
impl Default for ObjectOpResult {
533533
fn default() -> ObjectOpResult {
534-
ObjectOpResult {
535-
code_: ObjectOpResult_SpecialCodes::Uninitialized as usize,
536-
}
534+
ObjectOpResult { code_: ObjectOpResult_SpecialCodes::Uninitialized as usize }
537535
}
538536
}
539537

0 commit comments

Comments
 (0)