1- # WASI Libc
1+ # ` wasi-libc `
22
3- WASI Libc is a libc for WebAssembly programs built on top of WASI system calls.
4- It provides a wide array of POSIX-compatible C APIs, including support for
5- standard I/O, file I/O, filesystem manipulation, memory management, time, string ,
6- environment variables, program startup, and many other APIs.
3+ ` wasi-libc ` is a libc for WebAssembly programs built on top of WASI system
4+ calls. It provides a wide array of POSIX-compatible C APIs, including support
5+ for standard I/O, file I/O, filesystem manipulation, memory management, time,
6+ string, environment variables, program startup, and many other APIs.
77
8- WASI Libc is sufficiently stable and usable for many purposes, as most of the
8+ ` wasi-libc ` is sufficiently stable and usable for many purposes, as most of the
99POSIX-compatible APIs are stable, though it is continuing to evolve to better
10- align with wasm and WASI. For example, pthread support is still a work in
11- progress.
10+ align with wasm and WASI. For example, pthread support is experimentally
11+ provided via the [ wasi-threads] proposal.`
12+
13+ [ wasi-threads ] : https://github.com/WebAssembly/wasi-threads
1214
1315## Usage
1416
1517The easiest way to get started with this is to use [ wasi-sdk] , which includes a
16- build of WASI Libc in its sysroot.
18+ build of ` wasi-libc ` in its sysroot.
1719
1820## Building from source
1921
2022To build a WASI sysroot from source, obtain a WebAssembly-supporting C compiler
21- (currently this is only clang 10+, though we'd like to support other compilers as well),
22- and then run:
23+ (currently this is only clang 10+, though we'd like to support other compilers
24+ as well), and then run:
2325
2426``` sh
2527make CC=/path/to/clang/with/wasm/support \
2628 AR=/path/to/llvm-ar \
2729 NM=/path/to/llvm-nm
2830```
2931
30- This makes a directory called "sysroot", by default. See the top of the Makefile
32+ This makes a directory called "sysroot" by default. See the top of the Makefile
3133for customization options.
3234
3335To use the sysroot, use the ` --sysroot= ` option:
@@ -39,10 +41,17 @@ To use the sysroot, use the `--sysroot=` option:
3941to run the compiler using the newly built sysroot.
4042
4143Note that Clang packages typically don't include cross-compiled builds of
42- compiler-rt, libcxx, or libcxxabi, for ` libclang_rt.builtins-wasm32.a ` , libc++.a,
43- or libc++abi.a, respectively, so they may not be usable without
44+ compiler-rt, libcxx, or libcxxabi, for ` libclang_rt.builtins-wasm32.a ` ,
45+ ` libc++.a ` , or ` libc++abi.a ` , respectively, so they may not be usable without
4446extra setup. This is one of the things [ wasi-sdk] simplifies, as it includes
45- cross-compiled builds of compiler-rt, libc++.a, and libc++abi.a.
47+ cross-compiled builds of compiler-rt, ` libc++.a ` , and ` libc++abi.a ` .
48+
49+ ## Building in pthread support
50+
51+ To enable pthreads support via the [ wasi-threads] proposal, follow the above
52+ build directions with one addition: ` make ... THREAD_MODEL=posix ` . This creates
53+ additional artifacts in ` sysroot/lib/wasm32-wasi-threads ` to support `--target
54+ wasm32-wasi-threads`.
4655
4756## Arch Linux AUR package
4857
0 commit comments