Skip to content

Add a pure Rust WASI target? #73432

Closed
Closed
@newpavlov

Description

@newpavlov

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-feature-requestCategory: A feature request, i.e: not implemented / a PR.O-wasmTarget: WASM (WebAssembly), http://webassembly.org/

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions