Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any example or documentation how to run it in browser? #235

Open
fsmoke opened this issue May 15, 2022 · 5 comments
Open

Any example or documentation how to run it in browser? #235

fsmoke opened this issue May 15, 2022 · 5 comments

Comments

@fsmoke
Copy link

fsmoke commented May 15, 2022

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

@pmp-p
Copy link

pmp-p commented May 15, 2022

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/

@sbc100
Copy link
Member

sbc100 commented May 16, 2022

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.

@spirobel
Copy link

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

@toyobayashi
Copy link

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.

@guest271314
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants