]>
Commit | Line | Data |
---|---|---|
94d34a13 | 1 | # WASI Libc |
dcf13b6f | 2 | |
c33ea73e DG |
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. | |
dcf13b6f | 7 | |
c33ea73e DG |
8 | WASI Libc is sufficiently stable and usable for many purposes, as most of the |
9 | POSIX-compatible APIs are stable, though it is continuing to evolve to better | |
dcd28cf8 AB |
10 | align with wasm and WASI. For example, pthread support is still a work in |
11 | progress. | |
dcf13b6f DG |
12 | |
13 | ## Usage | |
14 | ||
c33ea73e DG |
15 | The easiest way to get started with this is to use [wasi-sdk], which includes a |
16 | build of WASI Libc in its sysroot. | |
320054e8 DG |
17 | |
18 | ## Building from source | |
19 | ||
20 | To build a WASI sysroot from source, obtain a WebAssembly-supporting C compiler | |
7a21011e | 21 | (currently this is only clang 10+, though we'd like to support other compilers as well), |
320054e8 | 22 | and then run: |
dcf13b6f | 23 | |
b1e234b6 | 24 | ```sh |
9e09e02a | 25 | make CC=/path/to/clang/with/wasm/support \ |
9eb4a995 | 26 | AR=/path/to/llvm-ar \ |
a279514a | 27 | NM=/path/to/llvm-nm |
dcf13b6f DG |
28 | ``` |
29 | ||
c9850bfd | 30 | This makes a directory called "sysroot", by default. See the top of the Makefile |
dcf13b6f DG |
31 | for customization options. |
32 | ||
33 | To use the sysroot, use the `--sysroot=` option: | |
34 | ||
b1e234b6 | 35 | ```sh |
dcf13b6f | 36 | /path/to/wasm/supporting/c/compiler --sysroot=/path/to/the/newly/built/sysroot ... |
f2049d9b | 37 | ``` |
dcf13b6f DG |
38 | |
39 | to run the compiler using the newly built sysroot. | |
c33ea73e DG |
40 | |
41 | Note that Clang packages typically don't include cross-compiled builds of | |
42e6901e DG |
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 | |
c33ea73e | 44 | extra setup. This is one of the things [wasi-sdk] simplifies, as it includes |
42e6901e | 45 | cross-compiled builds of compiler-rt, libc++.a, and libc++abi.a. |
c33ea73e | 46 | |
ca4d2f0c ZL |
47 | ## Arch Linux AUR package |
48 | For Arch Linux users, there's an unofficial AUR package tracking this git repo that can be installed under the name [wasi-libc-git]. | |
b6390079 | 49 | |
c33ea73e | 50 | [wasi-sdk]: https://github.com/WebAssembly/wasi-sdk |
b6390079 | 51 | [wasi-libc-git]: https://aur.archlinux.org/packages/wasi-libc-git/ |