Skip to content

Commit d598b71

Browse files
Merge branch 'main' into websocket-builtin-module
2 parents 5243726 + df3c30b commit d598b71

17 files changed

Lines changed: 690 additions & 545 deletions

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

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ on:
1717
- ''
1818
- 'ubuntu-22.04'
1919
- 'macos-15-intel'
20-
- 'macos-14'
20+
- 'macos-15'
2121
- 'windows-2022'
2222
debug_enabled_python:
2323
type: choice
@@ -32,6 +32,7 @@ on:
3232
- '3.12'
3333
- '3.13'
3434
- '3.14'
35+
- '3.15'
3536
build_type:
3637
type: choice
3738
description: 'Choose the build type to use'
@@ -45,6 +46,10 @@ on:
4546
- 'Release'
4647
- 'None'
4748
pull_request:
49+
schedule:
50+
# GitHub Actions delete the CI caches that haven't been accessed in 7 days.
51+
# We need to keep the cached SpiderMonkey build because it takes a long time to build and is required for the PythonMonkey build.
52+
- cron: '0 4 */6 * *' # every 6 days
4853

4954
env:
5055
# don't upgrade outdated brew packages because the process is too slow
@@ -67,9 +72,8 @@ jobs:
6772
strategy:
6873
fail-fast: false
6974
matrix:
70-
# Use Ubuntu 22.04 / macOS 15 x86_64 / macOS 14 arm64 + Python 3.10 to build SpiderMonkey
71-
os: [ 'ubuntu-22.04', 'macos-15-intel', 'macos-14', 'ubuntu-22.04-arm' ] # macOS 14 runner exclusively runs on M1 hardwares
72-
# see https://github.blog/changelog/2024-01-30-github-actions-macos-14-sonoma-is-now-available
75+
# Use Ubuntu 22.04 / macOS 15 x86_64 / macOS 15 arm64 + Python 3.10 to build SpiderMonkey
76+
os: [ 'ubuntu-22.04', 'macos-15-intel', 'macos-15', 'ubuntu-22.04-arm' ]
7377
python_version: [ '3.10' ]
7478
runs-on: ${{ matrix.os }}
7579
container: ${{ (startsWith(matrix.os, 'ubuntu') && 'ubuntu:20.04') || null }} # Use the Ubuntu 20.04 container inside Ubuntu 22.04 runner to build
@@ -100,10 +104,10 @@ jobs:
100104
apt-get install -y lsb-release wget software-properties-common gnupg
101105
wget https://apt.llvm.org/llvm.sh
102106
chmod +x llvm.sh
103-
./llvm.sh 18 # install LLVM version 18
104-
update-alternatives --install /usr/bin/llvm-config llvm-config /usr/bin/llvm-config-18 18
105-
update-alternatives --install /usr/bin/clang clang /usr/bin/clang-18 18
106-
update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-18 18
107+
./llvm.sh 19 # SpiderMonkey at the current mozcentral.version pin requires clang/llvm >= 19 (confirmed via its own configure error)
108+
update-alternatives --install /usr/bin/llvm-config llvm-config /usr/bin/llvm-config-19 19
109+
update-alternatives --install /usr/bin/clang clang /usr/bin/clang-19 19
110+
update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-19 19
107111
clang --version
108112
clang++ --version
109113
- name: Setup Python
@@ -125,7 +129,7 @@ jobs:
125129
with:
126130
python-version: ${{ matrix.python_version }}
127131
- name: Setup XCode
128-
if: ${{ matrix.os == 'macos-15-intel' && steps.cache-spidermonkey.outputs.cache-hit != 'true' }}
132+
if: ${{ (matrix.os == 'macos-15-intel' || matrix.os == 'macos-15') && steps.cache-spidermonkey.outputs.cache-hit != 'true' }}
129133
# Xcode 16.x removed the old linker behaviour (-ld64 or -ld_classic) that SpiderMonkey relies on, so we need to switch to an older version
130134
run: sudo xcode-select -switch /Applications/Xcode_16.0.app
131135
- name: Build spidermonkey
@@ -181,8 +185,8 @@ jobs:
181185
strategy:
182186
fail-fast: false
183187
matrix:
184-
os: [ 'ubuntu-22.04', 'macos-15-intel', 'macos-14', 'windows-2022', 'ubuntu-22.04-arm' ]
185-
python_version: [ '3.8', '3.9', '3.10', '3.11', '3.12', '3.13', '3.14' ]
188+
os: [ 'ubuntu-22.04', 'macos-15-intel', 'macos-15', 'windows-2022', 'ubuntu-22.04-arm' ]
189+
python_version: [ '3.8', '3.9', '3.10', '3.11', '3.12', '3.13', '3.14', '3.15' ]
186190
runs-on: ${{ matrix.os }}
187191
container: ${{ (startsWith(matrix.os, 'ubuntu') && 'ubuntu:20.04') || null }}
188192
steps:
@@ -231,16 +235,33 @@ jobs:
231235
- name: Setup Poetry
232236
uses: snok/install-poetry@v1.4.1
233237
with:
234-
version: 1.5.1
238+
version: 1.8.5
235239
- name: Install Dependencies
236240
run: |
237241
echo "Installing Dependencies"
238242
if [[ "$OSTYPE" == "linux-gnu"* ]]; then # Linux
239243
sudo apt-get update -y
240244
sudo apt-get install -y cmake llvm
245+
# SpiderMonkey's headers now require clang/llvm >= 19 and
246+
# libstdc++ >= 10 to compile against (same requirement as the
247+
# build-spidermonkey job) -- this job's default toolchain
248+
# (ubuntu:20.04's stock gcc-9) doesn't meet it.
249+
sudo apt-get install -y lsb-release wget software-properties-common gnupg
250+
wget https://apt.llvm.org/llvm.sh
251+
chmod +x llvm.sh
252+
sudo ./llvm.sh 19
253+
sudo update-alternatives --install /usr/bin/llvm-config llvm-config /usr/bin/llvm-config-19 19
254+
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-19 19
255+
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-19 19
256+
sudo apt-get install -y libstdc++-10-dev
257+
echo "CC=clang" >> $GITHUB_ENV
258+
echo "CXX=clang++" >> $GITHUB_ENV
241259
elif [[ "$OSTYPE" == "darwin"* ]]; then # macOS
242-
brew update || true # allow failure
243-
brew install cmake pkg-config wget unzip coreutils # `coreutils` installs the `realpath` command
260+
# Shared with setup.sh: installs llvm@19/lld@19 (Xcode's clang is too old for
261+
# SpiderMonkey) and, on Intel, pulls archived bottles from GHCR.
262+
source ./cmake/macos-brew-deps.sh
263+
install_macos_brew_deps
264+
echo "PATH=$PATH" >> $GITHUB_ENV
244265
fi
245266
echo "Installing python deps"
246267
poetry self add "poetry-dynamic-versioning[plugin]"
@@ -255,7 +276,7 @@ jobs:
255276
run: |
256277
sudo apt-get install -y graphviz
257278
# the newest version in Ubuntu 20.04 repository is 1.8.17, but we need Doxygen 1.9 series
258-
wget -c -q https://www.doxygen.nl/files/doxygen-1.9.7.linux.bin.tar.gz
279+
wget -c -q https://github.com/doxygen/doxygen/releases/download/Release_1_9_7/doxygen-1.9.7.linux.bin.tar.gz
259280
tar xf doxygen-1.9.7.linux.bin.tar.gz
260281
cd doxygen-1.9.7 && sudo make install && cd -
261282
rm -rf doxygen-1.9.7 doxygen-1.9.7.linux.bin.tar.gz
@@ -289,7 +310,7 @@ jobs:
289310
BUILD_TYPE=${WORKFLOW_BUILD_TYPE:-"Debug"} poetry build --format=wheel
290311
ls -lah ./dist/
291312
- name: Make the wheels we build also support lower versions of macOS
292-
if: ${{ matrix.os == 'macos-15-intel' || matrix.os == 'macos-14' }}
313+
if: ${{ matrix.os == 'macos-15-intel' || matrix.os == 'macos-15' }}
293314
# Change the platform tag part of the wheel filename to `macosx_11_0_xxx` (means to support macOS 11.0 and above)
294315
# See https://packaging.python.org/en/latest/specifications/binary-distribution-format/#file-format
295316
# A wheel package file will only be selected by pip to install if the platform tag satisfies, regardless of whether the binary compatibility actually is.
@@ -299,6 +320,16 @@ jobs:
299320
for file in *.whl; do
300321
mv "$file" "$(echo "$file" | sed -E 's/macosx_[0-9]+_[0-9]+/macosx_11_0/')";
301322
done
323+
- name: Tag the Linux wheels as manylinux
324+
if: ${{ startsWith(matrix.os, 'ubuntu') }}
325+
# PyPI rejects wheels with the plain `linux_xxx` platform tag.
326+
# The wheels are built inside the Ubuntu 20.04 container (glibc 2.31), so tag them as `manylinux_2_31_xxx`.
327+
run: |
328+
cd ./dist/
329+
for file in *-linux_*.whl; do
330+
[ -e "$file" ] || continue
331+
mv "$file" "$(echo "$file" | sed -E 's/-linux_/-manylinux_2_31_/')";
332+
done
302333
- name: Upload wheel as CI artifacts
303334
uses: actions/upload-artifact@v4
304335
with:
@@ -330,7 +361,7 @@ jobs:
330361
- name: Setup Poetry
331362
uses: snok/install-poetry@v1
332363
with:
333-
version: 1.5.1
364+
version: 1.8.5
334365
- name: Build source distribution (sdist) file
335366
run: |
336367
poetry self add "poetry-dynamic-versioning[plugin]"

