Open fsmoke opened 2 years ago
You would need a Wasi web polyfill that provide all the syscalls you are using at runtime. like https://wasi.dev/polyfill/ ( could be very outdated ) and as an example https://pmp-p.github.io/wasi/
If you are targeting the web then emscripten is really you best bet today. wasi-sdk it not really designed to target the web, at last not today.
emscripten's output can be very small or very large depending on what features you use. You pay for what you use the compiler has good dead code elimination at -Os
or Oz
. For example a simple hello_world program is just a few bytes of JS and few bytes of Wasm.
In terms of supporting memory allocation, the allocator used in wasi-libc and emscripten is the same by default (dlmalloc). You can avoid malloc and free in both cases, but if your program depends on an allocator (indirectly) it will have roughly the same codesize cost in both wasi-sdk and emscripten.
I found this package that looks very interesting: https://github.com/qrdate/tinywasi the code is easy to read. take a look: https://github.com/qrdate/tinywasi/blob/main/src/TinyWASI.ts
You are looking for https://github.com/toyobayashi/wasm-util/blob/23117669ac178ea9b693b5b20d87f89be232a31e/src/wasi/preview1.ts
WASI polyfill for browser, written in pure JS, compatible with Node.js WASI API.
If you are targeting the web then emscripten is really you best bet today. wasi-sdk it not really designed to target the web, at last not today.
Fascinating. That just saved me asking a question here. I was going the try to use the WASI-SDK I downloaded instead of downloading Emscripten, which results in the temporary file system I am building on running out of disk space during downloading.
WASI-SDK is great, and it's good to understand that Emscripten is more application level, and WASI-SDK is more system level. So if you are build a library, better to link against libc/++ that everybody knows and allows the program hierarchy to provide the needed functions. I wonder, has anybody tried combining browsix with wasi-sdk and making a formal build server out of it all inside a web browser?
I want use wasi-sdk as backend c++ compiler/std-libraries to build my little library. Emscripten it seems too huge and highweight for my tasks. So I need just build library as wasm with supporting memory allocation(new/delete) and run functions from this library from javascript inside browser's page.
But i spent already many time to find normal tutorial: "from beginning to the end" - but found only very very scattered information with different technologies and libraries....
Is there any normal documentation: how can i just build c++ libarary with wasi-sdk and call it's functions from pure js ???
PS I am very new in wasm - so sorry for may be dumb questions