Skip to content

Commit f8f1b2c

Browse files
Merge pull request #367 from Distributive-Network/Xmader/chore/moz-central
Build SpiderMonkey from `mozilla-central`
2 parents 00d06e1 + 76cccdf commit f8f1b2c

22 files changed

+184
-68
lines changed

.github/workflows/test-and-publish.yaml

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ on:
1818
- 'ubuntu-20.04'
1919
- 'macos-12'
2020
- 'macos-14'
21-
- 'windows-2019'
21+
- 'windows-2022'
2222
debug_enabled_python:
2323
type: choice
2424
description: Choose a Python version to run the build with SSH debugging on
@@ -69,13 +69,15 @@ jobs:
6969
- uses: actions/setup-python@v5
7070
with:
7171
python-version: ${{ matrix.python_version }}
72+
- name: Read the mozilla-central commit hash to be used
73+
run: echo "MOZCENTRAL_VERSION=$(cat mozcentral.version)" >> $GITHUB_ENV
7274
- name: Cache spidermonkey build
7375
id: cache-spidermonkey
7476
uses: actions/cache@v4
7577
with:
7678
path: |
7779
./_spidermonkey_install/*
78-
key: spidermonkey115.8.0-${{ runner.os }}-${{ runner.arch }}
80+
key: spidermonkey-${{ env.MOZCENTRAL_VERSION }}-${{ runner.os }}-${{ runner.arch }}
7981
lookup-only: true # skip download
8082
- name: Setup XCode
8183
if: ${{ (matrix.os == 'macos-13' || matrix.os == 'macos-14') && steps.cache-spidermonkey.outputs.cache-hit != 'true' }}
@@ -86,16 +88,20 @@ jobs:
8688
if: ${{ steps.cache-spidermonkey.outputs.cache-hit != 'true' }}
8789
run: ./setup.sh
8890
build-spidermonkey-win:
89-
runs-on: windows-2019
91+
runs-on: windows-2022
92+
# SpiderMonkey requires Visual Studio 2022 or newer.
93+
# The Windows 2019 runner only has Visual Studio Enterprise 2019 installed.
9094
steps:
9195
- uses: actions/checkout@v4
96+
- name: Read the mozilla-central commit hash to be used
97+
run: echo "MOZCENTRAL_VERSION=$(cat mozcentral.version)" >> $GITHUB_ENV
9298
- name: Cache spidermonkey build
9399
id: cache-spidermonkey
94100
uses: actions/cache@v4
95101
with:
96102
path: |
97103
./_spidermonkey_install/*
98-
key: spidermonkey115.8.0-${{ runner.os }}-${{ runner.arch }}
104+
key: spidermonkey-${{ env.MOZCENTRAL_VERSION }}-${{ runner.os }}-${{ runner.arch }}
99105
lookup-only: true # skip download
100106
- name: Install dependencies
101107
if: ${{ steps.cache-spidermonkey.outputs.cache-hit != 'true' }}
@@ -104,7 +110,7 @@ jobs:
104110
# Already installed in Github Actions runner
105111
# choco install -y cmake --installargs 'ADD_CMAKE_TO_PATH=System' # add CMake to system PATH
106112
# choco install -y llvm gnuwin32-m4
107-
choco install -y wget make
113+
choco install -y wget make unzip
108114
- name: Install MozillaBuild
109115
if: ${{ steps.cache-spidermonkey.outputs.cache-hit != 'true' }}
110116
run: |
@@ -123,7 +129,7 @@ jobs:
123129
fail-fast: false
124130
matrix:
125131
# The lowest supported version is Ubuntu 20.04 + Python 3.8 or macOS 12 + Python 3.9
126-
os: [ 'ubuntu-20.04', 'macos-12', 'macos-14', 'windows-2019' ]
132+
os: [ 'ubuntu-20.04', 'macos-12', 'macos-14', 'windows-2022' ]
127133
python_version: [ '3.8', '3.9', '3.10', '3.11', '3.12' ]
128134
exclude:
129135
# actions/setup-python: The version '3.8'/'3.9' with architecture 'arm64' was not found for macOS.
@@ -154,7 +160,7 @@ jobs:
154160
sudo apt-get install -y cmake llvm
155161
elif [[ "$OSTYPE" == "darwin"* ]]; then # macOS
156162
brew update || true # allow failure
157-
brew install cmake pkg-config wget coreutils # `coreutils` installs the `realpath` command
163+
brew install cmake pkg-config wget unzip coreutils # `coreutils` installs the `realpath` command
158164
fi
159165
echo "Installing python deps"
160166
poetry self add "poetry-dynamic-versioning[plugin]"
@@ -177,12 +183,14 @@ jobs:
177183
with:
178184
name: docs-${{ github.run_id }}-${{ github.sha }}
179185
path: ./build/docs/html/
186+
- name: Read the mozilla-central commit hash to be used
187+
run: echo "MOZCENTRAL_VERSION=$(cat mozcentral.version)" >> $GITHUB_ENV
180188
- name: Use cached spidermonkey build
181189
uses: actions/cache@v4
182190
with:
183191
path: |
184192
./_spidermonkey_install/*
185-
key: spidermonkey115.8.0-${{ runner.os }}-${{ runner.arch }}
193+
key: spidermonkey-${{ env.MOZCENTRAL_VERSION }}-${{ runner.os }}-${{ runner.arch }}
186194
fail-on-cache-miss: true # SpiderMonkey is expected to be cached in its dedicated job
187195
- name: Build pminit
188196
run: |
@@ -203,7 +211,7 @@ jobs:
203211
name: wheel-${{ github.run_id }}-${{ github.sha }}
204212
path: ./dist/
205213
- name: Set cores to get stored in /cores
206-
if: ${{ matrix.os != 'windows-2019' }}
214+
if: ${{ matrix.os != 'windows-2022' }}
207215
# TODO (Caleb Aikens) figure out how to get Windows core dumps
208216
run: |
209217
sudo mkdir -p /cores
@@ -238,7 +246,7 @@ jobs:
238246
credentials: "admin:admin"
239247
- name: Upload core dumps as CI artifacts
240248
uses: actions/upload-artifact@v3
241-
if: ${{ matrix.os != 'windows-2019' && failure() }}
249+
if: ${{ matrix.os != 'windows-2022' && failure() }}
242250
# TODO (Caleb Aikens) figure out how to get Windows core dumps
243251
with:
244252
name: cores-${{ matrix.os }}-${{ matrix.python_version }}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: 'Create pull requests to update mozilla-central version to the latest'
2+
3+
on:
4+
schedule:
5+
- cron: "00 14 * * 1" # run every Monday at 14:00 UTC (10:00 Eastern Daylight Time)
6+
workflow_call:
7+
workflow_dispatch: # or you can run it manually
8+
9+
defaults:
10+
run:
11+
shell: bash
12+
13+
jobs:
14+
update:
15+
runs-on: ubuntu-20.04
16+
steps:
17+
- uses: actions/checkout@v4
18+
- name: Check Version
19+
# Check the latest changes on mozilla-central via the Mercurial pushlog HTTP API
20+
# See https://mozilla-version-control-tools.readthedocs.io/en/latest/hgmo/pushlog.html#hgweb-commands
21+
run: |
22+
COMMIT_HASH=$(
23+
curl -s "https://hg.mozilla.org/mozilla-central/json-pushes?tipsonly=1&version=2" |\
24+
jq --join-output '(.lastpushid | tostring) as $pushid | empty, .pushes[$pushid].changesets[0]'
25+
)
26+
echo "MOZCENTRAL_VERSION=$COMMIT_HASH" >> $GITHUB_ENV
27+
- name: Update `mozcentral.version` File
28+
run: echo $MOZCENTRAL_VERSION > mozcentral.version
29+
- name: Create Pull Request
30+
uses: peter-evans/create-pull-request@v6
31+
with:
32+
add-paths: mozcentral.version
33+
commit-message: |
34+
chore(deps): upgrade SpiderMonkey to `${{ env.MOZCENTRAL_VERSION }}`
35+
branch: chore/upgrade-spidermonkey-to-${{ env.MOZCENTRAL_VERSION }}
36+
title: Upgrade SpiderMonkey to mozilla-central commit `${{ env.MOZCENTRAL_VERSION }}`
37+
body: |
38+
Changeset: https://hg.mozilla.org/mozilla-central/rev/${{ env.MOZCENTRAL_VERSION }}
39+
labels: dependencies

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ lib/*
77
.pytest_cache
88
.DS_Store
99
firefox-*.tar.xz
10+
firefox-*.zip
1011
firefox-*/
12+
mozilla-central-*
1113
__pycache__
1214
Testing/Temporary
13-
_spidermonkey_install
15+
_spidermonkey_install*
1416
uncrustify-*.tar.gz
1517
uncrustify-*/
1618
uncrustify

