SpiderMonkey from firefox-140.14.0

#### Beyond Linux® From Scratch (System V Edition) - Version r13.1-84

### Chapter 9. General Libraries

- Prev

  simdutf-9.1.0

- Next

  SPIRV-Headers-1.4.357.0

- Up
- Home

# SpiderMonkey from firefox-140.14.0

## Introduction to SpiderMonkey

SpiderMonkey is Mozilla's JavaScript and WebAssembly Engine, written in C++ and Rust. In BLFS, the source code of SpiderMonkey is taken from Firefox.

### Note

Development versions of BLFS may not build or run some packages properly if LFS or dependencies have been updated since the most recent stable versions of the books.

### Package Information

- Download (HTTP): https://archive.mozilla.org/pub/firefox/releases/140.14.0esr/source/firefox-140.14.0esr.source.tar.xz

- Download MD5 sum: c2eb4ac79de8b34cb3353272bea1cbd3

- Download size: 614 MB

- Estimated disk space required: 4.7 GB (55 MB installed after removing 42 MB static lib; add 29 MB for the main and jit tests)

- Estimated build time: 1.9 SBU (with parallelism=4; add 0.4 SBU for the main tests and 2.6 SBU for the jit tests)

### Additional Downloads

- Required patch: https://www.linuxfromscratch.org/patches/blfs/svn/spidermonkey-140.14.0-python_3.14_fixes-1.patch

- Required patch: https://www.linuxfromscratch.org/patches/blfs/svn/spidermonkey-140.14.0-rust_1_98-1.patch

### SpiderMonkey Dependencies

#### Required

Cbindgen-0.29.4, ICU-78.3, Which-2.25

#### Recommended

LLVM-23.1.0 (with Clang, required for 32-bit systems without SSE2 capabilities)

### Important

If you are building this package on a 32-bit system, and Clang is not installed or you're overriding the default compiler choice with the environment variable `CXX`, please read the Command Explanations section first.

## Installation of SpiderMonkey

### Note

Unlike most other packages in BLFS, the instructions below require you to untar `firefox-140.14.0esr.tar.xz` and change into the `firefox-140.14.0` directory.

Extracting the tarball will reset the permissions of the current directory to 0755 if you have permission to do that. If you do this in a directory where the sticky bit is set, such as `/tmp` it will end with error messages:

tar: .: Cannot utime: Operation not permitted
tar: .: Cannot change mode to rwxr-xr-t: Operation not permitted
tar: Exiting with failure status due to previous errors

This does finish with non-zero status, but it does NOT mean there is a real problem. Do not untar as the `root` user in a directory where the sticky bit is set - that will unset it.

First, apply a patch to fix compatibility with Python 3.14:

    patch -Np1 -i ../spidermonkey-140.14.0-python_3.14_fixes-1.patch

Fix building this package with rustc 1.98 or newer:

    patch -Np1 -i ../spidermonkey-140.14.0-rust_1_98-1.patch

The configuration of SpiderMonkey is accomplished by creating a `mozconfig` file containing the desired configuration options. A default `mozconfig` is created below. To see the entire list of available configuration options (and a brief description of each), issue ./mach configure -- --help | less. Create the file with the following command:

    cat > mozconfig << "EOF"
    ac_add_options --prefix=/usr
    ac_add_options --enable-project=js
    ac_add_options --disable-debug-symbols
    ac_add_options --disable-jemalloc
    ac_add_options --enable-readline
    ac_add_options --enable-rust-simd
    ac_add_options --with-intl-api
    ac_add_options --with-system-icu
    ac_add_options --with-system-zlib
    EOF

Now invoke the Python mach script to compile SpiderMonkey:

### Note

If you are compiling this package in chroot you must ensure that `/dev/shm` is mounted. If you do not do this, the Python configuration will fail with a traceback report referencing `/usr/lib/pythonN.N/multiprocessing/synchronize.py`. As the `root` user, run:

    mountpoint -q /dev/shm || mount -t tmpfs devshm /dev/shm

    export MACH_BUILD_PYTHON_NATIVE_PACKAGE_SOURCE=none &&
    export MOZBUILD_STATE_PATH=$(pwd)/mozbuild          &&
    ./mach build

To run the SpiderMonkey test suite, issue:

    ./mach jstests

Because we are building with system ICU, a little over 100 tests, depending on ICU version, (out of a total of more than 50,000) are known to fail.

