Skip to content

Commit 26b593c

Browse files
committed
Merge branch 'main' of github.com:wasmerio/wasmer-js
# Conflicts: # Cargo.lock
2 parents 77eee3c + 3473565 commit 26b593c

14 files changed

+592
-432
lines changed

Cargo.lock

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

Cargo.toml

+5-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ crate-type = ["cdylib"]
1010
[dependencies]
1111
js-sys = "0.3.55"
1212
wasm-bindgen = "0.2.73"
13-
wasm-bindgen-futures = "0.4.28"
14-
wasmer = { path = "../wasmer/lib/api", default-features = false, features = ["js-default"] }
13+
wasmer = { path = "../wasmer/lib/api", default-features = false, features = ["js", "std"] }
1514
wasmer-wasi = { path = "../wasmer/lib/wasi", default-features = false, features = ["js"] }
1615
wasmer-vfs = { path = "../wasmer/lib/vfs", default-features = false, features = ["mem-fs"] }
16+
17+
[profile.release]
18+
lto = true
19+
opt-level = 'z'

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import { init, WASI } from '@wasmer/wasi';
2828
2929
### Deno
3030

31-
This package is published in Deno in the `wasm` package, you can import it direclty with:
31+
This package is published in Deno in the `wasm` package, you can import it directly with:
3232

