Skip to content
Merged
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
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ jobs:
key: guest-bundle-${{ steps.guest-keys.outputs.guest-key }}
- name: Install clang
run: sudo apt-get update && sudo apt-get install -y clang
- name: Test JavaScript guest build
run: just wasm js-guest-test
- name: Build guests
run: just wasm guest-bundle
- name: Upload guest bundle
Expand Down
2 changes: 1 addition & 1 deletion Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fmt-check-rust:

#### TESTS ####

test: wasm::test-build wasm::guest-build wasm::js-guest-build python::build python::python-test test-rust wasm::test dotnet::test-rust dotnet::test
test: wasm::test-build wasm::js-guest-test wasm::guest-build wasm::js-guest-build python::build python::python-test test-rust wasm::test dotnet::test-rust dotnet::test

fuzz seconds="60": (python::python-fuzz seconds)

Expand Down
5 changes: 5 additions & 0 deletions src/wasm_sandbox/Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ js-guest-build: js-guest-build-wasm js-guest-build-aot
js-guest-install:
uv run --no-project --python 3.14 python {{repo-root}}/scripts/guest_build.py javascript

# Test componentization against the installed JavaScript dependencies.
js-guest-test:
cd {{repo-root}}/src/wasm_sandbox/guests/javascript && npm ci
cd {{repo-root}}/src/wasm_sandbox/guests/javascript && npm test

build target=default-target: _clean-stale-wasm (guest-build target) (js-guest-build)
cargo build --manifest-path {{repo-root}}/src/wasm_sandbox/Cargo.toml --profile={{ if target == "debug" {"dev"} else { target } }}

Expand Down
3 changes: 2 additions & 1 deletion src/wasm_sandbox/guests/javascript/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ const outputPath = "js-sandbox.wasm";
async function build() {
console.log("Reading source...");
const source = await readFile(sourcePath, "utf-8");
const witWorld = await readFile(witPath, "utf-8");

console.log("Componentizing...");
const { component, imports } = await componentize(source, {
witPath,
witWorld,
worldName: "hyperlight:sandbox/sandbox",
});

Expand Down
15 changes: 15 additions & 0 deletions src/wasm_sandbox/guests/javascript/build.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import assert from "node:assert/strict";
import { execFile } from "node:child_process";
import { readFile } from "node:fs/promises";
import { promisify } from "node:util";
import { test } from "node:test";

test("builds the JavaScript component with the installed WASI shim", async () => {
const cwd = new URL(".", import.meta.url);
await promisify(execFile)(process.execPath, ["build.js"], {
cwd,
timeout: 120_000,
});
const component = await readFile(new URL("js-sandbox.wasm", cwd));
assert.deepEqual(component.subarray(0, 8), Buffer.from([0, 97, 115, 109, 13, 0, 1, 0]));
});
8 changes: 4 additions & 4 deletions src/wasm_sandbox/guests/javascript/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions src/wasm_sandbox/guests/javascript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
"private": true,
"type": "module",
"scripts": {
"build": "node build.js"
"build": "node build.js",
"test": "node --test build.test.js"
},
"devDependencies": {
"@bytecodealliance/componentize-js": "^0.23.0",
"@bytecodealliance/jco": "^1.39.0",
"@bytecodealliance/preview2-shim": "^0.25.0"
"@bytecodealliance/preview2-shim": "^0.31.0"
}
}
Loading