‎CMakeLists.txt‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
3030
include(FetchContent)
3131

3232
if (WIN32)
33-
SET(COMPILE_FLAGS "/GR- /W0")
33+
# This build bypasses moz.build, which normally defines XP_WIN; without
34+
# it SpiderMonkey headers (e.g. PlatformMutex.h) take a POSIX path.
35+
SET(COMPILE_FLAGS "/GR- /W0 /DXP_WIN")
3436

3537
SET(OPTIMIZED "/O2")
3638
SET(UNOPTIMIZED "/Od")
@@ -39,7 +41,9 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
3941
SET(PROFILE "/PROFILE")
4042
SET(ADDRESS_SANITIZE "/fsanitize=address /Oy-")
4143
else()
42-
SET(COMPILE_FLAGS "-fno-rtti -Wno-invalid-offsetof")
44+
# Same as -DXP_WIN above: without XP_UNIX, headers such as
45+
# mfbt/UniquePtrExtensions.h hit their "Unsupported OS" #error.
46+
SET(COMPILE_FLAGS "-fno-rtti -Wno-invalid-offsetof -DXP_UNIX")
4347

4448
SET(OPTIMIZED "-Ofast -DNDEBUG")
4549
SET(UNOPTIMIZED "-O0")

‎cmake/macos-brew-deps.sh‎

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/bin/bash
2+
# Source this file on macOS, then call `install_macos_brew_deps`.
3+
#
4+
# Installs cmake, pkg-config, wget, unzip, llvm@19 and lld@19.
5+
# On Intel Macs Homebrew no longer publishes bottles for newer macOS, so some
6+
# formulae (llvm@19, lld@19) would be built from source, which is
7+
# very slow or broken. The older Intel (macOS Sonoma) bottles are still on
8+
# GHCR, so install those manually first.
9+
10+
# $1 = formula path on GHCR (e.g. llvm/19), $2 = version, $3 = keg name (e.g. llvm@19)
11+
fetch_intel_bottle() {
12+
local token index digest cellar
13+
cellar="$(brew --cellar)"
14+
token=$(curl -fsSL "https://ghcr.io/token?service=ghcr.io&scope=repository:homebrew/core/$1:pull" | python3 -c 'import sys,json; print(json.load(sys.stdin)["token"])')
15+
index=$(curl -fsSL -H "Authorization: Bearer $token" -H "Accept: application/vnd.oci.image.index.v1+json" "https://ghcr.io/v2/homebrew/core/$1/manifests/$2")
16+
digest=$(echo "$index" | python3 -c 'import sys,json; print(next(m["annotations"]["sh.brew.bottle.digest"] for m in json.load(sys.stdin)["manifests"] if m["annotations"].get("org.opencontainers.image.ref.name","").endswith(".sonoma") and m["platform"]["architecture"]=="amd64"))')
17+
curl -fsSL -H "Authorization: Bearer $token" -o "/tmp/$3.tar.gz" "https://ghcr.io/v2/homebrew/core/$1/blobs/sha256:$digest"
18+
tar -xzf "/tmp/$3.tar.gz" -C "$cellar"
19+
relocate_bottle "$cellar/$3"
20+
mkdir -p "$(brew --prefix)/opt"
21+
ln -sfn "$cellar/$3/$2" "$(brew --prefix)/opt/$3"
22+
}
23+
24+
# Replace the @@HOMEBREW_PREFIX@@ / @@HOMEBREW_CELLAR@@ placeholders that bottles
25+
# ship with (normally done by `brew install` when pouring a bottle).
26+
relocate_bottle() {
27+
local dir="$1" prefix cellar f old
28+
prefix="$(brew --prefix)"
29+
cellar="$(brew --cellar)"
30+
_reloc() { local s="${1//@@HOMEBREW_PREFIX@@/$prefix}"; echo "${s//@@HOMEBREW_CELLAR@@/$cellar}"; }
31+
# text files (scripts, .pc, .cmake, clang config, ...)
32+
while IFS= read -r f; do
33+
sed -i '' -e "s|@@HOMEBREW_PREFIX@@|$prefix|g" -e "s|@@HOMEBREW_CELLAR@@|$cellar|g" "$f"
34+
done < <(grep -rIl '@@HOMEBREW_' "$dir" 2>/dev/null || true)
35+
# Mach-O files: dependent libraries, install names and rpaths
36+
find "$dir" -type f ! -type l | while IFS= read -r f; do
37+
file "$f" | grep -q 'Mach-O' || continue
38+
chmod u+w "$f"
39+
otool -L "$f" | awk 'NR>1 && /@@HOMEBREW_/{print $1}' | while IFS= read -r old; do
40+
install_name_tool -change "$old" "$(_reloc "$old")" "$f"
41+
done
42+
old="$(otool -D "$f" 2>/dev/null | sed -n '2p' || true)"
43+
if [[ "$old" == *@@HOMEBREW_* ]]; then install_name_tool -id "$(_reloc "$old")" "$f"; fi
44+
otool -l "$f" | awk '/cmd LC_RPATH/{getline; getline; if ($2 ~ /@@HOMEBREW_/) print $2}' | while IFS= read -r old; do
45+
install_name_tool -rpath "$old" "$(_reloc "$old")" "$f"
46+
done
47+
codesign -f -s - "$f" 2>/dev/null || true # ad-hoc re-sign after editing
48+
done
49+
}
50+
51+
install_macos_brew_deps() {
52+
brew update || true # allow failure
53+
if [[ "$(uname -m)" == "x86_64" ]]; then
54+
# llvm@19 depends on zstd
55+
brew install zstd
56+
fetch_intel_bottle llvm/19 19.1.7 llvm@19
57+
fetch_intel_bottle lld/19 19.1.7 lld@19
58+
# NOTE: `coreutils` is deliberately not installed: it depends on openssl@4,
59+
# which has no Intel bottle at its current version (built from source, ~10 min).
60+
# macOS ships `realpath` natively since 12.3.
61+
brew install cmake pkg-config wget unzip
62+
else
63+
brew install cmake pkg-config wget unzip
64+
# SpiderMonkey requires clang >= 19 and lld as the host linker; Xcode's clang
65+
# is older and ships no lld. Versioned formulas because the unversioned
66+
# `llvm`/`lld` build from source for hours on some macOS versions.
67+
brew install llvm@19 lld@19
68+
fi
69+
# Both kegs are keg-only, so put them on PATH explicitly.
70+
export PATH="$(brew --prefix llvm@19)/bin:$(brew --prefix lld@19)/bin:$PATH"
71+
# fail fast if the (manually installed) toolchain doesn't run
72+
clang --version
73+
ld.lld --version || true
74+
}

