Skip to content

Commit

Permalink
Auto merge of #1325 - sunfishcode:wasi-more-libc, r=alexcrichton
Browse files Browse the repository at this point in the history
Add more WASI libc bindings

This picks up #1321, adding more WASI libc bindings, adding several more fixes. In particular, `cargo test --all` including libc-test now builds successfully.
  • Loading branch information
bors committed Apr 25, 2019
2 parents fa186bb + 13ddc16 commit 0ec9af9
Show file tree
Hide file tree
Showing 4 changed files with 555 additions and 9 deletions.
2 changes: 1 addition & 1 deletion ci/docker/wasm32-unknown-wasi/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ RUN mv /clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-18.04 /wasmcc
# those breaking changes on `libc`'s own CI
RUN git clone https://github.com/CraneStation/wasi-sysroot && \
cd wasi-sysroot && \
git reset --hard e5f14be38362f1ab83302895a6e74b2ffd0e2302
git reset --hard 2201343c17b7149a75f543f523bea0c3243c6091
RUN make -C wasi-sysroot install -j $(nproc) WASM_CC=/wasmcc/bin/clang INSTALL_DIR=/wasi-sysroot

# This is a small wrapper script which executes the actual clang binary in
Expand Down
17 changes: 16 additions & 1 deletion libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1875,17 +1875,28 @@ fn test_wasi(target: &str) {
cfg.define("_GNU_SOURCE", None);

headers! { cfg:
"ctype.h",
"dirent.h",
"errno.h",
"fcntl.h",
"limits.h",
"locale.h",
"malloc.h",
"poll.h",
"stdbool.h",
"stddef.h",
"stdint.h",
"stdio.h",
"stdlib.h",
"string.h",
"sys/resource.h",
"sys/select.h",
"sys/socket.h",
"sys/stat.h",
"sys/times.h",
"sys/types.h",
"sys/uio.h",
"sys/utsname.h",
"time.h",
"unistd.h",
"wasi/core.h",
Expand All @@ -1895,7 +1906,7 @@ fn test_wasi(target: &str) {
}

cfg.type_name(move |ty, is_struct, is_union| match ty {
"FILE" => ty.to_string(),
"FILE" | "fd_set" | "DIR" => ty.to_string(),
t if is_union => format!("union {}", t),
t if t.starts_with("__wasi") && t.ends_with("_u") => {
format!("union {}", t)
Expand All @@ -1920,5 +1931,9 @@ fn test_wasi(target: &str) {
// import the same thing but have different function pointers
cfg.skip_fn_ptrcheck(|f| f.starts_with("__wasi"));

// d_name is declared as a flexible array in WASI libc, so it
// doesn't support sizeof.
cfg.skip_field(|s, field| s == "dirent" && field == "d_name");

cfg.generate("../src/lib.rs", "main.rs");
}
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ cfg_if! {
} else if #[cfg(all(target_env = "sgx", target_vendor = "fortanix"))] {
mod sgx;
pub use sgx::*;
} else if #[cfg(target_env = "wasi")] {
} else if #[cfg(any(target_env = "wasi", target_os = "wasi"))] {
mod wasi;
pub use wasi::*;
} else {
Expand Down
Loading

0 comments on commit 0ec9af9

Please sign in to comment.