Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 72 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ jobs:
strategy:
fail-fast: false
matrix:
build: [release, debug, weval]
build: [release, debug, weval, nightmonkey]
os: [ubuntu-latest]
outputs:
SM_TAG_EXISTS: ${{ steps.check-sm-release.outputs.SM_TAG_EXISTS }}
SM_TAG: ${{ steps.check-sm-release.outputs.SM_TAG }}
SM_CACHE_KEY_debug: ${{ steps.check-sm-release.outputs.SM_CACHE_KEY_debug }}
SM_CACHE_KEY_release: ${{ steps.check-sm-release.outputs.SM_CACHE_KEY_release }}
SM_CACHE_KEY_weval: ${{ steps.check-sm-release.outputs.SM_CACHE_KEY_weval }}
SM_CACHE_KEY_nightmonkey: ${{ steps.check-sm-release.outputs.SM_CACHE_KEY_nightmonkey }}
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -73,8 +74,9 @@ jobs:
- name: Configure StarlingMonkey
run: |
cmake -S . -B cmake-build-${{ matrix.build }}\
-DCMAKE_BUILD_TYPE=${{ (matrix.build == 'release' || matrix.build == 'weval') && 'Release' || 'Debug' }}\
${{matrix.build == 'weval' && '-DUSE_WASM_OPT=OFF -DWEVAL=ON' || ''}}
-DCMAKE_BUILD_TYPE=${{ (matrix.build == 'release' || matrix.build == 'weval' || matrix.build == 'nightmonkey') && 'Release' || 'Debug' }}\
${{matrix.build == 'weval' && '-DUSE_WASM_OPT=OFF -DWEVAL=ON' || ''}}\
${{matrix.build == 'nightmonkey' && '-DNIGHTMONKEY=ON' || ''}}

- name: Build StarlingMonkey
run: |
Expand Down Expand Up @@ -102,7 +104,15 @@ jobs:
mkdir -p spidermonkey-dist-${{ matrix.build }}
cp -a cmake-build-${{ matrix.build }}/spidermonkey-obj/dist/libspidermonkey.a spidermonkey-dist-${{ matrix.build }}/
cp -aL cmake-build-${{ matrix.build }}/spidermonkey-obj/dist/include spidermonkey-dist-${{ matrix.build }}/
tree spidermonkey-dist-${{ matrix.build }}
if [ "${{ matrix.build }}" = "nightmonkey" ]; then
# The NightMonkey runtime is compiled against the engine's private
# headers and with the flags libjs was built with, which a
# --enable-external-compiler-hooks build exports alongside the
# public headers (see cmake/nightmonkey.cmake).
cp -aL cmake-build-${{ matrix.build }}/spidermonkey-obj/dist/include-private spidermonkey-dist-${{ matrix.build }}/
cp -aL cmake-build-${{ matrix.build }}/spidermonkey-obj/dist/system_wrappers spidermonkey-dist-${{ matrix.build }}/
fi
tree -L 2 spidermonkey-dist-${{ matrix.build }}

# Upload tarball as an artifact of the github action run, so the output
# can be inspected for pull requests.
Expand Down Expand Up @@ -153,13 +163,22 @@ jobs:
spidermonkey-dist-weval
key: ${{ needs.test.outputs.SM_CACHE_KEY_weval }}
fail-on-cache-miss: true
- name: Restore SpiderMonkey NightMonkey Cache
uses: actions/cache/restore@v4
id: sm-cache-nightmonkey
with:
path: |
spidermonkey-dist-nightmonkey
key: ${{ needs.test.outputs.SM_CACHE_KEY_nightmonkey }}
fail-on-cache-miss: true