The test suite is executed with all CPU cores available: even in a cgroup with less cores assigned, it still attempts to spawn as many testing jobs as the number of all cores in the system; fortunately the kernel still won't run these jobs on cores not assigned to the cgroup so the CPU usage is still controlled.

To run the JIT test suite, issue the following command:

    ./mach jit-test

Like the SpiderMonkey test suite, the number of test jobs is same as the number of all CPU cores in the system even if a cgroup is used. To make things worse, some test cases can use up to 4 GB of system memory, so the peak memory usage may be very large if your CPU have multiple cores. Running the JIT test suite without enough memory may invoke the kernel OOM killer and cause stability issues. If you don't have enough system memory available, append `-j`N`` to the command and replace `N` with the number of test jobs your available system memory can hold. For example, if you have 15 GB system memory available and 4 CPU cores, append `-j3` to run the test suite with 3 parallel jobs so the memory usage won't exceed 12 GB.

### Caution

An issue in the installation process causes any running program which links to SpiderMonkey shared library (for example, GNOME Shell) to crash if SpiderMonkey is reinstalled, or upgraded or downgraded without a change of the major version number (140 in 140.14.0). To work around this issue, remove the old version of the SpiderMonkey shared library before installation:

    rm -fv /usr/lib/libmozjs-140.so

Install SpiderMonkey by running the following commands as the `root` user:

    MACH_BUILD_PYTHON_NATIVE_PACKAGE_SOURCE=none ./mach install

Still as the `root` user, remove a useless and very large static library, and remove a buggy output of the js140-config script:

    rm -v /usr/lib/libjs_static.ajs &&
    sed -i '/@NSPR_CFLAGS@/d' /usr/bin/js140-config

Still as the `root` user, fix an issue with one of the installed headers:

    sed '$i#define XP_UNIX' -i /usr/include/mozjs-140/js-config.h

Empty the environment variables which were set above:

    unset MACH_BUILD_PYTHON_NATIVE_PACKAGE_SOURCE &&
    unset MOZBUILD_STATE_PATH

## Command Explanations

`MOZBUILD_STATE_PATH=${PWD}/mozbuild`: Override the default location (`${HOME}/.mozbuild`) for the cache of the build system, to avoid polluting the home directory.

`--disable-debug-symbols`: Don't generate debug symbols since they are very large and most users won't need it. Remove it if you want to debug SpiderMonkey.

`--disable-jemalloc`: This switch disables the internal memory allocator used in SpiderMonkey. jemalloc is only intended for the Firefox browser environment. For other applications using SpiderMonkey, the application may crash as items allocated in the jemalloc allocator are freed on the system (glibc) allocator.

`--enable-readline`: This switch enables Readline support in the SpiderMonkey command line interface.

`--enable-rust-simd`: This switch enables SIMD optimization in the shipped encoding_rs crate.

`--with-intl-api`: This enables the internationalization functions required by Gjs.

`--with-system-*`: These parameters allow the build system to use system versions of the above libraries. These are required for stability.

export CC=gcc and export CXX=g++: BLFS use to prefer to use gcc and g++ instead of upstream's defaults of the clang programs. With the release of gcc-12 the build takes longer with gcc and g++, primarily because of extra warnings, and is bigger. Put these two commands into the `mozconfig` file if you wish to continue to use gcc and g++. If you are building on a 32-bit system, also see below.

export CXXFLAGS="$CXXFLAGS -msse2 -mfpmath=sse": Use SSE2 instead of 387 for double-precision floating-point operations. It's needed to satisfy the expectations of upstream (Mozilla) developers with floating-point arithmetic (meaning, a 32-bit processor lacking SSE2 is not capable to run this package). Add it to `mozconfig` if you are building this package on a 32-bit system with GCC. This setting is not needed with Clang, neither with GCC on a 64-bit system because those configurations have SSE2 enabled by default.

## Contents

Installed Programs: js140 and js140-config
Installed Libraries: libmozjs-140.so
Installed Directories: /usr/include/mozjs-140

### Short Descriptions

js140 | provides a command line interface to the JavaScript engine
js140-config | is used to find the SpiderMonkey compiler and linker flags
`libmozjs-140.so` | contains the Mozilla JavaScript API functions

- Prev

  simdutf-9.1.0

- Next

  SPIRV-Headers-1.4.357.0

- Up
- Home