mach: Add js-runtime as a dependency for wasm applications

This is a workaround for a limitation right now. The html-generator has
no way to dynamically add JS sources (and that can't be done without
using a preprocessor library) so we hardcode js-runtime in it.

In the future, I think the correct behavior would be to move tools/
inside js-runtime along with a wasm application building SDK and get rid
of any direct JS access we have today (which is just
src/platform/wasm.zig and src/platform/mach.js).
This commit is contained in:
iddev5 2022-07-06 17:50:12 +05:30 committed by Stephen Gutekanst
parent d10ab25c5d
commit 0ff8edebd9
2 changed files with 14 additions and 7 deletions

View file

@ -6,9 +6,10 @@
<body>
<script type="module">
import {{ mach }} from "./mach.js";
import {{ zig }} from "./js-runtime.js";
let imports = {{
env: mach,
env: {{ ...mach, ...zig }},
}};
fetch("{s}.wasm")
@ -16,6 +17,7 @@
.then(buffer => WebAssembly.instantiate(buffer, imports))
.then(results => results.instance)
.then(instance => {{
zig.init(instance);
mach.init(instance);
instance.exports.wasmInit();