‎include/JobQueue.hh‎

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -49,45 +49,37 @@ bool init(JSContext *cx);
4949
* If any error happens while generating the host defined data, this method
5050
* should set a pending exception to `cx` and return `false`.
5151
*/
52-
bool getHostDefinedData(JSContext *cx, JS::MutableHandle<JSObject *> data) const override;
52+
bool getHostDefinedData(JSContext *cx, JS::MutableHandle<JSObject *> incumbentGlobal, JS::MutableHandle<JSObject *> data) const override;
5353

5454
/**
55-
* @brief Enqueue a reaction job `job` for `promise`, which was allocated at
56-
* `allocationSite`. Provide `incumbentGlobal` as the incumbent global for
57-
* the reaction job's execution.
55+
* @brief Ask the embedding for the host defined global to use when running
56+
* a JS microtask.
5857
*
59-
* `promise` can be null if the promise is optimized out.
60-
* `promise` is guaranteed not to be optimized out if the promise has
61-
* non-default user-interaction flag.
58+
* Not tracked by this embedding; null falls back to SpiderMonkey's default,
59+
* as its own InternalJobQueue does.
6260
*/
63-
bool enqueuePromiseJob(JSContext *cx, JS::HandleObject promise,
64-
JS::HandleObject job, JS::HandleObject allocationSite,
65-
JS::HandleObject incumbentGlobal) override;
61+
bool getHostDefinedGlobal(JSContext *cx, JS::MutableHandle<JSObject *> out) const override;
6662