3333
```ts
3434
import { init, WASI } from 'https://deno.land/x/wasm/wasi.ts';
@@ -55,10 +55,10 @@ let wasi = new WASI({
5555
const moduleBytes = fetch("https://deno.land/x/wasm/tests/demo.wasm");
5656
const module = await WebAssembly.compileStreaming(moduleBytes);
5757
// Instantiate the WASI module
58-
await wasi.instantiate(module, {});
58+
let instance = await wasi.instantiate(module, {});
5959

6060
// Run the start function
61-
let exitCode = wasi.start();
61+
let exitCode = wasi.start(instance);
6262
let stdout = wasi.getStdoutString();
6363

6464
// This should print "hello world (exit code: 0)"
@@ -80,7 +80,7 @@ export class WASI {
8080
instantiate(module: any, imports: object): WebAssembly.Instance;
8181
// Start the WASI Instance, it returns the status code when calling the start
8282
// function
83-
start(): number;
83+
start(instance: WebAssembly.Instance): number;
8484
// Get the stdout buffer
8585
// Note: this method flushes the stdout
8686
getStdoutBuffer(): Uint8Array;

examples/deno/fs.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ let wasi = new WASI({
1010

1111
const moduleBytes = fetch("https://cdn.deno.land/wasm/versions/v1.0.1/raw/tests/mapdir.wasm");
1212
const module = await WebAssembly.compileStreaming(moduleBytes);
13-
await wasi.instantiate(module, {});
13+
let instance = await wasi.instantiate(module, {});
1414

1515
wasi.fs.createDir("/a");
1616
wasi.fs.createDir("/b");
@@ -19,7 +19,7 @@ let file = wasi.fs.open("/file", {read: true, write: true, create: true});
1919
file.writeString("fileContents");
2020
file.seek(0);
2121

22-
let exitCode = wasi.start();
22+
let exitCode = wasi.start(instance);
2323
let stdout = wasi.getStdoutString();
2424
// This should print "hello world (exit code: 0)"
2525
console.log(`${stdout}(exit code: ${exitCode})`);

examples/deno/helloworld.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ let wasi = new WASI({
1010

1111
const moduleBytes = fetch("https://cdn.deno.land/wasm/versions/v1.0.1/raw/tests/demo.wasm");
1212
const module = await WebAssembly.compileStreaming(moduleBytes);
13-
await wasi.instantiate(module, {});
13+
let instance = await wasi.instantiate(module, {});
1414

15-
let exitCode = wasi.start();
15+
let exitCode = wasi.start(instance);
1616
let stdout = wasi.getStdoutString();
1717
// This should print "hello world (exit code: 0)"
1818
console.log(`${stdout}(exit code: ${exitCode})`);

examples/node/fs.mjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const buf = fs.readFileSync('../../tests/mapdir.wasm');
1414
const module = await WebAssembly.compile(
1515
new Uint8Array(buf)
1616
);
17-
await wasi.instantiate(module, {});
17+
let instance = await wasi.instantiate(module, {});
1818

1919
wasi.fs.createDir("/a");
2020
wasi.fs.createDir("/b");
@@ -23,7 +23,7 @@ let file = wasi.fs.open("/file", {read: true, write: true, create: true});
2323
file.writeString("fileContents");
2424
file.seek(0);
2525

26-
let exitCode = wasi.start();
26+
let exitCode = wasi.start(instance);
2727
let stdout = wasi.getStdoutString();
2828

2929
// This should print "hello world (exit code: 0)"

examples/node/helloworld.mjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ const buf = fs.readFileSync('../../tests/demo.wasm');
1414
const module = await WebAssembly.compile(
1515
new Uint8Array(buf)
1616
);
17-
await wasi.instantiate(module, {});
17+
let instance = await wasi.instantiate(module, {});
1818

19-
let exitCode = wasi.start();
19+
let exitCode = wasi.start(instance);
2020
let stdout = wasi.getStdoutString();
2121
// This should print "hello world (exit code: 0)"
2222
console.log(`${stdout}(exit code: ${exitCode})`);

pkg/wasmer_wasi_js.d.ts

+23-16
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,23 @@ export class WASI {
101101
*/
102102
constructor(config: any);
103103
/**
104+
* @param {WebAssembly.Module} module
105+
* @returns {object}
106+
*/
107+
get_imports(module: WebAssembly.Module): object;
108+
/**
104109
* @param {any} module
105-
* @param {object} imports
110+
* @param {object | undefined} imports
106111
* @returns {WebAssembly.Instance}
107112
*/
108-
instantiate(module: any, imports: object): WebAssembly.Instance;
113+
instantiate(module: any, imports?: object): WebAssembly.Instance;
109114
/**
110115
* Start the WASI Instance, it returns the status code when calling the start
111116
* function
117+
* @param {WebAssembly.Instance} instance
112118
* @returns {number}
113119
*/
114-
start(): number;
120+
start(instance: WebAssembly.Instance): number;
115121
/**
116122
* Get the stdout buffer
117123
* Note: this method flushes the stdout
@@ -163,6 +169,19 @@ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembl
163169

164170
export interface InitOutput {
165171
readonly memory: WebAssembly.Memory;
172+
readonly __wbg_wasmerruntimeerror_free: (a: number) => void;
173+
readonly __wbg_wasi_free: (a: number) => void;
174+
readonly wasi_new: (a: number) => number;
175+
readonly wasi_fs: (a: number) => number;
176+
readonly wasi_get_imports: (a: number, b: number) => number;
177+
readonly wasi_instantiate: (a: number, b: number, c: number) => number;
178+
readonly wasi_start: (a: number, b: number) => number;
179+
readonly wasi_getStdoutBuffer: (a: number, b: number) => void;
180+
readonly wasi_getStdoutString: (a: number, b: number) => void;
181+
readonly wasi_getStderrBuffer: (a: number, b: number) => void;
182+
readonly wasi_getStderrString: (a: number, b: number) => void;
183+
readonly wasi_setStdinBuffer: (a: number, b: number, c: number) => void;
184+
readonly wasi_setStdinString: (a: number, b: number, c: number) => void;
166185
readonly __wbg_memfs_free: (a: number) => void;
167186
readonly memfs_new: () => number;
168187
readonly memfs_readDir: (a: number, b: number, c: number) => number;
@@ -184,24 +203,12 @@ export interface InitOutput {
184203
readonly jsvirtualfile_writeString: (a: number, b: number, c: number) => number;
185204
readonly jsvirtualfile_flush: (a: number) => void;
186205
readonly jsvirtualfile_seek: (a: number, b: number) => number;
187-
readonly __wbg_wasi_free: (a: number) => void;
188-
readonly wasi_new: (a: number) => number;
189-
readonly wasi_fs: (a: number) => number;
190-
readonly wasi_instantiate: (a: number, b: number, c: number) => number;
191-
readonly wasi_start: (a: number) => number;
192-
readonly wasi_getStdoutBuffer: (a: number, b: number) => void;
193-
readonly wasi_getStdoutString: (a: number, b: number) => void;
194-
readonly wasi_getStderrBuffer: (a: number, b: number) => void;
195-
readonly wasi_getStderrString: (a: number, b: number) => void;
196-
readonly wasi_setStdinBuffer: (a: number, b: number, c: number) => void;
197-
readonly wasi_setStdinString: (a: number, b: number, c: number) => void;
198-
readonly __wbg_wasmerruntimeerror_free: (a: number) => void;
199206
readonly __wbindgen_malloc: (a: number) => number;
200207
readonly __wbindgen_realloc: (a: number, b: number, c: number) => number;
201208
readonly __wbindgen_export_2: WebAssembly.Table;
209+
readonly __wbindgen_exn_store: (a: number) => void;
202210
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
203211
readonly __wbindgen_free: (a: number, b: number) => void;
204-
readonly __wbindgen_exn_store: (a: number) => void;
205212
}
206213

207214
/**

0 commit comments

Comments
 (0)