Hello, I tried running the hello world, wanting to create a wasm output, ./roc build --target wasm32
but got this error:
I was expecting this file to exist:
/Users/matthew/.cache/roc/packages/github.com/roc-lang/basic-cli/releases/download/0.5.0/Cufzl36_SnJ4QbOoEmiJ5dIpUxBvdB3NEySvuH82Wio/host.zig
However, it was not there!
The help suggests that using --target wasm32 should not assume prebuilt, but that doesn't seem to be the case. Any advice?
2 messages were moved here from #beginners > my from time to time feedback about Roc by Anton.
Hi @Matthew Phillips,
The basic-cli platform does not support targeting wasm. That's because a lot of basic-cli functions can't work in a wasm/browser context, like reading from stdin. We should have a better error message for this case though.
You may want to checkout this wasm platform.
Can you share what you would like to build/test with wasm?
That may help us guide you better.
Ah ok thank you. So the idea is you use a different cli when building to wasm?
A different platform to be specific.
Hm, ok I think the problem is I don't know what "platform" is yet
so i'll read that page
ok, so the pf
in the app config defines the platform? So I just need to swap that out? Will try it.
Do you need a zig file to use wasm?
Yes, I believe so
I recommend downloading this platform locally and following along with the README
ok, i'll test that out, thanks
So I just need to swap that out?
Different platforms work with different types and provide different functionality so in most cases it will not be possible to swap out the platform without changing anything else.
I have to go now, but other people should be able to help out :)
Oh, well it's already included in the nightly.
Thanks @Anton
I get a compiler error. Getting closer!
I think it's because I have the wrong version of zig installed.
Fixing that part now.
Now installing Rust...
:hammer: Rebuilding platform...
An internal compiler expectation was broken.
This is definitely a compiler bug.
Please file an issue here: https://github.com/roc-lang/roc/issues/new/choose
thread 'main' panicked at 'cannot find wasi-libc.a
', crates/compiler/build/src/link.rs:133:5
rustc --version
rustc 1.74.0 (79e9716c9 2023-11-13)
zig version
0.11.0
app "rocLovesWebAssembly"
packages { pf: "./examples/platform-switching/web-assembly-platform/main.roc" }
imports []
provides [main] to pf
main = "Roc <3 Web Assembly!\n"
My guess is that we build that file but have failed to include it in the nightly releases. So the platform works if the compiler is built from source, but not if it is downloaded from nightly.
Ok, might try that
If you run cargo build
where are the binaries? I'm not familiar with rust conventions
target/debug/roc
(or target/release/roc
if you built with --release
)
Perfect, thanks
woohoo, it all works now
I'll file a bug for that
Should definitely work for nightly too
Not sure if this is another bug or I did something wrong:
LinkError: WebAssembly.instantiate(): Import #2 module="wasi_snapshot_preview1" function="random_get": function import requires a callable
That's in the browser.
Yeah, i think that's a bug too
I would guess that's just the example missing that function
But I don't see anything in the repo about "random_get"
random_get(v) {
return Math.random();
}
Adding this to the importObj fixed it. I assume this is not right though!
good enough to unblock me, for now.
Hmm. So I think I see the real issue, this is compiling for wasi, which is web assembly not in the browser. I think it should be compiling for just wasm without any extra wasi stuff.
ah yeah that makes sense
That problems means the binary size is a little larger than it would normally be
not that it's big currently or anything
Last updated: Jul 05 2025 at 12:14 UTC