Stream: beginners

Topic: nodejs-wasm example


view this post on Zulip Vladimir Zotov (Dec 09 2023 at 21:24):

I'm trying to compile nodejs-wasm example in a docker image with roc nightly and zig 0.11. Getting an error for this file
https://github.com/roc-lang/roc/blob/main/examples/nodejs-interop/wasm/platform/host.zig

$ roc build --target=wasm32
🔨 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 '<unnamed>' panicked at 'Error:
    Failed to rebuild host.zig:
        The executed command was:
            zig build-obj platform/host.zig -femit-llvm-ir=platform/main.bc --mod glue::/roc/crates/compiler/builtins/bitcode/src/glue.zig --deps glue --library c -target wasm32-wasi -fPIC -fstrip
        stderr of that command:
            platform/host.zig:27:33: error: expected type 'u32', found 'type'
platform/host.zig:33:23: error: expected type 'u32', found 'type'
', crates/compiler/build/src/link.rs:1414:21
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Is there an easy fix (in the Zig file I suppose)?

view this post on Zulip Brendan Hansknecht (Dec 09 2023 at 21:34):

we probably missed updating it to 0.11

view this post on Zulip Brendan Hansknecht (Dec 09 2023 at 21:36):

Oh, I see

view this post on Zulip Brendan Hansknecht (Dec 09 2023 at 21:36):

In some place we use @alignOf(Align) and others just Align

view this post on Zulip Brendan Hansknecht (Dec 09 2023 at 21:36):

yeah, small fix

view this post on Zulip Vladimir Zotov (Dec 10 2023 at 07:46):

@Brendan Hansknecht Here you go
https://github.com/roc-lang/roc/pull/6237

view this post on Zulip Vladimir Zotov (Dec 10 2023 at 08:29):

Now it is complaining that it cannot find wasi-libc.a. I guess I could install or build it but I'm not sure that there are more things to install as well. Does anyone know?

view this post on Zulip Brian Carroll (Dec 10 2023 at 09:02):

If you build the compiler from source it should build that file. I think we might not be packaging it correctly.

view this post on Zulip Vladimir Zotov (Dec 11 2023 at 07:51):

It took me a few hours to figure out how to build compiler in my Docker file. The thing I'm trying to understand now is how to get past this error during building:
No suitable version of LLVM was found system-wide or pointed...

view this post on Zulip Anton (Dec 11 2023 at 10:27):

Hi @Vladimir Zotov,
You need to set LLVM_SYS_160_PREFIX to the path of where you installed llvm 16.

view this post on Zulip Pearce Keesling (Dec 11 2023 at 19:14):

I think there's an open GitHub issue for the wasi-libc issues. I remember running into that a while back

view this post on Zulip Vladimir Zotov (Dec 11 2023 at 20:18):

I know, there are two of them actually, I already explored them. Building from scratch was the answer. Annoyingly, apt install for llvm is broken on Ubuntu with a ticket open on github, so I have to do a sad plain download of clang, llvm and other stuff.

view this post on Zulip Vladimir Zotov (Dec 11 2023 at 20:20):

I'm making a VSCode devcontainer, which makes getting started with roc super easy (I got it running the roc's CLI example). I'll probably get there with node WASM as well :melting_face:

view this post on Zulip Anton (Dec 12 2023 at 10:36):

This file may also be useful to you

view this post on Zulip Vladimir Zotov (Dec 12 2023 at 15:54):

Thanks! I've got mine working as well in the end :upside_down:

view this post on Zulip Vladimir Zotov (Dec 12 2023 at 20:52):

Hey @Brendan Hansknecht
https://github.com/roc-lang/roc/blob/012d93574ae59ce67647d7e2dcd9b47c93855651/examples/nodejs-interop/wasm/hello.js#L4
That line assumes the compiled file is called roc-app.wasm but instead mine is compiled tomain.wasm. Should I submit a PR with the change??
If it is, I've got a runtime error:

    const instance = new WebAssembly.Instance(wasmModule, importObj);
                     ^

LinkError: WebAssembly.Instance(): Import #2 module="wasi_snapshot_preview1" function="random_get" error: function import requires a callable
    at hello (/home/node/proj/hello.js:44:22)

I have no idea where it gets random_get from :melting_face:

view this post on Zulip Brian Carroll (Dec 13 2023 at 07:11):

That's a WASI function it's trying to import into the Wasm module so something in the platform must be using it.


Last updated: Jul 05 2025 at 12:14 UTC