Skip to content

Commit e44d0ff

Browse files
committed
Rebase and fix tests
* Pull in latest `wasmtime` where `main` now works * Add a `testwasi` implementation for JS and use it in all tests * Add a dummy `printf` to a C test to ensure it imports `testwasi` like the other languages. * Add a `fd_fdstat_get` stub to make C happy * Update `fd_write` to only work for fd 1
1 parent 5aa153a commit e44d0ff

File tree

13 files changed

+78
-42
lines changed

13 files changed

+78
-42
lines changed

Cargo.lock

+30-30
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ pulldown-cmark = { version = "0.8", default-features = false }
2626
clap = { version = "4.0.9", features = ["derive"] }
2727
env_logger = "0.9.1"
2828

29-
wasmtime = { git = "https://github.com/alexcrichton/wasmtime", branch = "wit-bindgen-pieces" , features = ["component-model"] }
30-
wasmtime-wasi = { git = "https://github.com/alexcrichton/wasmtime", branch = "wit-bindgen-pieces" }
31-
wasmtime-environ = { git = "https://github.com/alexcrichton/wasmtime", branch = "wit-bindgen-pieces" }
29+
wasmtime = { git = "https://github.com/bytecodealliance/wasmtime", branch = "main" , features = ["component-model"] }
30+
wasmtime-wasi = { git = "https://github.com/bytecodealliance/wasmtime", branch = "main" }
31+
wasmtime-environ = { git = "https://github.com/bytecodealliance/wasmtime", branch = "main" }
3232
wasmprinter = "0.2.41"
3333
wasmparser = "0.92.0"
3434
wasm-encoder = "0.18.0"

crates/gen-host-js/tests/helpers.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @ts-ignore
22
import { readFile } from 'node:fs/promises';
33
// @ts-ignore
4-
import { argv } from 'node:process';
4+
import { argv, stdout } from 'node:process';
55

66
// This is a helper function used from `host.ts` test in the `tests/runtime/*`
77
// directory to pass as the `instantiateCore` argument to the `instantiate`
@@ -15,3 +15,9 @@ export async function loadWasm(path: string, imports: any) {
1515
const m = await WebAssembly.compile(await readFile(root + '/' + path))
1616
return await WebAssembly.instantiate(m, imports);
1717
}
18+
19+
export const testwasi = {
20+
log(bytes: Uint8Array) {
21+
stdout.write(bytes);
22+
},
23+
};

crates/wasi_snapshot_preview1/src/lib.rs

+19
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ pub extern "C" fn fd_write(
8181
mut iovs_len: usize,
8282
nwritten: *mut Size,
8383
) -> Errno {
84+
if fd != 1 {
85+
unreachable();
86+
}
8487
unsafe {
8588
// Advance to the first non-empty buffer.
8689
while iovs_len != 0 && (*iovs_ptr).buf_len == 0 {
@@ -116,3 +119,19 @@ pub extern "C" fn fd_close(fd: Fd) -> Errno {
116119
pub extern "C" fn proc_exit(rval: Exitcode) -> ! {
117120
unreachable()
118121
}
122+
123+
#[no_mangle]
124+
pub extern "C" fn fd_fdstat_get(fd: Fd, fdstat: *mut Fdstat) -> Errno {
125+
if fd != 1 {
126+
unreachable();
127+
}
128+
129+
unsafe {
130+
(*fdstat).fs_filetype = FILETYPE_UNKNOWN;
131+
(*fdstat).fs_flags = FDFLAGS_APPEND;
132+
(*fdstat).fs_rights_base = RIGHTS_FD_WRITE;
133+
(*fdstat).fs_rights_inheriting = RIGHTS_FD_WRITE;
134+
}
135+
136+
ERRNO_SUCCESS
137+
}

tests/runtime/flavorful/host.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import { loadWasm } from "./helpers.js";
1+
import { loadWasm, testwasi } from "./helpers.js";
22
import { instantiate } from "./flavorful.js";
33

44
// @ts-ignore
55
import * as assert from 'assert';
66

77
async function run() {
88
const wasm = await instantiate(loadWasm, {
9+
testwasi,
910
imports: {
1011
fListInRecord1(x) {},
1112
fListInRecord2() { return { a: 'list_in_record2' }; },

tests/runtime/invalid/host.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { instantiate } from "./invalid.js";
2-
import { loadWasm } from "./helpers.js";
2+
import { loadWasm, testwasi } from "./helpers.js";
33
// @ts-ignore
44
import * as assert from 'assert';
55

66
async function run() {
77
const wasm = await instantiate(loadWasm, {
8+
testwasi,
89
imports: {
910
roundtripU8(x) { throw new Error('unreachable'); },
1011
roundtripS8(x) { throw new Error('unreachable'); },

tests/runtime/lists/host.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import { loadWasm } from "./helpers.js";
1+
import { loadWasm, testwasi } from "./helpers.js";
22
import { instantiate } from "./lists.js";
33

44
// @ts-ignore
55
import * as assert from 'assert';
66

77
async function run() {
88
const wasm = await instantiate(loadWasm, {
9+
testwasi,
910
imports: {
1011
emptyListParam(a) {
1112
assert.deepStrictEqual(Array.from(a), []);

tests/runtime/many_arguments/host.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { instantiate } from "./many_arguments.js";
2-
import { loadWasm } from "./helpers.js";
2+
import { loadWasm, testwasi } from "./helpers.js";
33

44
function assertEq(x: any, y: any) {
55
if (x !== y)
@@ -13,6 +13,7 @@ function assert(x: boolean) {
1313

1414
async function run() {
1515
const wasm = await instantiate(loadWasm, {
16+
testwasi,
1617
imports: {
1718
manyArguments(
1819
a1,

tests/runtime/numbers/host.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { loadWasm } from "./helpers.js";
1+
import { loadWasm, testwasi } from "./helpers.js";
22
import { instantiate } from "./numbers.js";
33

44
function assertEq(x: any, y: any) {
@@ -14,6 +14,7 @@ function assert(x: boolean) {
1414
async function run() {
1515
let scalar = 0;
1616
const wasm = await instantiate(loadWasm, {
17+
testwasi,
1718
imports: {
1819
roundtripU8(x) { return x; },
1920
roundtripS8(x) { return x; },

0 commit comments

Comments
 (0)