Stream: compiler development

Topic: zig compiler - WASM


view this post on Zulip Luke Boswell (Mar 19 2025 at 00:20):

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?

view this post on Zulip Brendan Hansknecht (Mar 19 2025 at 01:14):

Wasm in this case should be wasm32-freestanding-none?

view this post on Zulip Brendan Hansknecht (Mar 19 2025 at 01:17):

Or are we targetting wasm32-wasi-musl and something like wasmer js sdk

view this post on Zulip Luke Boswell (Mar 19 2025 at 01:17):

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.

view this post on Zulip Luke Boswell (Mar 19 2025 at 01:18):

I'm not sure we need to fully abstract things like files now, but we at least want to isolate those somehow.

view this post on Zulip Brendan Hansknecht (Mar 19 2025 at 01:18):

If the goal is the web repl, we don't need files at all.

view this post on Zulip Luke Boswell (Mar 19 2025 at 01:18):

Yeah, I can imagine things like REPL or interpreter running in WASM

view this post on Zulip Brendan Hansknecht (Mar 19 2025 at 01:18):

Though I guess it might be nice to import from github via the web repl

view this post on Zulip Luke Boswell (Mar 19 2025 at 01:19):

Or even the formatter, or eventual LSP maybe.

view this post on Zulip Brendan Hansknecht (Mar 19 2025 at 01:19):

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.

view this post on Zulip Luke Boswell (Mar 19 2025 at 01:20):

Yeah, not sure how we do that. Or would that just be libroc?

view this post on Zulip Brendan Hansknecht (Mar 19 2025 at 01:21):

Yeah, we probably want to make a root.zig and a library form of roc.

view this post on Zulip Brendan Hansknecht (Mar 19 2025 at 01:21):

Looks likes all issues today are around filesystems and time measurement

view this post on Zulip Brendan Hansknecht (Mar 19 2025 at 01:23):

Oh, though timing is for the cli, so it won't be in the library at all

view this post on Zulip Brendan Hansknecht (Mar 19 2025 at 01:23):

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).

view this post on Zulip Brendan Hansknecht (Mar 19 2025 at 01:24):

So shouldn't be too bad

view this post on Zulip Luke Boswell (Mar 19 2025 at 01:24):

Yeah, it was the filesystem and also specifically our use of "paths" that I'm concerned about

view this post on Zulip Brendan Hansknecht (Mar 19 2025 at 01:29):

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.

view this post on Zulip Luke Boswell (Mar 19 2025 at 01:30):

Yeah something like that was what I was thinking.

view this post on Zulip Brendan Hansknecht (Mar 19 2025 at 01:31):

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?

view this post on Zulip Luke Boswell (Mar 19 2025 at 01:32):

The API for the (internal) compiler functionality?

view this post on Zulip Luke Boswell (Mar 19 2025 at 01:33):

Like load and typecheck this roc module? or format this file?

view this post on Zulip Brendan Hansknecht (Mar 19 2025 at 01:54):

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