Skip to content

Commit

Permalink
dl moztool if not found
Browse files Browse the repository at this point in the history
  • Loading branch information
sagudev committed Aug 17, 2023
1 parent f46fc0c commit cece0e2
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 11 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,10 @@ jobs:
#target: [""]
target: ["", "aarch64-uwp-windows-msvc", "x86_64-uwp-windows-msvc"]
env:
MOZILLA_BUILD: 'C:\mozilla-build'
LINKER: "lld-link.exe"
CC: "clang-cl"
CXX: "clang-cl"
PYTHON3: "C:\\mozilla-build\\python3\\python3.exe"
PYTHON3: "python3"
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
Expand All @@ -87,10 +86,8 @@ jobs:
with:
toolchain: "nightly-2023-02-02"
components: rust-src
- name: Install deps
- name: Add LLVM to PATH
run: |
Start-BitsTransfer -Source https://ftp.mozilla.org/pub/mozilla/libraries/win32/MozillaBuildSetup-3.4.exe -Destination ./MozillaBuildSetup.exe
.\MozillaBuildSetup.exe /S | Out-Null
echo 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Tools\LLVM\bin' | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
- name: Run sccache-cache
uses: mozilla-actions/[email protected]
Expand Down
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ export LIBCLANG_PATH=/usr/lib/clang/4.0/lib

## Windows

1. Install [MozillaBuild 3.4][mozbuild].
[mozbuild]: https://ftp.mozilla.org/pub/mozilla/libraries/win32/MozillaBuildSetup-3.4.exe
1. Install Python 3

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

Expand All @@ -46,7 +45,6 @@ export LIBCLANG_PATH=/usr/lib/clang/4.0/lib
the dependencies above:

```shell
set MOZILLA_BUILD=C:\mozilla-build
set LIBCLANG_PATH=C:\Program Files\LLVM\lib
```

Expand Down Expand Up @@ -76,7 +74,7 @@ mozjs_sys = { path = "../mozjs/mozjs" }
In order to upgrade to a new version of SpiderMonkey:
1. Find the mozilla-release commit for the desired version of SpiderMonkey, at
https://treeherder.mozilla.org/#/jobs?repo=mozilla-release&filter-searchStr=spidermonkey%20pkg.
<https://treeherder.mozilla.org/#/jobs?repo=mozilla-release&filter-searchStr=spidermonkey%20pkg>.
You are looking for an SM(pkg) tagged with FIREFOX_RELEASE.
Take a note of the commit number to the left (a hex number such as ac4fbb7aaca0).
Expand All @@ -98,7 +96,7 @@ In order to upgrade to a new version of SpiderMonkey:
To get a dev environment with shell.nix:
```sh
$ nix-shell
nix-shell
```
To configure rust-analyzer in Visual Studio Code:
Expand Down
8 changes: 7 additions & 1 deletion mozjs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ libc = "0.2"
libz-sys = "1.0"

[build-dependencies]
bindgen = { version = "0.62", default-features = false, features = ["runtime", "which-rustfmt"] }
bindgen = { version = "0.62", default-features = false, features = [
"runtime",
"which-rustfmt",
] }
cc = "1.0"
walkdir = "2"

[target.'cfg(windows)'.build-dependencies]
zip = { version = "0.6", default-features = false, features = ["deflate"] }
32 changes: 32 additions & 0 deletions mozjs/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
extern crate bindgen;
extern crate cc;
extern crate walkdir;
#[cfg(windows)]
extern crate zip;

use std::env;
use std::ffi::{OsStr, OsString};
Expand Down Expand Up @@ -38,6 +40,9 @@ const EXTRA_FILES: &'static [&'static str] = &[
"src/jsglue.cpp",
];

const MOZ_TOOLS_DL: &str =
"https://github.com/servo/servo-build-deps/releases/download/msvc-deps/moztools-3.2.zip";

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

Expand Down Expand Up @@ -191,6 +196,33 @@ fn build_jsapi(build_dir: &Path) {
// moztools already in targed/dependencies/moztools-*
moztools
} else {
// download moztools
let cargo_target_dir = cargo_target_dir();
let deps_dir = cargo_target_dir.join("dependencies");

// curl is on Win10+
let mut curl = Command::new("curl");

let moztools_zip = &deps_dir.join("moztools.zip");
let result = curl
.arg("-SL")
.arg(MOZ_TOOLS_DL)
.arg("--create-dirs")
.arg("-o")
.arg(moztools_zip.as_os_str())
.status()
.expect("Failed to download moztools.");
assert!(result.success());

// extract
let file = fs::File::open(moztools_zip).expect("Failed to read moztools.zip");
let mut archive = zip::ZipArchive::new(file).expect("Failed to read moztools archive");
archive
.extract(deps_dir)
.expect("Failed to unpack moztools");

fs::remove_file(&moztools_zip).expect("Failed to remove moztools.zip");

find_moztools().unwrap()
};
let mut paths = Vec::new();
Expand Down

0 comments on commit cece0e2

Please sign in to comment.