I think we should add a CI test that builds the compiler for a WASM target -- to ensure we maintain this as an option for embedding roc in future.
Currently we can't build for WASM due to using realpath, but it's only in a few places -- in coordinate I think.
I've somewhat isolated those using a (very average) abstraction, but it would be good to sort this out now because it might get painful later to change.
Is this something anyone would like to look at?
Wasm in this case should be wasm32-freestanding-none
?
Or are we targetting wasm32-wasi-musl
and something like wasmer js sdk
I'm not sure. For embedding the roc compiler in WASM -- we would need a way to provide things like files etc.
I guess we could compile to WASI...
My concern is that we add more features over time and it becomes harder to embed the compiler in a WASM context.
I'm not sure we need to fully abstract things like files now, but we at least want to isolate those somehow.
If the goal is the web repl, we don't need files at all.
Yeah, I can imagine things like REPL or interpreter running in WASM
Though I guess it might be nice to import from github via the web repl
Or even the formatter, or eventual LSP maybe.
Anyway, I think we have to work via wasm32-freestanding-none
if we want to run in the browser with no dependencies. In that case, roc won't be an executable at all. It will be a library and js will have to fill in filesystem hooks.
Yeah, not sure how we do that. Or would that just be libroc?
Yeah, we probably want to make a root.zig
and a library form of roc.
Looks likes all issues today are around filesystems and time measurement
Oh, though timing is for the cli, so it won't be in the library at all
So yeah, I think it is just either making the library level not interact with the filesystem (assume all data is already loaded), or make it abstract away the filesystem (likely nicer and more flexible).
So shouldn't be too bad
Yeah, it was the filesystem and also specifically our use of "paths" that I'm concerned about
I guess porting the formatter to the filesystem api, making a dummy filesystem for wasm (can be totally unimplemented), and adding wasm to ci, would at least stop any new problematic code from being created.
Yeah something like that was what I was thinking.
Though I'm not sure what the right api to cut for wasm is. Like can the current api reasonably be implemented in a browser?
The API for the (internal) compiler functionality?
Like load and typecheck this roc module? or format this file?
The file api. Cause we expect that it will be implemented in the browser by js
Last updated: Jul 06 2025 at 12:14 UTC