Skip to content

Support latest nightly snapshot #246

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 8, 2024
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
4 changes: 1 addition & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ jobs:
# Ensure that test succeeds with all toolchains and wasi backend combinations
- { os: ubuntu-20.04, toolchain: wasm-5.7.3-RELEASE, wasi-backend: Node }
- { os: ubuntu-20.04, toolchain: wasm-5.8.0-RELEASE, wasi-backend: Node }
- { os: ubuntu-20.04, toolchain: wasm-5.7.3-RELEASE, wasi-backend: Wasmer }
- { os: ubuntu-20.04, toolchain: wasm-5.8.0-RELEASE, wasi-backend: Wasmer }
- { os: ubuntu-20.04, toolchain: wasm-5.9.1-RELEASE, wasi-backend: Wasmer }
- { 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:
Expand Down
3 changes: 2 additions & 1 deletion IntegrationTests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ TestSuites/.build/$(CONFIGURATION)/%.wasm: FORCE
--triple wasm32-unknown-wasi \
--configuration $(CONFIGURATION) \
-Xswiftc -Xclang-linker -Xswiftc -mexec-model=reactor \
-Xlinker --export=main \
-Xlinker --export-if-defined=main -Xlinker --export-if-defined=__main_argc_argv \
--static-swift-stdlib -Xswiftc -static-stdlib \
$(SWIFT_BUILD_FLAGS)

dist/%.wasm: TestSuites/.build/$(CONFIGURATION)/%.wasm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ try test("Call Function With This") {
let setName = try expectFunction(getJSValue(this: cat1, name: "setName"))

// Direct call without this
try expectEqual(getIsCat(), .undefined)
_ = try expectThrow(try getIsCat.throws())

// Call with this
let gotIsCat = getIsCat(this: cat1)
Expand Down
4 changes: 2 additions & 2 deletions IntegrationTests/bin/benchmark-tests.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { startWasiTask } = require("../lib");
const { performance } = require("perf_hooks");
import { startWasiTask } from "../lib.js";
import { performance } from "perf_hooks";

const SAMPLE_ITERATION = 1000000

Expand Down
2 changes: 1 addition & 1 deletion IntegrationTests/bin/concurrency-tests.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { startWasiTask } = require("../lib");
import { startWasiTask } from "../lib.js";

Error.stackTraceLimit = Infinity;

Expand Down
2 changes: 1 addition & 1 deletion IntegrationTests/bin/primary-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ global.objectDecodingTest = {
bi: BigInt(3)
};

const { startWasiTask, WASI } = require("../lib");
import { startWasiTask } from "../lib.js";

startWasiTask("./dist/PrimaryTests.wasm").catch((err) => {
console.log(err);
Expand Down
67 changes: 14 additions & 53 deletions IntegrationTests/lib.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,9 @@
const SwiftRuntime = require("javascript-kit-swift").SwiftRuntime;
const WasmerWASI = require("@wasmer/wasi").WASI;
const WasmFs = require("@wasmer/wasmfs").WasmFs;
const NodeWASI = require("wasi").WASI;
const { WASI: MicroWASI, useAll } = require("uwasi");

const promisify = require("util").promisify;
const fs = require("fs");
const readFile = promisify(fs.readFile);
import { SwiftRuntime } from "javascript-kit-swift"
import { WASI as NodeWASI } from "wasi"
import { WASI as MicroWASI, useAll } from "uwasi"
import * as fs from "fs/promises"

const WASI = {
Wasmer: ({ programName }) => {
// Instantiate a new WASI Instance
const wasmFs = new WasmFs();
// Output stdout and stderr to console
const originalWriteSync = wasmFs.fs.writeSync;
wasmFs.fs.writeSync = (fd, buffer, offset, length, position) => {
const text = new TextDecoder("utf-8").decode(buffer);
switch (fd) {
case 1:
console.log(text);
break;
case 2:
console.error(text);
break;
}
return originalWriteSync(fd, buffer, offset, length, position);
};
const wasi = new WasmerWASI({
args: [programName],
env: {},
bindings: {
...WasmerWASI.defaultBindings,
fs: wasmFs.fs,
},
});

return {
wasiImport: wasi.wasiImport,
start(instance) {
wasi.start(instance);
instance.exports._initialize();
instance.exports.main();
}
}
},
MicroWASI: ({ programName }) => {
const wasi = new MicroWASI({
args: [programName],
Expand All @@ -53,25 +13,28 @@ const WASI = {

return {
wasiImport: wasi.wasiImport,
start(instance) {
start(instance, swift) {
wasi.initialize(instance);
instance.exports.main();
swift.main();
}
}
},
Node: ({ programName }) => {
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();
}
}
},
Expand All @@ -88,10 +51,10 @@ const selectWASIBackend = () => {
return WASI.Node;
};

const startWasiTask = async (wasmPath, wasiConstructor = selectWASIBackend()) => {
export const startWasiTask = async (wasmPath, wasiConstructor = selectWASIBackend()) => {
const swift = new SwiftRuntime();
// Fetch our Wasm File
const wasmBinary = await readFile(wasmPath);
const wasmBinary = await fs.readFile(wasmPath);
const wasi = wasiConstructor({ programName: wasmPath });

// Instantiate the WebAssembly file
Expand All @@ -106,7 +69,5 @@ 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 };
Loading
Loading