• Stars
    star
    156
  • Rank 239,589 (Top 5 %)
  • Language
    Rust
  • Created over 12 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Servo's SpiderMonkey fork

This repository contains Rust bindings for SpiderMonkey for use with Servo.

The bindings are to the raw SpiderMonkey API, higher-level bindings are in the rust-mozjs directory.

Building

Under Linux:

Install Clang (at least version 3.9) and autoconf v 2.13, for example in a Debian-based Linux:

sudo apt-get install clang-6.0 autoconf2.13

If you have more than one version of Clang installed, you can set the LIBCLANG_PATH environment variable, for example:

export LIBCLANG_PATH=/usr/lib/clang/4.0/lib

Under Windows:

  1. Follow the directions at https://developer.mozilla.org/en-US/docs/Mozilla/Developer_guide/Build_Instructions/Windows_Prerequisites

  2. Open up a shell configured to use Visual Studio. This could be the one included with Visual Studio (e.g. Visual Studio 2017 / X64 Native Tools Command Prompt for VS 2017) or a shell in which you have run

"c:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build\vcvars64.bat"
  1. Set the MOZTOOLS_PATH environment variable to point to the tools from the Mozilla Build Package:
set MOZTOOLS_PATH=C:\mozilla-build\msys\bin;C:\mozilla-build\bin
  1. Download and install Clang for Windows (64 bit) from https://releases.llvm.org/download.html and set the LIBCLANG_PATH environment variable to its lib directory:
set LIBCLANG_PATH=C:\Program Files\LLVM\lib
  1. Set environment variables so the build script can find Python 2.7 and Autoconf 2.13:
set AUTOCONF=C:\mozilla-build\msys\local\bin\autoconf-2.13
set NATIVE_WIN32_PYTHON=C:\mozilla-build\python\python2.7.exe

You can now build and test the crate using cargo:

cargo build
cargo test
cargo build --features debugmozjs
cargo test --features debugmozjs

Building servo against your local mozjs

Assuming your local servo and mozjs directories are siblings, you can build servo against mozjs by adding the following to servo/Cargo.toml:

[patch."https://github.com/servo/mozjs"]
mozjs = { path = "../mozjs/rust-mozjs" }
mozjs_sys = { path = "../mozjs/mozjs" }