6763
/**
68-
* @brief Run all jobs in the queue. Running one job may enqueue others; continue to
69-
* run jobs until the queue is empty.
64+
* @brief Pull every job SpiderMonkey has queued internally and forward each
65+
* one to the Python event-loop.
66+
*
67+
* SpiderMonkey no longer pushes promise jobs to the embedding as they are
68+
* created; it queues them and expects the embedder to drain them at microtask
69+
* checkpoints via js::RunJobs(cx) (jsfriendapi.h), which calls this method.
70+
* Every place PythonMonkey enters JS from Python must checkpoint afterwards,
71+
* or promises settled there never run their reactions.
7072
*
7173
* Calling this method at the wrong time can break the web. The HTML spec
7274
* indicates exactly when the job queue should be drained (in HTML jargon,
7375
* when it should "perform a microtask checkpoint"), and doing so at other
7476
* times can incompatibly change the semantics of programs that use promises
7577
* or other microtask-based features.
76-
*
77-
* This method is called only via AutoDebuggerJobQueueInterruption, used by
78-
* the Debugger API implementation to ensure that the debuggee's job queue is
79-
* protected from the debugger's own activity. See the comments on
80-
* AutoDebuggerJobQueueInterruption.
8178
*/
8279
void runJobs(JSContext *cx) override;
8380

