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
61 changes: 58 additions & 3 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 @@ -153,13 +155,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 +182,47 @@ jobs:
stability or availability guarantees.
tag_name: ${{ needs.test.outputs.SM_TAG }}
files: release-artifacts/*

nightmonkey-compilers:
name: NightMonkey compiler (${{ matrix.artifact }})
needs: test
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 Firefox revision
id: firefox-revision
shell: bash
run: |
revision="$(awk '/^set\(SM_TAG / {gsub(/set\(SM_TAG |\)/, ""); print}' cmake/spidermonkey.cmake)"
echo "revision=$revision" >> "$GITHUB_OUTPUT"
- uses: actions/checkout@v4
with:
repository: bytecodealliance/firefox
ref: ${{ steps.firefox-revision.outputs.revision }}
path: firefox
- name: Build compiler
run: |
cargo build --release --manifest-path firefox/js/src/night/nightmonkey/Cargo.toml
compiler="firefox/js/src/night/nightmonkey/target/release/${{ matrix.binary }}"
"$compiler" --help
cp "$compiler" "${{ matrix.artifact }}"
- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.artifact }}
path: ${{ matrix.artifact }}
50 changes: 50 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 @@ -72,6 +74,7 @@ jobs:
# Supporting artifacts
cp build-release/preview1-adapter.wasm release-artifacts
cp build-weval/starling-ics.wevalcache release-artifacts
cp build-nightmonkey/componentize.sh release-artifacts

echo "Release artifacts:"
ls -la release-artifacts/
Expand All @@ -82,6 +85,53 @@ jobs:
tag_name: ${{ needs.release-please.outputs.tag_name }}
files: release-artifacts/*

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 Firefox revision
id: firefox-revision
shell: bash
run: |
revision="$(awk '/^set\(SM_TAG / {gsub(/set\(SM_TAG |\)/, ""); print}' cmake/spidermonkey.cmake)"
echo "revision=$revision" >> "$GITHUB_OUTPUT"
- uses: actions/checkout@v4
with:
repository: bytecodealliance/firefox
ref: ${{ steps.firefox-revision.outputs.revision }}
path: firefox
- name: Build compiler
run: |
cargo build --release --manifest-path firefox/js/src/night/nightmonkey/Cargo.toml
compiler="firefox/js/src/night/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
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,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 <js/NightMonkey.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
41 changes: 30 additions & 11 deletions cmake/spidermonkey.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
set(SM_TAG FIREFOX_147_0_4_RELEASE_STARLING)
set(SM_TAG 9f1a4ce9a631039e6898985d842afaf16cebc89e)
set(SM_REPO_URL https://github.com/bytecodealliance/firefox.git)

include("manage-git-source")

Expand All @@ -9,9 +10,16 @@ else()
endif()

option(WEVAL "Build with a SpiderMonkey variant that supports weval-based AOT compilation" OFF)
option(NIGHTMONKEY "Build with NightMonkey AOT compilation support" OFF)

if (WEVAL AND NIGHTMONKEY)
message(FATAL_ERROR "WEVAL and NIGHTMONKEY cannot be enabled together")
endif()

if (WEVAL)
set(SM_BUILD_TYPE "${SM_BUILD_TYPE}_weval")
elseif (NIGHTMONKEY)
set(SM_BUILD_TYPE "${SM_BUILD_TYPE}_nightmonkey")
endif()

# If the developer has specified an alternate local set of SpiderMonkey
Expand Down Expand Up @@ -53,16 +61,20 @@ if (DEFINED SM_LIB_DIR)
target_include_directories(spidermonkey INTERFACE ${SM_INCLUDE_DIR})
target_link_libraries(spidermonkey INTERFACE ${SM_LIB_DIR}/libspidermonkey.a)
else()
# Clone SpiderMonkey source using git directly for shallow clone
# Use deps folder in project root for shared access across build directories
set(SM_SOURCE_DIR ${CMAKE_SOURCE_DIR}/deps/spidermonkey-source)

manage_git_source(
NAME spidermonkey
REPO_URL https://github.com/bytecodealliance/firefox.git
TAG ${SM_TAG}
SOURCE_DIR ${SM_SOURCE_DIR}
)
set(SM_SOURCE_DIR "${CMAKE_SOURCE_DIR}/deps/spidermonkey-source" CACHE PATH
"Path to a local Firefox source checkout")
if (SM_SOURCE_DIR STREQUAL "${CMAKE_SOURCE_DIR}/deps/spidermonkey-source")
manage_git_source(
NAME spidermonkey
REPO_URL ${SM_REPO_URL}
TAG ${SM_TAG}
SOURCE_DIR ${SM_SOURCE_DIR}
)
elseif (NOT EXISTS "${SM_SOURCE_DIR}/mach")
message(FATAL_ERROR "SM_SOURCE_DIR does not contain a Firefox checkout: ${SM_SOURCE_DIR}")
else()
message(STATUS "Using SpiderMonkey source from ${SM_SOURCE_DIR}")
endif()

# Each build configuration gets its own object directory
set(SM_OBJ_DIR ${CMAKE_CURRENT_BINARY_DIR}/spidermonkey-obj)
Expand Down Expand Up @@ -151,6 +163,8 @@ mk_add_options AUTOCLOBBER=1
string(APPEND MOZCONFIG_CONTENT "ac_add_options --enable-aot-ics\n")
string(APPEND MOZCONFIG_CONTENT "ac_add_options --enable-aot-ics-force\n")
string(APPEND MOZCONFIG_CONTENT "ac_add_options --enable-pbl-weval\n")
elseif(NIGHTMONKEY)
string(APPEND MOZCONFIG_CONTENT "ac_add_options --enable-nightmonkey\n")
endif()

file(GENERATE OUTPUT ${MOZCONFIG} CONTENT "${MOZCONFIG_CONTENT}")
Expand Down Expand Up @@ -188,6 +202,11 @@ mk_add_options AUTOCLOBBER=1
)
add_custom_target(spidermonkey_build DEPENDS ${LIB_SM})

if(NIGHTMONKEY)
set(NIGHTMONKEY_BIN "${SM_OBJ_DIR}/dist/host/bin/nightmonkey" CACHE FILEPATH
"Path to the NightMonkey compiler" FORCE)
endif()

add_library(spidermonkey INTERFACE)
add_dependencies(spidermonkey spidermonkey_build)
target_include_directories(spidermonkey INTERFACE ${SM_INCLUDE_DIR})
Expand Down
Loading
Loading