Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Spidermonkey

Benjamin Bouvier edited this page Mar 30, 2020 · 3 revisions

Cranelift is being used in Spidermonkey (see also this document). Here is a collection of tricks related to this use case.

Bumping the version of Cranelift in Spidermonkey

  • Open the top-level Cargo.toml file in your local Gecko clone, and locate the two patch sections related to cranelift-codegen and cranelift-wasm.
  • Update the commit hashes (rev = ...) to the desired Cranelift git hash.
  • Check that the Cranelift version specified in its Cargo.toml file matches the version numbers in the Gecko's js/src/wasm/cranelift/Cargo.toml file. Otherwise, the Cargo patches won't apply properly.
  • Run ./mach vendor rust. This will create changes to the global Cargo.lock file, which should be committed separately (later).
  • Compile Spidermonkey as usual, update to latest Cranelift API changes, if any.
  • Once you're done, create two Gecko commits (using for instance the hg record extension):
    • once for the Cargo.toml changes as well as API changes.
    • once for the result of the mach vendor rust command.
  • Ideally, run the test suite with Cranelift, and at least note failures in the associated bug, so we keep track of known failures over time.
  • And then upload them for review to a wasm peer. The second commit exists to separate meaningful changes from changes already reviewed on Cranelift's github repository. So this latter commit may only be rubberstamp by its reviewer.

Using a different repository or branch

Almost the same steps as above: instead of replacing the rev field by another hash commit in Gecko's top-level Cargo.toml file, you need to:

  • replace the repository username, if needed.
  • then point to a specific commit with rev = COMMIT_HASH, or a specific branch with branch = BRANCH_NAME.
  • and then, re-run mach vendor rust as usual.

Using a local Cranelift fork in Spidermonkey

⚠️ Do not put your external Cranelift tree anywhere inside your Gecko tree. For example, it might seem convenient or at least tidy, to park it at the top of your mozilla-central tree. Unfortunately that causes ‘./mach vendor rust’ to fail mysteriously, with an error message complaining that “package ‘/path/to/your/external/cranelift-codegen/Cargo.toml’ is a member of the wrong workspace”.

  • Edit $MOZROOT/js/src/wasm/cranelift/Cargo.toml
  • Replace both lines cranelift-codegen / cranelift-wasm by the following form:
cranelift-codegen = { path = “/abs/path/to/your/local/wasmtime/cranelift/cranelift-codegen” }
  • Remove the two patch sections in Gecko's top-level Cargo.toml file, sections resembling this:
[patch.crates-io.cranelift-codegen]
git = "https://github.com/bytecodealliance/wasmtime"
rev = "538a0662bf90a1daa9921c10f34827ace134abf1"
  • cd MOZROOT && ./mach vendor rust to synchronize the global Cargo.lock file.
  • then compile as usual.

Running Spidermonkey wasm test suite using Cranelift

$MOZROOT/js/src/jit-test/jit_test.py --args=”--wasm-compiler=cranelift --no-wasm-multi-value --shared-memory=off” /path/to/built/shell/js wasm