Skip to content

Commit

Permalink
more reworking
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed Feb 22, 2025
1 parent eaf5364 commit 437ab8c
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 99 deletions.
95 changes: 23 additions & 72 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,6 @@ jobs:

build-splicer:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node-version:
- '22.11.0'
# - latest reenable when https://github.com/nodejs/node/issues/57172 is fixed
steps:
- uses: actions/checkout@v4

Expand All @@ -51,7 +45,7 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version: ${{matrix.node-version}}
node-version: '22'

- name: Install NPM packages
run: npm install
Expand All @@ -60,7 +54,7 @@ jobs:
uses: actions/cache@v4
id: splicer-build
with:
key: splicer-node-${{matrix.node-version}}-${{ hashFiles('Cargo.lock', 'crates/spidermonkey-embedding-splicer/src/**/*.rs') }}
key: splicer-${{ hashFiles('Cargo.lock', 'crates/spidermonkey-embedding-splicer/src/**/*.rs') }}
path: |
lib/spidermonkey-embedding-splicer.core2.wasm
lib/spidermonkey-embedding-splicer.core.wasm
Expand All @@ -69,19 +63,19 @@ jobs:
- name: Build splicer
if: steps.splicer-build.outputs.cache-hit != 'true'
run: |
make lib/spidermonkey-embedding-splicer.js
run: make lib/spidermonkey-embedding-splicer.js

build-jit:
build:
runs-on: ubuntu-latest
needs:
- build-splicer
strategy:
fail-fast: false
matrix:
node-version:
- '22'
- latest
build-type:
- 'release'
- 'debug'
- 'weval'
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -104,87 +98,44 @@ jobs:
uses: actions/cache/restore@v4
id: splicer-build
with:
key: splicer-node-${{matrix.node-version}}-${{ hashFiles('Cargo.lock', 'crates/spidermonkey-embedding-splicer/src/**/*.rs') }}
key: splicer-${{ hashFiles('Cargo.lock', 'crates/spidermonkey-embedding-splicer/src/**/*.rs') }}
path: lib

- uses: actions/setup-node@v4
with:
node-version: ${{matrix.node-version}}
node-version: '22'

- name: Install NPM packages
run: npm install

- name: Build ComponentizeJS
run: |
npm run clean
npm run build:debug
npm run build:release
- uses: actions/upload-artifact@v4
with:
name: starlingmonkey-jit-node-${{matrix.node-version}}-${{ steps.starlingmonkey-commit.outputs.STARLINGMONKEY_HASH }}
if-no-files-found: 'error'
path: lib

build-aot:
runs-on: ubuntu-latest
needs:
- build-splicer
strategy:
fail-fast: false
matrix:
node-version:
- '22'
- latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Get StarlingMonkey Commit
id: starlingmonkey-commit
run: echo "STARLINGMONKEY_HASH=$(git submodule status | head -c9 | tail -c8)" >> "$GITHUB_OUTPUT"

- name: Install Rust Toolchain
run: |
rustup toolchain install 1.77.1
rustup target add wasm32-wasi --toolchain 1.77.1
rustup target add wasm32-wasip1
- name: Install wasm-tools
run: cargo install wasm-tools

- uses: actions/setup-node@v4
with:
node-version: ${{matrix.node-version}}

- name: Install NPM packages
run: npm install

- name: Build Weval
run: |
npm run clean
npm run build:weval
npm run build:${{matrix.build-type}}
- uses: actions/cache/save@v4
with:
key: starlingmonkey-aot-node-${{matrix.node-version}}-${{ steps.starlingmonkey-commit.outputs.STARLINGMONKEY_HASH }}
key: starlingmonkey-${{matrix.build-type}}-${{ steps.starlingmonkey-commit.outputs.STARLINGMONKEY_HASH }}
path: lib

########
# Test #
########

test-jit:
test:
runs-on: ubuntu-latest
needs:
- build-jit
- build
strategy:
fail-fast: false
matrix:
node-version:
- '22'
- latest
# - latest reenable when https://github.com/nodejs/node/issues/57172 is fixed
build-type:
- 'release'
- 'debug'
- 'weval'
steps:
- uses: actions/checkout@v4

Expand All @@ -196,7 +147,7 @@ jobs:
uses: actions/cache/restore@v4
id: restore-starlingmonkey-jit-build
with:
key: starlingmonkey-jit-node-${{matrix.node-version}}-${{ steps.starlingmonkey-commit.outputs.STARLINGMONKEY_HASH }}
key: starlingmonkey-${{matrix-build-type}}-${{ steps.starlingmonkey-commit.outputs.STARLINGMONKEY_HASH }}
path: lib

- uses: actions/setup-node@v4
Expand All @@ -207,10 +158,10 @@ jobs:
run: npm install

- name: Test
run: npm run test
run: npm run test:${{matrix.build-type}}

