3 ms·
> C without the standard library (called “libc”) is pretty rough If you don't want to pull in musl or a traditional libc, there's a more Wasm-y solution known
by _nhynes 7y ago
> C without the standard library (called “libc”) is pretty rough
If you don't want to pull in musl or a traditional libc, there's a more Wasm-y solution known as the Web Assembly System Interface (WASI) [0] that delegates the libc functionality to the runtime.
A WASI Wasm module can be compiled using clang, as in the article. The only difference is to use the WASI sysroot [1].
> optimization
LTO and -O3 are great! I've also found the Twiggy [2] tool useful for more "manual" optimization.
[0] https://wasi.dev https://wasi.dev
[1] https://github.com/CraneStation/wasi-sdk/releases https://github.com/CraneStation/wasi-sdk/releases
[2] https://rustwasm.github.io/twiggy/ https://rustwasm.github.io/twiggy/
- swolchok 7y ago> -O3 If size is really important, you probably want to try -Os (optimize for size) and -Oz (try harder to optimize for size, including at the expense of CPU) as well. > LTO If your project gets big enough that -flto results in unacceptable link times, try -flto=thin.
- s-macke 7y agoI just created a code snippet in C [1] which prints hello world by using the (bare-metal) WASI interface. No headers included. The compiled wasm file works with wasmer, lucet, wasmtime and an web implementation of WASI [2] [1] https://gist.github.com/s-macke/6dd78c78be46214d418454abb667a1ba https://gist.github.com/s-macke/6dd78c78be46214d418454abb667... [2] https://wasi.dev/polyfill/ https://wasi.dev/polyfill/
- monocasa 7y agoOne of the things I like about Rust as an embedded developer is that they make a distinction between core and std portions of the standard library. Core is everything that only depends on memset, memcpy, and memcmp,.which means you know you get it for free on new ports.
- dassurma 7y agoAuthor here :) I am very excited about WASI, but as I mentioned in a comment below, wanted to keep it to the fundamentals so you can appreciate what WASI does for you. And definitely agree with the shout-out to Twiggy (which I mention in the previous post in the series)!
- ngcc_hk 7y agoTotally agreed. Just may be the next step is like rust to have core and std so some minimum subset would be used. But without this option still excellent.