cmake/modules/FindSpiderMonkey.cmake

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
# SPIDERMONKEY_FOUND - True if SpiderMonkey found.
2525
# SPIDERMONKEY_THREADSAFE - True if SpiderMonkey is compiled with multi threading support.
2626

27-
#Last Change: 2022-10-03 (Caleb Aikens)
28-
2927
include(CheckIncludeFileCXX)
3028
include(CheckCXXSourceCompiles)
3129
include(CheckCXXSourceRuns)
@@ -36,11 +34,26 @@ if(SPIDERMONKEY_FOUND)
3634
set(SPIDERMONKEY_FIND_QUIETLY TRUE)
3735
endif()
3836

37+
# Get the SpiderMonkey major version number
38+
# See https://hg.mozilla.org/releases/mozilla-esr102/file/tip/js/src/old-configure.in#l1081
39+
file(GLOB LIB_PATH "${CMAKE_CURRENT_SOURCE_DIR}/_spidermonkey_install")
40+
execute_process(COMMAND
41+
"sh" "-c" "./js*-config --version" # Run "_spidermonkey_install/bin/js*-config --version" to print the full version number
42+
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/_spidermonkey_install/bin"
43+
OUTPUT_VARIABLE MOZILLA_VERSION
44+
)
45+
string(STRIP ${MOZILLA_VERSION} MOZILLA_VERSION)
46+
string(REGEX REPLACE "^([0-9]+)(\\.[0-9]+)*([ab][0-9]|)?" # Only the MAJOR and the "a1" (indicator of nightly build) part is needed
47+
"\\1\\3" # see https://hg.mozilla.org/releases/mozilla-esr102/file/tip/build/moz.configure/init.configure#l959
48+
MOZILLA_SYMBOLVERSION
49+
${MOZILLA_VERSION}
50+
)
51+
3952
# SpiderMonkey search paths
4053
set(SPIDERMONKEY_PATHS
4154
"${CMAKE_CURRENT_SOURCE_DIR}/_spidermonkey_install"
4255
"${CMAKE_CURRENT_SOURCE_DIR}/_spidermonkey_install/lib"
43-
"${CMAKE_CURRENT_SOURCE_DIR}/_spidermonkey_install/include/mozjs-115"
56+
"${CMAKE_CURRENT_SOURCE_DIR}/_spidermonkey_install/include/mozjs-${MOZILLA_SYMBOLVERSION}"
4457
${SPIDERMONKEY_ROOT}
4558
$ENV{SPIDERMONKEY_ROOT}
4659
~/Library/Frameworks
@@ -60,7 +73,7 @@ set(SPIDERMONKEY_PATHS
6073
set(SPIDERMONKEY_HEADERS jsapi.h js/RequiredDefines.h)
6174

6275
# SpiderMonkey include suffix paths
63-
set(SPIDERMONKEY_INCLUDE_SUFFIX_PATHS include/mozjs-115/)
76+
set(SPIDERMONKEY_INCLUDE_SUFFIX_PATHS include/mozjs-${MOZILLA_SYMBOLVERSION}/)
6477

6578
# Find SpiderMonkey include path
6679
find_path(SPIDERMONKEY_INCLUDE_DIR ${SPIDERMONKEY_HEADERS}
@@ -71,7 +84,7 @@ find_path(SPIDERMONKEY_INCLUDE_DIR ${SPIDERMONKEY_HEADERS}
7184
)
7285

7386
# SpiderMonkey libs
74-
set(SPIDERMONKEY_LIBRARY_NAMES libmozjs-115.so libmozjs-115.dylib mozjs-115.lib)
87+
set(SPIDERMONKEY_LIBRARY_NAMES libmozjs-${MOZILLA_SYMBOLVERSION}.so libmozjs-${MOZILLA_SYMBOLVERSION}.dylib mozjs-${MOZILLA_SYMBOLVERSION}.lib)
7588

7689
set(SPIDERMONKEY_LIB_SUFFIX_PATHS js/src/build lib)
7790

include/JobQueue.hh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ void runJobs(JSContext *cx) override;
7878
*/
7979
bool empty() const override;
8080

81+
/**
82+
* @return true if the job queue stopped draining, which results in `empty()` being false after `runJobs()`.
83+
*/
84+
bool isDrainingStopped() const override;
85+
8186
/**
8287
* @brief Appends a callback to the queue of FinalizationRegistry callbacks
8388
*

include/jsTypeFactory.hh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,18 @@ public:
2525
* @return PyObject* - the PyObject string
2626
*/
2727
static PyObject *getPyString(const char16_t *chars);
28+
static PyObject *getPyString(const JS::Latin1Char *chars);
2829

2930
/**
3031
* @brief decrefs the underlying PyObject string when the JSString is finalized
3132
*
3233
* @param chars - The char buffer of the string
3334
*/
3435
void finalize(char16_t *chars) const override;
36+
void finalize(JS::Latin1Char *chars) const override;
3537

3638
size_t sizeOfBuffer(const char16_t *chars, mozilla::MallocSizeOf mallocSizeOf) const override;
39+
size_t sizeOfBuffer(const JS::Latin1Char *chars, mozilla::MallocSizeOf mallocSizeOf) const override;
3740
};
3841
extern PythonExternalString PythonExternalStringCallbacks;
3942

mozcentral.version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
d25c9bdacb64ae50779dc91f5919ca0189ad6c36

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ include = [
2323
{ path = "tests", format = "sdist" },
2424
{ path = "CMakeLists.txt", format = "sdist" },
2525
{ path = "*.sh", format = "sdist" },
26+
{ path = "mozcentral.version", format = "sdist" },
2627
]
2728

2829

python/pythonmonkey/lib/pmdb.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def enable(debuggerGlobalObject=pm.eval("debuggerGlobal")):
2222
return # already enabled, skipping
2323

2424
debuggerGlobalObject._pmdbEnabled = True
25-
debuggerGlobalObject.eval("""(debuggerInput, _pythonPrint, _pythonExit) => {
25+
pm.eval("debuggerGlobal.eval")("""(mainGlobal, debuggerInput, _pythonPrint, _pythonExit) => {
2626
const dbg = new Debugger()
2727
const mainDebuggee = dbg.addDebuggee(mainGlobal)
2828
dbg.uncaughtExceptionHook = (e) => {
@@ -177,4 +177,4 @@ def enable(debuggerGlobalObject=pm.eval("debuggerGlobal")):
177177
// Enter debugger on `debugger;` statement
178178
dbg.onDebuggerStatement = (frame) => enterDebuggerLoop(frame)
179179
180-
}""")(debuggerInput, print, lambda status: exit(int(status)))
180+
}""")(pm.globalThis, debuggerInput, print, lambda status: exit(int(status)))

setup.sh

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ if [[ "$OSTYPE" == "linux-gnu"* ]]; then # Linux
1818
SUDO='sudo'
1919
fi
2020
$SUDO apt-get update --yes
21-
$SUDO apt-get install --yes cmake graphviz llvm clang pkg-config m4 \
21+
$SUDO apt-get install --yes cmake graphviz llvm clang pkg-config m4 unzip \
2222
wget curl python3-distutils python3-dev
2323
# Install Doxygen
2424
# the newest version in Ubuntu 20.04 repository is 1.8.17, but we need Doxygen 1.9 series
@@ -28,15 +28,16 @@ if [[ "$OSTYPE" == "linux-gnu"* ]]; then # Linux
2828
rm -rf doxygen-1.9.7 doxygen-1.9.7.linux.bin.tar.gz
2929
elif [[ "$OSTYPE" == "darwin"* ]]; then # macOS
3030
brew update || true # allow failure
31-
brew install cmake doxygen pkg-config wget coreutils # `coreutils` installs the `realpath` command
31+
brew install cmake doxygen pkg-config wget unzip coreutils # `coreutils` installs the `realpath` command
3232
elif [[ "$OSTYPE" == "msys"* ]]; then # Windows
3333
echo "Dependencies are not going to be installed automatically on Windows."
3434
else
3535
echo "Unsupported OS"
3636
exit 1
3737
fi
3838
# Install rust compiler
39-
curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain 1.69 # force to use Rust 1.69 because 1.70 has linking issues on Windows
39+
curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain 1.76
40+
cargo install cbindgen
4041
# Setup Poetry
4142
curl -sSL https://install.python-poetry.org | python3 - --version "1.7.1"
4243
if [[ "$OSTYPE" == "msys"* ]]; then # Windows
@@ -51,15 +52,15 @@ echo "Done installing dependencies"
5152
echo "Downloading uncrustify source code"
5253
wget -c -q https://github.com/uncrustify/uncrustify/archive/refs/tags/uncrustify-0.78.1.tar.gz
5354
mkdir -p uncrustify-source
54-
tar -xzvf uncrustify-0.78.1.tar.gz -C uncrustify-source --strip-components=1 # strip the root folder
55+
tar -xzf uncrustify-0.78.1.tar.gz -C uncrustify-source --strip-components=1 # strip the root folder
5556
echo "Done downloading uncrustify source code"
5657

5758
echo "Building uncrustify"
5859
cd uncrustify-source
5960
mkdir -p build
6061
cd build
6162
if [[ "$OSTYPE" == "msys"* ]]; then # Windows
62-
cmake ../ -T ClangCL
63+
cmake ../
6364
cmake --build . -j$CPUS --config Release
6465
cp Release/uncrustify.exe ../../uncrustify.exe
6566
else
@@ -71,9 +72,10 @@ cd ../..
7172
echo "Done building uncrustify"
7273

7374
echo "Downloading spidermonkey source code"
74-
wget -c -q https://ftp.mozilla.org/pub/firefox/releases/115.8.0esr/source/firefox-115.8.0esr.source.tar.xz
75-
mkdir -p firefox-source
76-
tar xf firefox-115.8.0esr.source.tar.xz -C firefox-source --strip-components=1 # strip the root folder
75+
# Read the commit hash for mozilla-central from the `mozcentral.version` file
76+
MOZCENTRAL_VERSION=$(cat mozcentral.version)
77+
wget -c -q -O firefox-source-${MOZCENTRAL_VERSION}.zip https://hg.mozilla.org/mozilla-central/archive/${MOZCENTRAL_VERSION}.zip
78+
unzip -q firefox-source-${MOZCENTRAL_VERSION}.zip && mv mozilla-central-${MOZCENTRAL_VERSION} firefox-source
7779
echo "Done downloading spidermonkey source code"
7880

7981
echo "Building spidermonkey"
@@ -85,14 +87,20 @@ sed -i'' -e '/"winheap.cpp"/d' ./memory/mozalloc/moz.build # https://bugzilla.mo
8587
sed -i'' -e 's/"install-name-tool"/"install_name_tool"/' ./moz.configure # `install-name-tool` does not exist, but we have `install_name_tool`
8688
sed -i'' -e 's/bool Unbox/JS_PUBLIC_API bool Unbox/g' ./js/public/Class.h # need to manually add JS_PUBLIC_API to js::Unbox until it gets fixed in Spidermonkey
8789
sed -i'' -e 's/bool js::Unbox/JS_PUBLIC_API bool js::Unbox/g' ./js/src/vm/JSObject.cpp # same here
90+
sed -i'' -e 's/shared_lib = self._pretty_path(libdef.output_path, backend_file)/shared_lib = libdef.lib_name/' ./python/mozbuild/mozbuild/backend/recursivemake.py
91+
sed -i'' -e 's/if version < Version(mac_sdk_min_version())/if False/' ./build/moz.configure/toolchain.configure # do not verify the macOS SDK version as the required version is not available on Github Actions runner
92+
sed -i'' -e 's/return JS::GetWeakRefsEnabled() == JS::WeakRefSpecifier::Disabled/return false/' ./js/src/vm/GlobalObject.cpp # forcibly enable FinalizationRegistry
93+
sed -i'' -e 's/return !IsIteratorHelpersEnabled()/return false/' ./js/src/vm/GlobalObject.cpp # forcibly enable iterator helpers
94+
sed -i'' -e '/MOZ_CRASH_UNSAFE_PRINTF/,/__PRETTY_FUNCTION__);/d' ./mfbt/LinkedList.h # would crash in Debug Build: in `~LinkedList()` it should have removed all this list's elements before the list's destruction
95+
sed -i'' -e '/MOZ_ASSERT(stackRootPtr == nullptr);/d' ./js/src/vm/JSContext.cpp # would assert false in Debug Build since we extensively use `new JS::Rooted`
8896
cd js/src
8997
mkdir -p _build
9098
cd _build
9199
mkdir -p ../../../../_spidermonkey_install/
92100
../configure \
93101
--prefix=$(realpath $PWD/../../../../_spidermonkey_install) \
94102
--with-intl-api \
95-
--without-system-zlib \
103+
$(if [[ "$OSTYPE" != "msys"* ]]; then echo "--without-system-zlib"; fi) \
96104
--disable-debug-symbols \
97105
--disable-jemalloc \
98106
--disable-tests \

0 commit comments

Comments
 (0)