WIP: Improve Emscripten support - #5259
Conversation
|
@QuantumSegfault: This seems like a viable approach - basing Emscripten on your WASI work, after reading https://v8.dev/blog/emscripten-standalone-wasm and noting that they apparently try to use WASI APIs as much as possible, even in non-standalone-wasm mode. To get the druntime test runners to link, I only had to avoid a single undefined |
|
I'm not sure this makes sense to do like this. Emscripten use a more vanilla Musl, without all of the differences to the headers WASI-libc made. They opted to stub out functions, rather than remove them, and otherwise use the unmodified types, constants, etc. (other than where architecture specific differences are concerned). A lot of the
|
|
Yeah the I'd hope that Emscripten would eventually be based on wasi-libc... |
dc050c1 to
b03eb55
Compare
|
Okay, this is now based on I'm okay with depending/building on predefined |
Threading is a notable difference. Emscripten actually DOES support threading (over web workers; with some caveats). https://emscripten.org/docs/porting/pthreads.html Signals still not, other than for Though I wouldn't mind holding off on the threading discussion until I figure out WASIp3 (with Other than that I think the rest of the WASI route-arounds should be fine, if not always necessary. |
Yeah that sounds good to me. [And note that I've just started with The compiler has a special case wrt. TLS globals for wasm in general IIRC, emitting them as thread-global; so the compiler will probably have to be adapted for wasm threading too. |
I'm fairly certain that WASIp1 is the only valid option for Emscripten. They provide a subset of WASIp1 for the web (but not p2+ AFAICT) https://github.com/emscripten-core/emscripten/blob/main/src/lib/libwasi.js
Good to know. |
| enum B_NO_TRANSLATOR = (B_TRANSLATION_ERROR_BASE + 1); | ||
| enum B_ILLEGAL_DATA = (B_TRANSLATION_ERROR_BASE + 2); | ||
| } | ||
| else version (CRuntime_WASI) |
There was a problem hiding this comment.
These errno are correct, but Emscripten provides additional ones:
There was a problem hiding this comment.
Yeah here I was lazy and didn't want to duplicate the existing CRuntime_WASI block, after seeing that the Emscripten headers forward the WASI codes. [And I don't really care about the extra ones; if people relied on them, their code wouldn't work with WASI.]
At least a comment wrt. Emscripten would be good though; there's some polishing left to do, hence the draft state and WIP title. :)
There was a problem hiding this comment.
Yeah. Just the one thing that stuck out as probably somehow wrong, so I checked.
I'll wait for it to be undrafted before reviewing the changes more thoroughly.
| tool = getCC(argsBuilder->args); | ||
| } | ||
| auto argsBuilder = std::make_unique<ArgsBuilder>(); | ||
| std::string tool = getCC(argsBuilder->args); |
There was a problem hiding this comment.
This is e.g. also still to polish, causing the Alpine CI job failures (no integrated LLD, but external wasm-ld).
This all dates back to the very early wasm support, like the wasm-defaults .conf file - we used to only support bare-metal wasm, so no druntime and Phobos to link, and no need for a C compiler as linker driver, since there wasn't a wasm libc support either. So we used to invoke wasm-ld (unless we have an integrated LLD) with the ld CLI interface, for all (non-WASI) wasm targets.
We can keep this behavior for backwards-compatibility, but then only when targeting an unknown/none OS. We already do that in 55-target-wasm-naked.conf nowadays, via the -link-internally (=> use integrated lld with wasm-ld CLI interface) - but only if LLD integration was enabled at build-time.
So the compiler special case here would only be needed without LLD integration. Not sure that's worth the trouble, incl. the link_WebAssembly lit complication (looking for an external wasm-ld), which I haven't gotten rid of yet.
Based on WASI.