diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index be06d493..1767b138 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,6 +21,7 @@ jobs: - { os: ubuntu-20.04, toolchain: wasm-5.7.3-RELEASE, wasi-backend: MicroWASI } - { os: ubuntu-20.04, toolchain: wasm-5.8.0-RELEASE, wasi-backend: MicroWASI } - { os: ubuntu-20.04, toolchain: wasm-5.9.1-RELEASE, wasi-backend: MicroWASI } + - { os: ubuntu-22.04, toolchain: wasm-DEVELOPMENT-SNAPSHOT-2024-05-02-a, wasi-backend: Node } runs-on: ${{ matrix.entry.os }} env: diff --git a/IntegrationTests/lib.js b/IntegrationTests/lib.js index a68f2bde..fa732498 100644 --- a/IntegrationTests/lib.js +++ b/IntegrationTests/lib.js @@ -1,6 +1,6 @@ const SwiftRuntime = require("javascript-kit-swift").SwiftRuntime; const NodeWASI = require("wasi").WASI; -const { WASI: MicroWASI, useAll } = require("uwasi"); +const { WASI: MicroWASI, useAll, useTrace } = require("uwasi"); const promisify = require("util").promisify; const fs = require("fs"); @@ -16,9 +16,9 @@ const WASI = { return { wasiImport: wasi.wasiImport, - start(instance) { + start(instance, swift) { wasi.initialize(instance); - instance.exports.main(); + swift.main(); } } }, @@ -26,15 +26,18 @@ const WASI = { const wasi = new NodeWASI({ args: [programName], env: {}, + preopens: { + "/": "./", + }, returnOnExit: false, version: "preview1", }) return { wasiImport: wasi.wasiImport, - start(instance) { + start(instance, swift) { wasi.initialize(instance); - instance.exports.main(); + swift.main(); } } }, @@ -69,7 +72,7 @@ const startWasiTask = async (wasmPath, wasiConstructor = selectWASIBackend()) => swift.setInstance(instance); // Start the WebAssembly WASI instance! - wasi.start(instance); + wasi.start(instance, swift); }; module.exports = { startWasiTask, WASI }; diff --git a/Makefile b/Makefile index ccf22798..35530b26 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,7 @@ test: .PHONY: unittest unittest: @echo Running unit tests - swift build --build-tests --triple wasm32-unknown-wasi -Xswiftc -Xclang-linker -Xswiftc -mexec-model=reactor -Xlinker --export=main + swift build --build-tests --triple wasm32-unknown-wasi -Xswiftc -Xclang-linker -Xswiftc -mexec-model=reactor -Xlinker --export-if-defined=main -Xlinker --export-if-defined=__main_argc_argv --static-swift-stdlib -Xswiftc -static-stdlib node --experimental-wasi-unstable-preview1 scripts/test-harness.js ./.build/wasm32-unknown-wasi/debug/JavaScriptKitPackageTests.wasm .PHONY: benchmark_setup diff --git a/scripts/test-harness.js b/scripts/test-harness.js index 39a7dbe9..27f9e93a 100644 --- a/scripts/test-harness.js +++ b/scripts/test-harness.js @@ -1,6 +1,11 @@ Error.stackTraceLimit = Infinity; -const { startWasiTask, WASI } = require("../IntegrationTests/lib"); +const { startWasiTask } = require("../IntegrationTests/lib"); + +if (process.env["JAVASCRIPTKIT_WASI_BACKEND"] === "MicroWASI") { + console.log("Skipping XCTest tests for MicroWASI because it is not supported yet."); + process.exit(0); +} const handleExitOrError = (error) => { console.log(error);