8481
/**
85-
* @return true if the job queue is empty, false otherwise.
86-
*/
87-
bool empty() const override;
88-
89-
/**
90-
* @return true if the job queue stopped draining, which results in `empty()` being false after `runJobs()`.
82+
* @return true if the job queue stopped draining before it was empty.
9183
*/
9284
bool isDrainingStopped() const override;
9385

@@ -127,11 +119,31 @@ js::UniquePtr<JS::JobQueue::SavedJobQueue> saveJobQueue(JSContext *) override;
127119
* @brief The callback for dispatching an off-thread promise to the event loop
128120
* see https://hg.mozilla.org/releases/mozilla-esr102/file/tip/js/public/Promise.h#l580
129121
* https://hg.mozilla.org/releases/mozilla-esr102/file/tip/js/src/vm/OffThreadPromiseRuntimeState.cpp#l160
122+
*
123+
* Takes ownership of the Dispatchable (run via the public static
124+
* Dispatchable::Run, since Dispatchable::run() is protected).
125+
*
130126
* @param closure - closure, currently the javascript context
131-
* @param dispatchable - Pointer to the Dispatchable to be called
127+
* @param dispatchable - the Dispatchable to be called; ownership transferred to this callback
132128
* @return not shutting down
133129
*/
134-
static bool dispatchToEventLoop(void *closure, JS::Dispatchable *dispatchable);
130+
static bool dispatchToEventLoop(void *closure, js::UniquePtr<JS::Dispatchable> &&dispatchable);
131+
132+
/**
133+
* @brief The callback for dispatching an off-thread promise to the event
134+
* loop after a delay.
135+
*
136+
* Always declines (returns false), which js/public/Promise.h permits when the
137+
* embedding has no timeout manager. Only engine features needing a delayed
138+
* off-thread callback (e.g. Atomics.waitAsync timeouts) are affected;
139+
* setTimeout/setInterval use PyEventLoop::enqueueWithDelay instead.
140+
*
141+
* @param closure - closure, currently the javascript context
142+
* @param dispatchable - the Dispatchable that would be called; ownership transferred to this callback
143+
* @param delay - requested delay in milliseconds
144+
* @return false (no timeout manager available)
145+
*/
146+
static bool delayedDispatchToEventLoop(void *closure, js::UniquePtr<JS::Dispatchable> &&dispatchable, uint32_t delay);
135147

