What is the current way to create a wasm platform?
For a "normal" platform, I know what to do to create the files for the surgical or the legacy linker. But what is needed for was wasm-platform?
When I create an app and try to build it, as if the platform was there, I get the error message: No host.zig file found at examples/../platform/host.zig when building wasm32 target.
. Is host.zig
hardcoded?
If I create the file, I get the error error: wasm-ld: entry symbol not defined (pass --no-entry to suppress): _start
. Is the zig-command hard coded? Is there any way I could use a build.zig
? If I just create an _start
function, an .wasm
file is created, but it imports functions like wasi_snapshot_preview1
. So its not a normal .wasm
file, but a wasi
file.
I think wasm is very hardcode currently
The current state is to copy an example and use zig or to use --no-link
and the directly interact with the generated wasm
That is at least my current understanding from when I last used it.
And yeah, I think the exact build command is hard coded as well.
I would assume using --no-link
and then having build.zig
control all the linking would be the easiest way today
I think that is what roc-wasm4 does
But this means, there is no way to create a precompiled platform. You need to create some sort of app.o
file and link it with the host.o
-file to a .wasm
file?
I would need to mess around with the tool chain, but I don't think we have ever had working recompiled hosts for wasm
It has always been more adhoc and could use help
If I understand wasm4
correctly, it has a build.zig
and a build_roc.zig
. To build a wasm file, you call build.zig
which calls build_roc.zig
. build_roc.zig
calls the roc compiler with --no-link
. It creates an app.o
that is used by build.zig
to create the final wasm-file.
If there where support for a recompiled host, it would probably work like the legacy linker. Is this correct? The platform would provide some sort of host.o file, that roc can use to link it with the app.
This is an area that needs some love in the roc build pipeline.
Here's how I do it in the wasm template https://github.com/lukewilliamboswell/roc-platform-template-wasi/blob/main/build.sh
I think steps 2&3 are not currently done by roc build, but I think they should.
At least this is what I remember from when I was last looking at it.
After syntax season... I'm keen to loop back and clean up all these templates.
I'm definitely keen to pickup the WASM platform stuff again. I'd still like to build a playground in the browser.
Also for reference, another (slightly more modern) example I have is the js-dom experiment https://github.com/lukewilliamboswell/roc-experiment-js-dom
This uses Rust and builds both a WASI cli, and also a WASM module for the browser using wasm-pack.
Using rust for WASM platforms is also a good option right now -- though it's the same limitation, there isn't a good way to pre-build the host.
Luke Boswell said:
I'm definitely keen to pickup the WASM platform stuff again. I'd still like to build a playground in the browser.
it would be super rad to have this before redoing all the tutorials for static dispatch and everything, so they could be built around being interactive! :smiley:
Last updated: Jul 05 2025 at 12:14 UTC