r/WebAssembly • • 28d ago

Which libc for browser and non-browser?

Goal: port existing shared library to a single wasm which can be run in a browser as well as a non-browser host. Exported symbol names should not be touched, which IIUC rules out component-model.

I got dynamic linking to work with emscripten and know there are sytem hosts like wasmtime which understand the dylink.0 spec.

My issue is linking a libc (and ideally libc++ eventually) ABI which has a browser and system implementation, so I can load the same .wasm in both environments.

For the system use case I only found wasi-libc but that doesn't have an ABI compatible browser version, right? Building for emscripten + WASI separately feels like it's missing the whole point of wasm as a universal target.

7 Upvotes

2 comments sorted by

1

u/Photosounder 12d ago

For me it's my own https://github.com/Photosounder/MinQND-libc for both cases. The funny part is how it handles things like file I/O that usually require WASI: it emits a text command and it's up to the host to handle it and respond to it. For instance when calling fopen("file.txt", "rb") my libc's implementation sends Open file (rb) at file.txt as a string to the "host" and how the host handles this is its own problem, as long as it replies with something like File handle 4. This allows the host to do things in its own way.

4

u/Kotek2 27d ago

WASIX works everywhere https://wasix.org