Upgrading

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. 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).

  2. Click on the SM(pkg) link, which will open a panel with details of the commit, including an artefact uploaded link, with a name of the form mozjs-version.tar.bz2. Download it and save it locally.

  3. Look at the patches in etc/patches/*.patch, and remove any that no longer apply (with a bit of luck this will be all of them).

  4. Run python3 ./etc/update.py path/to/tarball.

  5. Update etc/COMMIT with the commit number.

  6. Build and test the bindings as above, then submit a PR!

NixOS users

To get a dev environment with shell.nix:

$ nix-shell

To configure rust-analyzer in Visual Studio Code:

{
    "rust-analyzer.check.overrideCommand": ["nix-shell", "--run", "cargo check --message-format=json"],
    "rust-analyzer.cargo.buildScripts.overrideCommand": ["nix-shell", "--run", "cargo check --message-format=json"],
    "rust-analyzer.rustfmt.overrideCommand": ["nix-shell", "--run", "cargo fmt"],
}

Editor support

If you are working on the Rust code only, rust-analyzer should work perfectly out of the box, though NixOS users will need to configure rust-analyzer to wrap cargo invocations (see above).

But if you are working on the C++ code, editor support is only really possible in upstream SpiderMonkey (aka β€œmozilla-central”), but once you’ve set up your editor in your upstream checkout, you can work on your changes there, then import them here as needed for local testing.

This guide assumes that your code is checked out at:

  • ~/code/mozjs for this repo
  • ~/code/mozilla-unified for upstream SpiderMonkey
  • (NixOS users only) ~/code/nixpkgs-mozilla for mozilla/nixpkgs-mozilla

NixOS users: some steps have a note in [brackets] saying they need to be wrapped in nix-shell. Those commands should be wrapped as follows:

nix-shell ~/code/nixpkgs-mozilla/release.nix -A gecko.x86_64-linux.clang --run '...'

C++ editor setup

Start by checking out mozilla-unified (Building Firefox on Linux §§ 1 and 2).

NixOS users: it’s ok if the bootstrap command fails with a NotImplementedError due to NixOS not being a supported distro.

Now create your MOZCONFIG file (Building and testing SpiderMonkey). I recommend (and this guide assumes) that the file is named debug.mozconfig, because simple names like debug can cause MozconfigFindException problems. The file should look like this:

# Build only the JS shell
ac_add_options --enable-project=js

# Enable the debugging tools: Assertions, debug only code etc.
ac_add_options --enable-debug

# Enable optimizations as well so that the test suite runs much faster. If
# you are having trouble using a debugger, you should disable optimization.
ac_add_options --enable-optimize

# Use a dedicated objdir for SpiderMonkey debug builds to avoid
# conflicting with Firefox build with default configuration.
mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/obj-debug-@CONFIG_GUESS@

If you are a NixOS user, clone mozilla/nixpkgs-mozilla next to your mozilla-unified checkout, and add the following line to the start of your debug.mozconfig:

. ./.mozconfig.nix-shell

You will need to generate your Visual Studio Code config and compilation database against central at least once, before you can do so against the commit we forked from (mozjs/etc/COMMIT).

~/code/mozilla-unified $ MOZCONFIG=debug.mozconfig ./mach ide vscode

[NixOS users: wrap the command above in nix-shell]

Otherwise you might get an error with lots of exclamation marks:

~/code/mozilla-unified $ MOZCONFIG=debug.mozconfig ./mach ide vscode
[snip]
 0:05.80 Unable to locate clangd in /home/delan/code/mozilla-unified/.mozbuild/clang-tools/clang-tidy/bin.
[snip]
 0:07.78 ERROR!!!!!! Could not find artifacts for a toolchain build named `linux64-clang-tidy`. Local commits, dirty/stale files, and other changes in your checkout may cause this error. Make sure you are on a fresh, current checkout of mozilla-central. Beware that commands like `mach bootstrap` and `mach artifact` are unlikely to work on any versions of the code besides recent revisions of mozilla-central.

[NixOS users: wrap the command above in nix-shell]

Now switch to the commit we forked from, and generate them again.

~/code/mozilla-unified $ hg update -r $(cat ../mozjs/mozjs/etc/COMMIT)
~/code/mozilla-unified $ MOZCONFIG=debug.mozconfig ./mach ide vscode

[NixOS users: wrap the mach command above in nix-shell]

At this point, you should be able to open Visual Studio Code, install the clangd extension, and open a file like js/src/vm/ArrayBufferObject.cpp without seeing any problems in the margin.

If there are no problems in the margin, and you can Go To Definition, you’re done!

Troubleshooting

If you are a NixOS user and see this in the clangd output panel:

[Error - 7:38:13 pm] Clang Language Server client: couldn't create connection to server.
Launching server using command /home/delan/code/mozilla-unified/.mozbuild/clang-tools/clang-tidy/bin/clangd failed. Error: spawn /home/delan/code/mozilla-unified/.mozbuild/clang-tools/clang-tidy/bin/clangd ENOENT

Then you need to replace the mozbuild toolchain’s clangd with one that has been patchelf’d:

~/code/mozilla-unified $ ln -sf ~/.nix-profile/bin/clangd .mozbuild/clang-tools/clang-tidy/bin/clangd

If you see this in the clangd output panel:

I[19:20:28.001] Indexed /home/delan/code/mozilla-unified/js/src/jit/LIR.cpp (61040 symbols, 244267 refs, 738 files)
I[19:20:28.001] Failed to compile /home/delan/code/mozilla-unified/js/src/jit/LIR.cpp, index may be incomplete
I[19:20:28.087] --> $/progress

Then the commands in your compilation database might be incorrect. You can try running one of the commands in a terminal to see what happens:

~/code/mozilla-unified $ ( f=$PWD/obj-debug-x86_64-pc-linux-gnu/clangd/compile_commands.json; set -x; cd $(< $f jq -r '.[0].directory'); $(< $f jq -r '.[0].command') )
+/run/current-system/sw/bin/zsh:252> jq -r '.[0].directory'
+/run/current-system/sw/bin/zsh:252> cd /home/delan/code/mozilla-unified/obj-debug-x86_64-pc-linux-gnu/js/src
+/run/current-system/sw/bin/zsh:252> jq -r '.[0].command'
+/run/current-system/sw/bin/zsh:252> /nix/store/dkw46jgi8i0bq64cag95v4ywz6g9bnga-gcc-wrapper-11.3.0/bin/cc '-std=gnu99' -o /dev/null -c -I/home/delan/code/mozilla-unified/obj-debug-x86_64-pc-linux-gnu/dist/system_wrappers -include /home/delan/code/mozilla-unified/config/gcc_hidden.h -U_FORTIFY_SOURCE '-D_FORTIFY_SOURCE=2' -fstack-protector-strong '-DDEBUG=1' -DWASM_SUPPORTS_HUGE_MEMORY -DJS_CACHEIR_SPEW -DJS_STRUCTURED_SPEW -DEXPORT_JS_API -DMOZ_HAS_MOZGLUE -I/home/delan/code/mozilla-unified/js/src -I/home/delan/code/mozilla-unified/obj-debug-x86_64-pc-linux-gnu/js/src -I/home/delan/code/mozilla-unified/obj-debug-x86_64-pc-linux-gnu/dist/include -I/nix/store/bsslcbcnrfcv6nl0jfha444nxjky7zxa-zlib-1.2.13-dev/include -include /home/delan/code/mozilla-unified/obj-debug-x86_64-pc-linux-gnu/js/src/js-confdefs.h -DMOZILLA_CLIENT -fPIC -fno-math-errno -pthread -pipe -gdwarf-4 -freorder-blocks -O3 -fno-omit-frame-pointer -funwind-tables -Wall -Wempty-body -Wignored-qualifiers -Wpointer-arith -Wsign-compare -Wtype-limits -Wunreachable-code -Wduplicated-cond -Wlogical-op '-Wno-error=maybe-uninitialized' '-Wno-error=deprecated-declarations' '-Wno-error=array-bounds' '-Wno-error=free-nonheap-object' -Wno-multistatement-macros '-Wno-error=class-memaccess' -Wformat '-Wformat-overflow=2' '-Werror=implicit-function-declaration' -Wno-psabi -fno-strict-aliasing '-ffp-contract=off' '-ferror-limit=0' /home/delan/code/mozilla-unified/js/src/vtune/ittnotify_static.c -Wno-varargs -Wno-sign-compare -Wno-unknown-pragmas -Wno-stringop-overflow -Wno-stringop-truncation
gcc: error: unrecognized command-line option β€˜-ferror-limit=0’

In this case, it was because your compiler was gcc (which supports -fmax-errors but not -ferror-limit), but it should always be clang (which supports both) when working with clangd. If you are a NixOS user, make sure you use the clang derivation, not the gcc derivation, when generating your compilation database:

~/code/mozilla-unified $ nix-shell ~/code/nixpkgs-mozilla/release.nix -A gecko.x86_64-linux.clang --run 'MOZCONFIG=debug.mozconfig ./mach ide vscode'
                                                                                            ^^^^^

Importing changes for local testing

Start by making a source tarball from your local upstream SpiderMonkey checkout. [TODO(@delan) the default xz compression is very slow here, we should add an option upstream to make it faster]

~/code/mozilla-unified $ AUTOMATION=1 DIST=$PWD/../mozjs/mozjs/etc js/src/make-source-package.py

[NixOS users: wrap the command above in nix-shell]

Now update your vendored copy of SpiderMonkey from that tarball. This creates a commit replacing mozjs/mozjs with the unpatched contents of the tarball, leaving the changes made by reapplying our patches in your working directory diff (git diff).

~/code/mozjs $ python3 mozjs/etc/update.py mozjs/etc/mozjs-107.0.0.tar.xz

Then do a (mixed) reset to remove the commit and unstage its changes.

~/code/mozjs $ git reset @~

Your working directory diff (git diff) should now contain (and only contain) the changes you’ve made to your upstream SpiderMonkey checkout. If you see changes to mozjs/mozjs/js/src/old-configure [TODO(@delan) why does this happen?], you may need to undo them:

~/code/mozjs $ git restore -W mozjs/mozjs/js/src/old-configure

Otherwise you might get the build failure below:

~/code/mozjs $ cargo build
[snip]
  configure: error: can not find sources in /home/delan/code/mozjs/mozjs/mozjs/js/src or ..

  --- stderr
  WARNING: The value of LD is not used by this build system.
  ERROR: old-configure failed
  make: *** [/home/delan/code/mozjs/mozjs/makefile.cargo:195: maybe-configure] Error 1
  thread 'main' panicked at 'assertion failed: result.success()', mozjs/build.rs:178:5
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Now you can build the Rust crates against your modified version of SpiderMonkey!

~/code/mozjs $ cargo build

More Repositories

1

servo

The Servo Browser Engine
23,804
star
2

pathfinder

A fast, practical GPU rasterizer for fonts and vector graphics
Rust
3,587
star
3

webrender

A GPU-based renderer for the web
Rust
3,097
star
4

html5ever

High-performance browser-grade HTML5 parser
Rust
2,089
star
5

rust-smallvec

"Small vector" optimization for Rust: store up to a small number of items on the stack
Rust
1,320
star
6

rust-url

URL parser for Rust
Rust
1,290
star
7

core-foundation-rs

Rust bindings to Core Foundation and other low level libraries on Mac OS X and iOS
Rust
992
star
8

ipc-channel

A multiprocess drop-in replacement for Rust channels
Rust
838
star
9

rust-cssparser

Rust implementation of CSS Syntax Level 3
Rust
732
star
10

font-kit

A cross-platform font loading library written in Rust
Rust
676
star
11

euclid

Geometry primitives (basic linear algebra) for Rust
Rust
409
star
12

gaol

Cross-platform application sandboxing for Rust
Rust
342
star
13

rust-fnv

Fowler–Noll–Vo hash function
Rust
332
star
14

rust-mozjs

DEPRECATED - moved to servo/mozjs instead.
Rust
293
star
15

cocoa-rs

DEPRECATED - Cocoa/Objective-C bindings for the Rust programming language
Rust
284
star
16

highfive

Github hooks to provide an encouraging atmosphere for new contributors
Python
255
star
17

tendril

Compact string type for zero-copy parsing
Rust
248
star
18

project

A repo for the Servo Project
236
star
19

string-cache

String interning for Rust
Rust
193
star
20

uluru

A simple, fast, LRU cache implementation.
Rust
191
star
21

surfman

Accelerated offscreen graphics for WebGL
Rust
171
star
22

rust-webvr

UNMAINTAINED - WebVR API implementation for servo.
Rust
106
star
23

skia

Skia
C++
105
star
24

heapsize

In support of measuring heap allocations in Rust programs.
Rust
99
star
25

gleam

Generated OpenGL bindings and wrapper for Servo.
Rust
83
star
26

media

Rust
82
star
27

webxr

Bindings for WebXR
Rust
81
star
28

unicode-bidi

Implementation of the Unicode Bidirection Algorithm in Rust
Rust
75
star
29

rust-harfbuzz

Rust bindings to HarfBuzz
Rust
70
star
30

rust-stb-image

Rust bindings to the awesome stb_image library
C
65
star
31

stylo

Rust
59
star
32

rust-layers

A GPU-accelerated 2D animation library for Rust
Rust
58
star
33

servo-starters

Servo Starters is a list of easy tasks that are good for beginners to rust or servo.
JavaScript
58
star
34

saltfs

Salt Stack Filesystem
SaltStack
56
star
35

rust-azure

Rust bindings to mozilla-central's graphics abstraction layer
C++
56
star
36

rust-opengles

[UNMAINTAINED] OpenGL ES 2.0 bindings for Rust (see servo/gleam)
Rust
42
star
37

mozangle

Mozilla’s fork of Google ANGLE, repackaged as a Rust crate
C++
40
star
38

rust-selectors

CSS Selectors matching for Rust
38
star
39

smallbitvec

A growable bit-vector for Rust, optimized for size
Rust
37
star
40

pixman

C
30
star
41

rust-png

Rust bindings for libpng - UNMAINTAINED - DO NOT USE
C
27
star
42

rust-freetype

Rust bindings for FreeType.
Rust
25
star
43

rust-http-client

[UNMAINTAINED] old HTTP client library for Rust
C
24
star
44

rust-xlib

Rust bindings for xlib. UNMAINTAINED
Rust
22
star
45

core-graphics-rs

DEPRECATED - CoreGraphics bindings for Rust
Rust
21
star
46

rust-glut

[UNMAINTAINED] GLUT bindings for Rust
Rust
20
star
47

devices

Servo-specific APIs to access various devices
Rust
19
star
48

core-text-rs

DEPRECATED - Rust bindings for CoreText.
Rust
18
star
49

rustc-test

A fork of Rust’s `test` crate that doesn’t require unstable language features.
Rust
17
star
50

rust-quicksort

A Rust quicksort implementation for in-place sorting.
Rust
17
star
51

hyper_serde

Serde support for Hyper types
Rust
16
star
52

doc.servo.org

Documentation generated from Servo’s source code in its master branch
HTML
15
star
53

rust-fontconfig

Rust bindings for fontconfig.
Rust
15
star
54

book

The Servo Book
JavaScript
14
star
55

libfreetype2

C
13
star
56

servo.org_2014-2020

Main website for Servo.
JavaScript
13
star
57

osmesa-src

OSMesa source code and cargo build scripts to compile on Linux and Mac
C
12
star
58

homebrew-servo

Servo formulae repo for Homebrew
Ruby
11
star
59

nss

Network Security Services - UNMAINTAINED - DO NOT USE
C
11
star
60

plane-split

Plane splitting with euclid
Rust
11
star
61

rust-icu

Rust bindings to ICU (International Components for Unicode)
C++
11
star
62

libcss

[UNMAINTAINED] Servo fork of libcss from the NetSurf project
C
11
star
63

servo-warc-tests

Test Servo on Web Archive snapshots of real web sites
Shell
11
star
64

libfontconfig

Cargoified libfontconfig for Rust packages
C
10
star
65

libhubbub

[UNMAINTAINED] HTML parser library from the NetSurf project
C
10
star
66

cairo

C
10
star
67

libexpat

Not actively updating to new versions of expat. Pull requests to do so accepted.
C
10
star
68

blog.servo.org

The Servo blog
CSS
9
star
69

libgstreamer_android_gen

Scripts to generate Servo Media GStreamer dependencies on Android
Shell
9
star
70

io-surface-rs

Rust bindings to IOSurface.framework on Mac OS X and iOS
Rust
9
star
71

servo.org

Servo project website
HTML
8
star
72

futf

Handling fragments of UTF-8 in Rust
Rust
8
star
73

fontsan

Sanitiser for untrusted font files
C
8
star
74

sparkle

GL bindings for Servo's WebGL implementation (alternative to the `gleam` crate)
Rust
7
star
75

rust-glx

GLX 1.4 bindings for Linux
Rust
7
star
76

rust-hubbub

[UNMAINTAINED] Rust bindings to the hubbub HTML parser library from the NetSurf project
Rust
6
star
77

unicode-script

Rust
6
star
78

gecko-media

Firefox's media playback stack in a stand alone Rust crate
C
6
star
79

internal-wpt-dashboard

A simple wpt.fyi like dashboard to track progress of WPT scores for Servo's focus areas.
JavaScript
5
star
80

libparserutils

[UNMAINTAINED] libparserutils from the NetSurf project
C
5
star
81

rust-css

[UNMAINTAINED] obsolete CSS glue code for Servo
Rust
5
star
82

cgl-rs

Rust bindings for CGL on Mac
Rust
5
star
83

nspr

Netscape Portable Runtime
C
5
star
84

rust-egl

wrapper of EGL (maintenance changes only)
Rust
5
star
85

surfman-chains

An implementation of double-buffered swap chains for surfman
Rust
5
star
86

webrender_traits

DEPRECATED - now contained in https://github.com/servo/webrender/
Rust
4
star
87

download.servo.org

download.servo.org landing page
HTML
4
star
88

app_units

Rust
3
star
89

libpng

C
3
star
90

layout-zoo

A collection of spectacular and exotic CSS layout edge cases
3
star
91

servoexperiments.com

Experiments with Servo.
JavaScript
3
star
92

intermittent-tracker

A live database of intermittent test failures based on github's webhook notifications.
Python
3
star
93

servo-nightly-builds

Repository to host Servo nightly builds using Github Releases.
Shell
2
star
94

content-blocker

A library for parsing Safari-style content blocking lists and dynamically evaluating the rules against against requests.
Rust
2
star
95

servo-viewer

Simple GLUT-based viewer app for Servo
Rust
2
star
96

rust-netsurfcss

[UNMAINTAINED] Rust bindings to libcss
Rust
2
star
97

rust-cairo

Rust bindings for Cairo.
Rust
2
star
98

servo-with-rust-nightly

Detecting breakage early
2
star
99

sharegl

[UNMAINTAINED] A Rust library for cross-process OpenGL texture sharing
Rust
2
star
100

nelson

Newbors for Servo
Python
1
star