Skip to content

Commit 84b2d5f

Browse files
chore(build): Move WPT support build-time to runtime config (#257)
Instead of requiring a CMake build config option to enable WPT support, with this change that's moved to the new `--wpt-mode` runtime flag.
1 parent 0cc1181 commit 84b2d5f

File tree

11 files changed

+50
-60
lines changed

11 files changed

+50
-60
lines changed

.github/workflows/main.yml

Lines changed: 11 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
strategy:
2525
fail-fast: false
2626
matrix:
27-
build: [release, weval]
27+
build: [release, debug, weval]
2828
os: [ubuntu-latest]
2929
runs-on: ${{ matrix.os }}
3030
steps:
@@ -39,55 +39,28 @@ jobs:
3939
with:
4040
node-version: 'lts/*'
4141

42-
- name: Build StarlingMonkey
42+
- name: Configure StarlingMonkey
4343
run: |
4444
cmake -S . -B cmake-build-${{ matrix.build }}\
4545
-DCMAKE_BUILD_TYPE=${{ (matrix.build == 'release' || matrix.build == 'weval') && 'Release' || 'Debug' }}\
4646
${{matrix.build == 'weval' && '-DUSE_WASM_OPT=OFF -DWEVAL=ON' || ''}}
47-
cmake --build cmake-build-${{ matrix.build }} --parallel 4 --target all integration-test-server
48-
49-
- name: StarlingMonkey E2E & Integration Tests
50-
run: |
51-
CTEST_OUTPUT_ON_FAILURE=1 ctest --test-dir cmake-build-${{ matrix.build }} -j4
52-
53-
wpt:
54-
name: Web Platform Tests
55-
strategy:
56-
matrix:
57-
build: [release, debug, weval]
58-
runs-on: ubuntu-latest
59-
steps:
60-
- uses: actions/checkout@v2
61-
with:
62-
submodules: recursive
6347
64-
- name: Install Rust 1.80.0
48+
- name: Build StarlingMonkey
6549
run: |
66-
rustup toolchain install 1.80.0
67-
rustup target add wasm32-wasip1 --toolchain 1.80.0
50+
cmake --build cmake-build-${{ matrix.build }} --parallel $(nproc) --target all
6851
69-
- uses: actions/setup-node@v2
70-
with:
71-
node-version: 'lts/*'
72-
73-
- name: Build StarlingMonkey WPT
74-
if: matrix.build != 'weval'
52+
- name: Build Integration Test Server
7553
run: |
76-
cmake -S . -B cmake-build-${{ matrix.build }} -DENABLE_WPT:BOOL=ON -DCMAKE_BUILD_TYPE=${{ matrix.build == 'release' && 'Release' || 'Debug' }}
77-
cmake --build cmake-build-${{ matrix.build }} --parallel 4 --target wpt-runtime
54+
cmake --build cmake-build-${{ matrix.build }} --parallel $(nproc) --target integration-test-server
7855
79-
- name: Build StarlingMonkey WPT Weval
80-
if: matrix.build == 'weval'
56+
- name: Build WPT Runtime
8157
run: |
82-
cmake -S . -B cmake-build-weval -DCMAKE_BUILD_TYPE=Release -DUSE_WASM_OPT=OFF -DWEVAL=ON -DENABLE_WPT:BOOL=ON
83-
cmake --build cmake-build-weval --parallel 4 --target starling-ics.wevalcache
84-
cmake --build cmake-build-weval --parallel 4 --target wpt-runtime
58+
cmake --build cmake-build-${{ matrix.build }} --parallel $(nproc) --target wpt-runtime
8559
8660
- name: Prepare WPT hosts
8761
run: |
8862
cat deps/wpt-hosts | sudo tee -a /etc/hosts
8963
90-
- name: StarlingMonkey WPT Test
91-
env:
92-
CTEST_OUTPUT_ON_FAILURE: 1
93-
run: ctest -R wpt --test-dir cmake-build-${{ matrix.build }} --verbose --no-tests=error
64+
- name: StarlingMonkey E2E, Integration, and WPT Tests
65+
run: |
66+
CTEST_OUTPUT_ON_FAILURE=1 ctest --test-dir cmake-build-${{ matrix.build }} -j$(nproc) --verbose

CMakeLists.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,7 @@ target_include_directories(extension_api INTERFACE include deps/include runtime)
5050

5151
include("builtins")
5252

53-
option(ENABLE_WPT "Enable WPT harness support" OFF)
54-
if (ENABLE_WPT)
55-
include("tests/wpt-harness/wpt.cmake")
56-
endif()
53+
include("tests/wpt-harness/wpt.cmake")
5754

5855
set(SOURCES
5956
runtime/js.cpp

componentize.sh.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ usage() {
1616
echo " Specifying '-i' or '--initializer-script-path' allows specifying an initializer script"
1717
echo " Specifying '--strip-path-prefix' will cause the provided prefix to be stripped from paths in stack traces and the debugger"
1818
echo " Specifying '--legacy-script' causes evaluation as a legacy JS script instead of a module"
19+
echo " Specifying '--wpt-mode' enables WPT compatibility mode"
1920
exit 1
2021
}
2122

@@ -50,6 +51,10 @@ do
5051
STARLING_ARGS="$STARLING_ARGS $1 $2"
5152
shift 2
5253
;;
54+
--wpt-mode)
55+
STARLING_ARGS="$STARLING_ARGS $1 $2"
56+
shift 2
57+
;;
5358
-v|--verbose)
5459
STARLING_ARGS="$1 $STARLING_ARGS"
5560
VERBOSE=1