- name: Create SpiderMonkey Tar Balls
run: |
mkdir -p release-artifacts
tar -a -cf release-artifacts/spidermonkey-static-debug.tar.gz spidermonkey-dist-debug/*
tar -a -cf release-artifacts/spidermonkey-static-release.tar.gz spidermonkey-dist-release/*
tar -a -cf release-artifacts/spidermonkey-static-release_weval.tar.gz spidermonkey-dist-weval/*
tar -a -cf release-artifacts/spidermonkey-static-release_nightmonkey.tar.gz spidermonkey-dist-nightmonkey/*
tree release-artifacts

- name: Do the Release
Expand All @@ -171,3 +190,52 @@ jobs:
stability or availability guarantees.
tag_name: ${{ needs.test.outputs.SM_TAG }}
files: release-artifacts/*

# The NightMonkey compiler is a host binary that transforms a wizened
# snapshot of the (NightMonkey-enabled) runtime.
nightmonkey-compilers:
name: NightMonkey compiler (${{ matrix.artifact }})
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
artifact: nightmonkey-x86_64-linux
binary: nightmonkey
- os: ubuntu-24.04-arm
artifact: nightmonkey-aarch64-linux
binary: nightmonkey
- os: macos-14
artifact: nightmonkey-aarch64-macos
binary: nightmonkey
- os: windows-2022
artifact: nightmonkey-x86_64-windows.exe
binary: nightmonkey.exe
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Read NightMonkey pins
id: nightmonkey
shell: bash
run: |
revision="$(awk '/^set\(NIGHTMONKEY_TAG / {gsub(/set\(NIGHTMONKEY_TAG |\)/, ""); print}' cmake/nightmonkey.cmake)"
engine="$(awk '/^set\(NIGHTMONKEY_ENGINE_VERSION / {gsub(/"/, "", $2); print $2}' cmake/nightmonkey.cmake)"
echo "revision=$revision" >> "$GITHUB_OUTPUT"
echo "engine=$engine" >> "$GITHUB_OUTPUT"
- uses: actions/checkout@v4
with:
repository: bytecodealliance/nightmonkey
ref: ${{ steps.nightmonkey.outputs.revision }}
path: nightmonkey
- name: Build compiler
shell: bash
run: |
cargo build --release -p nightmonkey --manifest-path nightmonkey/Cargo.toml \
--no-default-features --features "${{ steps.nightmonkey.outputs.engine }}"
compiler="nightmonkey/target/release/${{ matrix.binary }}"
"$compiler" --help
cp "$compiler" "${{ matrix.artifact }}"
- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.artifact }}
path: ${{ matrix.artifact }}
56 changes: 56 additions & 0 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ jobs:
just mode=release builddir=build-release build starling
just mode=relwithdebinfo builddir=build-debug build starling
just mode=weval builddir=build-weval build starling-ics.wevalcache
just mode=nightmonkey builddir=build-nightmonkey build starling

- name: Prepare Artifacts
run: |
Expand All @@ -64,6 +65,7 @@ jobs:
cp build-release/starling-raw.wasm release-artifacts/starling-raw.wasm
cp build-debug/starling-raw.wasm release-artifacts/starling-raw-debug.wasm
cp build-weval/starling-raw.wasm release-artifacts/starling-raw-weval.wasm
cp build-nightmonkey/starling-raw.wasm release-artifacts/starling-raw-nightmonkey.wasm

# Component-versions of the runtime
cp build-release/starling.wasm release-artifacts/starling.wasm
Expand All @@ -82,6 +84,60 @@ jobs:
tag_name: ${{ needs.release-please.outputs.tag_name }}
files: release-artifacts/*

# The NightMonkey compiler for each supported host, built as in the CI
# workflow (see the nightmonkey-compilers job in main.yml) and uploaded next
# to the starling-raw-nightmonkey.wasm runtime it belongs to.
build-nightmonkey-compilers:
needs: release-please
if: ${{ needs.release-please.outputs.release_created }}
permissions:
contents: write
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
artifact: nightmonkey-x86_64-linux
binary: nightmonkey
- os: ubuntu-24.04-arm
artifact: nightmonkey-aarch64-linux
binary: nightmonkey
- os: macos-14
artifact: nightmonkey-aarch64-macos
binary: nightmonkey
- os: windows-2022
artifact: nightmonkey-x86_64-windows.exe
binary: nightmonkey.exe
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Read NightMonkey pins
id: nightmonkey
shell: bash
run: |
revision="$(awk '/^set\(NIGHTMONKEY_TAG / {gsub(/set\(NIGHTMONKEY_TAG |\)/, ""); print}' cmake/nightmonkey.cmake)"
engine="$(awk '/^set\(NIGHTMONKEY_ENGINE_VERSION / {gsub(/"/, "", $2); print $2}' cmake/nightmonkey.cmake)"
echo "revision=$revision" >> "$GITHUB_OUTPUT"
echo "engine=$engine" >> "$GITHUB_OUTPUT"
- uses: actions/checkout@v4
with:
repository: bytecodealliance/nightmonkey
ref: ${{ steps.nightmonkey.outputs.revision }}
path: nightmonkey
- name: Build compiler
shell: bash
run: |
cargo build --release -p nightmonkey --manifest-path nightmonkey/Cargo.toml \
--no-default-features --features "${{ steps.nightmonkey.outputs.engine }}"
compiler="nightmonkey/target/release/${{ matrix.binary }}"
"$compiler" --help
cp "$compiler" "${{ matrix.artifact }}"
- name: Upload Release Asset
uses: softprops/action-gh-release@72f2c25fcb47643c292f7107632f7a47c1df5cd8 #2.3.2
with:
tag_name: ${{ needs.release-please.outputs.tag_name }}
files: ${{ matrix.artifact }}

publish-extension:
needs: release-please
if: ${{ needs.release-please.outputs.debugger_release_created }}
Expand Down
9 changes: 8 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ include("wasmtime")
include("cbindgen")

include("spidermonkey")
include("nightmonkey")
include("openssl")
include("${HOST_API}/host_api.cmake")
include("build-crates")
Expand All @@ -49,7 +50,7 @@ add_library(extension_api INTERFACE include/extension-api.h runtime/encode.h run
if (ENABLE_JS_DEBUGGER)
target_compile_definitions(extension_api INTERFACE ENABLE_JS_DEBUGGER)
endif()
target_link_libraries(extension_api INTERFACE rust-url spidermonkey)
target_link_libraries(extension_api INTERFACE rust-url spidermonkey nightmonkey)
target_include_directories(extension_api INTERFACE include deps/include runtime)

include("builtins")
Expand Down Expand Up @@ -121,6 +122,12 @@ else()
set(AOT 0)
endif()

if(NIGHTMONKEY)
set(NIGHTMONKEY_AOT 1)
else()
set(NIGHTMONKEY_AOT 0)
endif()

set(RUNTIME_FILE "starling-raw.wasm")
set(ADAPTER_FILE "preview1-adapter.wasm")
configure_file("componentize.sh.in" "${CMAKE_CURRENT_BINARY_DIR}/componentize.sh" @ONLY)
Expand Down
8 changes: 8 additions & 0 deletions builtins/web/fetch/fetch_event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
#include <allocator.h>
#include <debugger.h>
#include <js/SourceText.h>
#ifdef ENABLE_JS_NIGHTMONKEY
# include "runtime/NightRegistration.h"
#endif

#include <iostream>
#include <memory>
Expand Down Expand Up @@ -493,6 +496,11 @@ static void dispatch_fetch_event(HandleObject event, double *total_compute) {
}

bool handle_incoming_request(host_api::HttpIncomingRequest *request) {
#ifdef ENABLE_JS_NIGHTMONKEY
if (!JS::NightActivate(ENGINE->cx())) {
return false;
}
#endif
#ifdef DEBUG
std::println(stderr, "Warning: Using a DEBUG build. Expect things to be SLOW.");
#endif
Expand Down
Loading
Loading