Skip to content

Commit

Permalink
First attempt to get dynamic linking working
Browse files Browse the repository at this point in the history
  • Loading branch information
asprouse committed May 28, 2024
1 parent e03e2ae commit c2a9d73
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
node_modules
embedded.wasm
embedded.wasm
provider.wasm
24 changes: 18 additions & 6 deletions host.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,19 @@ async function run(wasmFilePath, input) {
const wasm = await WebAssembly.compile(
await readFile(new URL(wasmFilePath, import.meta.url)),
);
const instance = await WebAssembly.instantiate(
wasm,
wasi.getImportObject(),

const provider = await WebAssembly.compile(
await readFile(new URL("./provider.wasm", import.meta.url)),
);

const wasiImports = wasi.getImportObject();
const providerInstance = await WebAssembly.instantiate(provider, wasiImports);

const instance = await WebAssembly.instantiate(wasm, {
...wasiImports,
javy_quickjs_provider_v1: providerInstance.exports,
});

wasi.start(instance);

const [out, err] = await Promise.all([
Expand All @@ -63,9 +71,13 @@ async function run(wasmFilePath, input) {

return out;
} catch (e) {
const errorMessage = await readOutput(stderrFilePath);
if (errorMessage) {
throw new Error(errorMessage);
if (e instanceof WebAssembly.RuntimeError) {
const errorMessage = await readOutput(stderrFilePath);
if (errorMessage) {
throw new Error(errorMessage);
}
} else {
throw e;
}
} finally {
await Promise.all([
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "host.mjs",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "javy compile embedded.js -o embedded.wasm",
"build": "javy emit-provider -o provider.wasm && javy compile embedded.js -d -o embedded.wasm",
"start": "node --no-warnings=ExperimentalWarning host.mjs"
},
"author": "",
Expand Down

0 comments on commit c2a9d73

Please sign in to comment.