docs/src/getting-started/testing.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ cmake --build cmake-build-debug --target integration-test-server
1111
Then tests can be run with `ctest` directly via:
1212

1313
```console
14-
ctest --test-dir cmake-build-debug -j8 --output-on-failure
14+
ctest --test-dir cmake-build-debug -j$(nproc) --output-on-failure
1515
```
1616

1717
Alternatively, the integration test server can be directly run with `wasmtime serve` via:
@@ -25,12 +25,11 @@ Then visit `http://0.0.0.0:8080/timers`, or any test name and filter of the form
2525
## Web Platform Tests
2626

2727
To run the [Web Platform Tests](https://web-platform-tests.org/) suite, the WPT runner requires
28-
`Node.js` above v18.0 to be installed, and during build configuration the option `ENABLE_WPT:BOOL=ON`
29-
must be set.
28+
`Node.js` above v18.0 to be installed, and the list of hosts in `deps/wpt-hosts` needs to be added to `etc/hosts`.
3029

3130
```console
32-
cmake -S . -B cmake-build-debug -DENABLE_WPT:BOOL=ON -DCMAKE_BUILD_TYPE=Debug
33-
cmake --build cmake-build-debug --parallel 8 --target wpt-runtime
31+
cmake -S . -B cmake-build-debug -DCMAKE_BUILD_TYPE=Debug
32+
cmake --build cmake-build-debug --parallel $(nproc) --target wpt-runtime
3433
cat deps/wpt-hosts | sudo tee -a /etc/hosts # Required to resolve test server hostnames
3534
cd cmake-build-debug
3635
ctest -R wpt --verbose # Note: some of the tests run fairly slowly in debug builds, so be patient

include/config-parser.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ class ConfigParser {
9797
config_->content_script_path = mozilla::Some(args[i + 1]);
9898
i++;
9999
}
100+
} else if (args[i] == "--wpt-mode") {
101+
config_->wpt_mode = true;
100102
} else if (args[i].starts_with("--")) {
101103
std::cerr << "Unknown option: " << args[i] << std::endl;
102104
exit(1);

include/extension-api.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ struct EngineConfig {
6565
*/
6666
bool debugging = false;
6767

68+
/**
69+
* Whether to enable Web Platform Test mode. Specifically, this means installing a
70+
* few global properties required to make WPT work, that wouldn't be made available
71+
* to content.
72+
*/
73+
bool wpt_mode = false;
74+
6875
EngineConfig() = default;
6976
};
7077

@@ -82,6 +89,7 @@ class Engine {
8289
HandleObject global();
8390
EngineState state();
8491
bool debugging_enabled();
92+
bool wpt_mode();
8593

8694
void finish_pre_initialization();
8795

justfile

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,26 +58,22 @@ format *ARGS:
5858
{{ justdir }}/scripts/clang-format.sh {{ ARGS }}
5959

6060
# Run integration test
61-
test regex="": (build "integration-test-server")
61+
test regex="": (build "integration-test-server") (build "wpt-runtime")
6262
ctest --test-dir {{ builddir }} -j {{ ncpus }} --output-on-failure {{ if regex == "" { regex } else { "-R " + regex } }}
6363

64-
# Build web platform test suite
65-
[group('wpt')]
66-
wpt-build: (build "wpt-runtime" "-DENABLE_WPT:BOOL=ON")
67-
6864
# Run web platform test suite
6965
[group('wpt')]
70-
wpt-test filter="": wpt-build
66+
wpt-test filter="": (build "wpt-runtime")
7167
WPT_FILTER={{ filter }} ctest --test-dir {{ builddir }} -R wpt --verbose
7268

7369
# Update web platform test expectations
7470
[group('wpt')]
75-
wpt-update filter="": wpt-build
71+
wpt-update filter="": (build "wpt-runtime")
7672
WPT_FLAGS="--update-expectations" WPT_FILTER={{ filter }} ctest --test-dir {{ builddir }} -R wpt --verbose
7773

7874
# Run wpt server
7975
[group('wpt')]
80-
wpt-server: wpt-build
76+
wpt-server: (build "wpt-runtime")
8177
#!/usr/bin/env bash
8278
set -euo pipefail
8379
cd {{ builddir }}

runtime/engine.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,7 @@ EngineState Engine::state() { return state_; }
518518
bool Engine::debugging_enabled() {
519519
return config_->debugging;
520520
}
521+
bool Engine::wpt_mode() { return config_->wpt_mode; }
521522

522523
void Engine::finish_pre_initialization() {
523524
MOZ_ASSERT(state_ == EngineState::ScriptPreInitializing);

tests/wpt-harness/build-wpt-runtime.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ inputs=(
1818
)
1919

2020
cat "${inputs[@]}" > wpt-test-runner.js
21-
./componentize.sh $componentize_flags --verbose --legacy-script wpt-test-runner.js wpt-runtime.wasm
21+
./componentize.sh $componentize_flags --verbose --wpt-mode --legacy-script wpt-test-runner.js wpt-runtime.wasm

tests/wpt-harness/run-wpt.mjs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,10 @@ async function timeout(millis, message) {
312312

313313
async function wasmtimeReady(wasmtime, config) {
314314
// Wait until Wasmtime has fully initialized and extract host from output.
315+
let output = "";
315316
for await(const [chunk] of on(wasmtime.stderr, "data")) {
316-
let result = chunk.match(/Serving HTTP on (.+)/);
317+
output += chunk;
318+
let result = output.match(/Serving HTTP on (http:\/\/.+\/)/);
317319
if (result) {
318320
return { process: wasmtime, host: result[1], ...config };
319321
}
@@ -333,6 +335,9 @@ async function startWasmtime(runtime, addr, logLevel) {
333335
let backtrace = "";
334336
let backtrace_re = /Error \{\s+context: "error while executing at wasm backtrace:(.+?)",\s+source: (.+?)/s;
335337
wasmtime.stderr.on("data", data => {
338+
if (logLevel >= LogLevel.VeryVerbose) {
339+
console.log(`wasmtime stderr: ${stripTrailingNewline(data)}`);
340+
}
336341
if (backtrace.length > 0 || data.includes("error while executing at wasm backtrace:")) {
337342
backtrace += data;
338343
let match = backtrace.match(backtrace_re);
@@ -353,11 +358,11 @@ async function startWasmtime(runtime, addr, logLevel) {
353358
});
354359
}
355360

356-
// give wasmtime 20 seconds to become available
357-
const WASMTIME_READY_TIMEOUT = 20000;
361+
// give wasmtime 60 seconds to become available
362+
const WASMTIME_READY_TIMEOUT = 60000;
358363
return await Promise.race([
359364
wasmtimeReady(wasmtime, config),
360-
timeout(WASMTIME_READY_TIMEOUT, "Wasmtime failed to start"),
365+
timeout(WASMTIME_READY_TIMEOUT, `Wasmtime start timeout after ${WASMTIME_READY_TIMEOUT}ms`),
361366
]);
362367
}
363368

0 commit comments

Comments
 (0)