Currently wasm32-wasi target is tied to the libc implementation for compatibility with C/C++ code. But for pure-Rust applications C environment is unnecessary and causes a certain bloat of resulting binaries.
For example a very simple code like this:
fn main() {
let mut buf = [0u8; 4];
unsafe {
let _ = wasi::random_get(buf.as_mut_ptr(), buf.len());
let c = wasi::Ciovec { buf: buf.as_mut_ptr(), buf_len: buf.len() };
let _ = wasi::fd_write(1, &[c]);
}
}
Gets compiled into a 64 KB binary (after strip), I guess a significant amount of which has to do with correctly setting up and destroying C environment.
Thus it could be beneficial to add a target like wasm32-wasi-rust intended for pure-Rust WASI applications. Most of the preliminary work has been already done and dependence of wasm32-wasi on libc is minimal (allocator and environment functions, abort, exit, __wasilibc_find_relpath), so IIUC addition of such target should be relatively simple. Depending on the rate of WASI evolution, such addition could be postponed until a certain level of stabilization to reduce maintenance burden.
Previously it was proposed in #63676.
cc @alexcrichton @sunfishcode
Currently
wasm32-wasitarget is tied to thelibcimplementation for compatibility with C/C++ code. But for pure-Rust applications C environment is unnecessary and causes a certain bloat of resulting binaries.For example a very simple code like this:
Gets compiled into a 64 KB binary (after strip), I guess a significant amount of which has to do with correctly setting up and destroying C environment.
Thus it could be beneficial to add a target like
wasm32-wasi-rustintended for pure-Rust WASI applications. Most of the preliminary work has been already done and dependence ofwasm32-wasionlibcis minimal (allocator and environment functions,abort,exit,__wasilibc_find_relpath), so IIUC addition of such target should be relatively simple. Depending on the rate of WASI evolution, such addition could be postponed until a certain level of stabilization to reduce maintenance burden.Previously it was proposed in #63676.
cc @alexcrichton @sunfishcode