What does HackerNews think of wasi-sdk?

WASI-enabled WebAssembly C/C++ toolchain

Language: Shell

There is the WASI SDK if you want to target WASI from C/C++:

https://github.com/WebAssembly/wasi-sdk

It comes with a libc implemented in WASM.

Just wrap the core functionality into a 'pure' WASM module which doesn't need to access 'system APIs', and then if needed write two thin wrappers, one for the 'web personality' and one for the 'WASI personality'.

WASI has the advantage that many compilers support it directly, e.g. in Zig:

    > cat hello.zig
    const print = @import("std").debug.print;
    pub fn main() void {
        print("Hello World!\n", .{});
    }

    > zig build-exe hello.zig -target wasm32-wasi
    > wasmtime hello.wasm
    Hello World!
Or if you prefer C:

    > cat hello.c
    #include 
    int main() {
        printf("Hello World!\n");
    }
    > zig cc hello.c -o hello.wasm -target wasm32-wasi
    > wasmtime hello.wasm
    Hello World!
(I guess Rust can do the same, or for a purely clang-based solution see: https://github.com/WebAssembly/wasi-sdk).

...while for web compatibility, you'll always need some sort of shim solution to talk to the Javascript APIs.

There's also the https://github.com/WebAssembly/wasi-sdk repo which is kind of a meta-build-system for all this.

But in FreeBSD we build all the pieces directly, here's our build recipes (with some hacks due to llvm's cmake code being stupid sometimes):

compiler-rt (from llvm): https://github.com/freebsd/freebsd-ports/blob/main/devel/was...

libc (from what you linked): https://github.com/freebsd/freebsd-ports/blob/main/devel/was...

libc++ (from llvm): https://github.com/freebsd/freebsd-ports/blob/main/devel/was...