136148
/**
137149
* @brief The callback that gets invoked whenever a Promise is rejected without a rejection handler (uncaught/unhandled exception)

‎mozcentral.version‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6bca861985ba51920c1cacc21986af01c51bd690
1+
1704651e7d6c706fcb753adab577e0954d61cee0

‎peter-jr‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,39 @@ if ! realpath --relative-to=. . >/dev/null 2>&1; then
118118
}
119119
fi
120120

121+
# macOS has no `timeout` (GNU coreutils); use `gtimeout` if installed, otherwise
122+
# fall back to a small perl implementation. Supports `[-s SIG] [--foreground] DURATION CMD...`.
123+
if ! command -v timeout >/dev/null 2>&1; then
124+
if command -v gtimeout >/dev/null 2>&1; then
125+
timeout() { gtimeout "$@"; }
126+
else
127+
timeout()
128+
{
129+
local sig=15
130+
while [[ "${1:-}" == -* ]]; do
131+
case "$1" in
132+
-s) sig="$2"; shift 2;;
133+
-s*) sig="${1#-s}"; shift;;
134+
--foreground) shift;;
135+
*) shift;;
136+
esac
137+
done
138+
local secs="$1"
139+
shift
140+
perl -e '
141+
my ($secs, $sig) = (shift, shift);
142+
my $pid = fork();
143+
die "fork: $!" unless defined $pid;
144+
if (!$pid) { exec @ARGV or exit 127; }
145+
$SIG{ALRM} = sub { kill $sig, $pid; waitpid($pid, 0); exit 124; };
146+
alarm $secs;
147+
waitpid($pid, 0);
148+
exit(($? & 127) ? 128 + ($? & 127) : ($? >> 8));
149+
' "$secs" "$sig" "$@"
150+
}
151+
fi
152+
fi
153+
121154
findTests()
122155
{
123156
for loc in "${testLocations[@]}"

0 commit comments

Comments
 (0)