- name: Cache Example build
uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a # 4.1.2
uses: actions/cache@v4
with:
path: example/target
key: example-jit-cargo-${{ hashFiles('example/src/main.rs', 'example/Cargo.lock', 'example/hello.wit') }}
Expand All @@ -222,7 +173,7 @@ jobs:
test-aot:
runs-on: ubuntu-latest
needs:
- build-aot
- build
strategy:
fail-fast: false
matrix:
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"build:debug": "make debug",
"test": "mocha -u tdd test/test.js --timeout 120000",
"test:weval": "WEVAL_TEST=1 mocha -u tdd test/test.js --timeout 120000",
"test:debug": "DEBUG_TEST=1 mocha -u tdd test/test.js --timeout 120000",
"prepublishOnly": "npm run build"
},
"files": [
Expand Down
68 changes: 41 additions & 27 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import { strictEqual } from 'node:assert';
const DEBUG_TRACING = false;
const LOG_DEBUGGING = false;

const enableAot = process.env.WEVAL_TEST == '1';
const debugBuild = process.env.DEBUG_TEST == '1';

function maybeLogging(disableFeatures) {
if (!LOG_DEBUGGING) return disableFeatures;
if (disableFeatures && disableFeatures.includes('stdio')) {
Expand All @@ -18,16 +21,14 @@ function maybeLogging(disableFeatures) {

const builtinsCases = await readdir(new URL('./builtins', import.meta.url));
suite('Builtins', () => {
const enableAot = process.env.WEVAL_TEST == '1'

for (const filename of builtinsCases) {
const name = filename.slice(0, -3);
test(name, async () => {
const {
source,
test: runTest,
disableFeatures,
enableFeatures
enableFeatures,
} = await import(`./builtins/${filename}`);

const { component } = await componentize(
Expand All @@ -41,14 +42,18 @@ suite('Builtins', () => {
{
sourceName: `${name}.js`,
// also test the debug build while we are about it (unless testing Weval)
debugBuild: !enableAot,
debugBuild,
enableFeatures,
disableFeatures: maybeLogging(disableFeatures),
enableAot
enableAot,
}
);

const { files } = await transpile(component, { name, wasiShim: true, tracing: DEBUG_TRACING });
const { files } = await transpile(component, {
name,
wasiShim: true,
tracing: DEBUG_TRACING,
});

await mkdir(new URL(`./output/${name}/interfaces`, import.meta.url), {
recursive: true,
Expand Down Expand Up @@ -101,23 +106,26 @@ suite('Builtins', () => {
code === 0 ? resolve() : reject(new Error(stderr || stdout))
);
timeout = setTimeout(() => {
reject(new Error("test timed out with output:\n" + stdout + '\n\nstderr:\n' + stderr));
reject(
new Error(
'test timed out with output:\n' +
stdout +
'\n\nstderr:\n' +
stderr
)
);
}, 10_000);
});
}
catch (err) {
} catch (err) {
throw { err, stdout, stderr };
}
finally {
} finally {
clearTimeout(timeout);
}

return { stdout, stderr };
});
}
catch (err) {
if (err.stderr)
console.error(err.stderr);
} catch (err) {
if (err.stderr) console.error(err.stderr);
throw err.err || err;
}
});
Expand All @@ -126,16 +134,17 @@ suite('Builtins', () => {

const bindingsCases = await readdir(new URL('./cases', import.meta.url));
suite('Bindings', () => {
const enableAot = process.env.WEVAL_TEST == '1'

for (const name of bindingsCases) {
test(name, async () => {
const source = await readFile(
new URL(`./cases/${name}/source.js`, import.meta.url),
'utf8'
);

let witWorld, witPath, worldName, isWasiTarget = false;
let witWorld,
witPath,
worldName,
isWasiTarget = false;
try {
witWorld = await readFile(
new URL(`./cases/${name}/world.wit`, import.meta.url),
Expand Down Expand Up @@ -165,7 +174,9 @@ suite('Bindings', () => {
const test = await import(`./cases/${name}/test.js`);

const enableFeatures = test.enableFeatures || ['http'];
const disableFeatures = test.disableFeatures || (isWasiTarget ? [] : ['random', 'clocks', 'http', 'stdio']);
const disableFeatures =
test.disableFeatures ||
(isWasiTarget ? [] : ['random', 'clocks', 'http', 'stdio']);

let testArg;
try {
Expand All @@ -176,7 +187,8 @@ suite('Bindings', () => {
worldName,
enableFeatures,
disableFeatures: maybeLogging(disableFeatures),
enableAot
enableAot,
debugBuild,
});
const map = {
'wasi:cli-base/*': '@bytecodealliance/preview2-shim/cli-base#*',
Expand All @@ -191,19 +203,22 @@ suite('Bindings', () => {
};
for (let [impt] of imports) {
if (impt.startsWith('wasi:')) continue;
if (impt.startsWith('['))
impt = impt.slice(impt.indexOf(']') + 1);
if (impt.startsWith('[')) impt = impt.slice(impt.indexOf(']') + 1);
let importName = impt.split('/').pop();
if (importName === 'test') importName = 'imports';
map[impt] = `../../cases/${name}/${importName}.js`;
}

const { files, imports: componentImports, exports: componentExports } = await transpile(component, {
const {
files,
imports: componentImports,
exports: componentExports,
} = await transpile(component, {
name,
map,
wasiShim: true,
validLiftingOptimization: false,
tracing: DEBUG_TRACING
tracing: DEBUG_TRACING,
});

testArg = { imports, componentImports, componentExports };
Expand Down Expand Up @@ -240,8 +255,6 @@ suite('Bindings', () => {

suite('WASI', () => {
test('basic app', async () => {
const enableAot = process.env.WEVAL_TEST == '1'

const { component } = await componentize(
`
import { now } from 'wasi:clocks/[email protected]';
Expand All @@ -259,7 +272,8 @@ suite('WASI', () => {
{
witPath: fileURLToPath(new URL('./wit', import.meta.url)),
worldName: 'test1',
enableAot
enableAot,
debugBuild,
}
);

Expand Down

0 comments on commit 437ab8c

Please sign in to comment.