Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use moztools instead of mozilla-build #368

Merged
merged 3 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,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"
MOZTOOLS_PATH: "${{ github.workspace }}\\target\\dependencies\\moztools-3.2"
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
Expand All @@ -86,8 +85,8 @@ jobs:
components: rust-src
- name: Install deps
run: |
Start-BitsTransfer -Source https://ftp.mozilla.org/pub/mozilla/libraries/win32/MozillaBuildSetup-3.4.exe -Destination ./MozillaBuildSetup.exe
.\MozillaBuildSetup.exe /S | Out-Null
curl -SL "https://github.com/servo/servo-build-deps/releases/download/msvc-deps/moztools-3.2.zip" --create-dirs -o target/dependencies/moztools.zip
cd target/dependencies && unzip -qo moztools.zip -d .
- name: Run sccache-cache
uses: mozilla-actions/[email protected]
with:
Expand Down
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ 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 [MozillaBuild 3.4](https://ftp.mozilla.org/pub/mozilla/libraries/win32/MozillaBuildSetup-3.4.exe)
or download and unzip [MozTools 3.2](https://github.com/servo/servo-build-deps/releases/download/msvc-deps/moztools-3.2.zip)

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

Expand All @@ -46,10 +46,21 @@ 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
```

If you installed MozillaBuild in 1.:

```shell
set MOZILLA_BUILD=C:\mozilla-build
```

or if you unzipped MozTools in 1.:

```shell
set MOZTOOLS_PATH=C:\path\to\moztools-3.2
```

## Run Cargo

You can now build and test the crate using cargo:
Expand Down
56 changes: 47 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",
"MOZJS_FORCE_RERUN",
"MOZTOOLS_PATH",
"MOZJS_FORCE_RERUN",
"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 MOZTOOLS_VERSION: &str = "3.2";

fn main() {
// https://github.com/servo/mozjs/issues/113
env::set_var("MOZCONFIG", "");
Expand Down Expand Up @@ -131,24 +133,60 @@ 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("moztools").join(MOZTOOLS_VERSION);

if moztools_path.exists() {
Some(moztools_path)
} 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("MOZTOOLS_PATH") {
PathBuf::from(moztools)
} else if let Some(moztools) = find_moztools() {
// moztools already in target/dependencies/moztools-*
moztools
} else if let Some(moz_build) = env::var_os("MOZILLA_BUILD") {
// For now we also support mozilla build
PathBuf::from(moz_build)
} else {
panic!(
"MozTools or MozillaBuild not found!\n \
Follow instructions on: https://github.com/servo/mozjs?tab=readme-ov-file#windows"
);
};
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
4 changes: 1 addition & 3 deletions mozjs/src/jsimpls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,9 +531,7 @@ impl JS::ObjectOpResult {

impl Default for ObjectOpResult {
fn default() -> ObjectOpResult {
ObjectOpResult {
code_: ObjectOpResult_SpecialCodes::Uninitialized as usize,
}
ObjectOpResult { code_: ObjectOpResult_SpecialCodes::Uninitialized as usize }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Were these changes added by mistake?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I run cargo fmt and I guess this was not formatted properly before.

}
}

Expand Down