WASM, setjmp and generic-musl


Hi friends! I’m back again, and so soon.

I’m getting an error I just don’t quite know how to make sense of.

I’m trying to build a (truly large, not at all within my grasp) blob of c, the https://janet-lang.org interpreter.

This is what I type: $ zig cc janet.c -target wasm32-wasi

This is what I get:

In file included from src/core/features.h:81:
In file included from ./janet.h:437:
/opt/homebrew/Cellar/zig/0.12.0/lib/zig/libc/include/generic-musl/setjmp.h:10:10: fatal error: 'bits/setjmp.h' file not found
   10 | #include <bits/setjmp.h>
      |          ^~~~~~~~~~~~~~~
LLD Link... 1 error generated.

Indeed, the setjmp.h in the generic-musl libc inside of Zig asks for bits/setjmp.h, which doesn’t exist. This is true in Zig 0.12.0 and in 0.13.0 (released today!!). This looks like a bug inside the generic-musl libc?

That said, from my googling around, it sounds like wasm doesn’t play nice with setjmp, so perhaps this is expected behaviour (just with an obscure error).

Any insight anybody could provide would be massively welcome. Thank you!!

Hi @kredati There are two problems.

  1. bits/setjmp.h is different for each architecture, for x86_64 it is placed in lib/libc/musl/arch/x86_64/bits/setjmp.h
  2. bits/setjmp.h is a linux kernel header file and musl is a linux libc. I am not sure why it is used for wasm32-wasi.
1 Like

How did you set up Janet to build for wasm? Just looking at the project I don’t see any mention of support for wasm targets. I found one playground project that is building it for the web using emscripten, but that will require you to use emcc .

1 Like

Thanks for the responses! And sorry for the long time coming for the thanks.

I did get everything to work using emcc and C++ (shudder), after stripping the playground projects down for parts. It looks like zig cc -target wasm32-wasi just isn’t compatible with Janet’s C codebase.

I just saw that I was getting errors in the guts of the Zig lib, and immediately knew I was out over my skis rather further than I expected.