From acd7ad8defd70d7cd5c24cc9bd7ef7264400c400 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Mon, 6 May 2019 10:14:13 -0700 Subject: [PATCH] Update to the latest wasi-sysroot. - Rename `wasm32-unknown-wasi` to `wasm32-wasi`. - `__wasilibc_rmfileat` was renamed to `__wasilibc_unlinkat` - Add bindings for a few more functions and typedefs. --- ci/docker/wasm32-unknown-wasi/clang.sh | 2 -- .../Dockerfile | 14 ++++++------- ci/docker/wasm32-wasi/clang.sh | 2 ++ libc-test/build.rs | 1 + src/wasi.rs | 20 ++++++++++++++++++- 5 files changed, 29 insertions(+), 10 deletions(-) delete mode 100755 ci/docker/wasm32-unknown-wasi/clang.sh rename ci/docker/{wasm32-unknown-wasi => wasm32-wasi}/Dockerfile (87%) create mode 100755 ci/docker/wasm32-wasi/clang.sh diff --git a/ci/docker/wasm32-unknown-wasi/clang.sh b/ci/docker/wasm32-unknown-wasi/clang.sh deleted file mode 100755 index a943e3782334e..0000000000000 --- a/ci/docker/wasm32-unknown-wasi/clang.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/usr/bin/env sh -exec /wasmcc/bin/clang --target=wasm32-unknown-wasi --sysroot /wasi-sysroot "$@" diff --git a/ci/docker/wasm32-unknown-wasi/Dockerfile b/ci/docker/wasm32-wasi/Dockerfile similarity index 87% rename from ci/docker/wasm32-unknown-wasi/Dockerfile rename to ci/docker/wasm32-wasi/Dockerfile index deac87a69305e..d963a442c86bb 100644 --- a/ci/docker/wasm32-unknown-wasi/Dockerfile +++ b/ci/docker/wasm32-wasi/Dockerfile @@ -28,13 +28,13 @@ 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 2201343c17b7149a75f543f523bea0c3243c6091 + git reset --hard eee6ee7566e26f2535eb6088c8494a112ff423b9 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 # `/wasmcc` and then is sure to pass the right `--sysroot` argument which we # just built above. -COPY docker/wasm32-unknown-wasi/clang.sh /wasi-sysroot/bin/clang +COPY docker/wasm32-wasi/clang.sh /wasi-sysroot/bin/clang # In the second container we're going to build the `wasmtime` binary which is # used to execute wasi executables. This is a standard Rust project so we're @@ -58,9 +58,9 @@ RUN curl -sSf https://sh.rustup.rs | sh -s -- -y ENV PATH=/root/.cargo/bin:$PATH RUN apt-get install -y --no-install-recommends python -RUN git clone https://github.com/CraneStation/wasmtime wasmtime && \ +RUN git clone --recursive https://github.com/CraneStation/wasmtime wasmtime && \ cd wasmtime && \ - git reset --hard a1c123c3dd8f9766990efe0f1734a646f61ba8a0 + git reset --hard 67edb00f29b62864b00179fe4bfa99bc29973285 RUN cargo build --release --manifest-path wasmtime/Cargo.toml # And finally in the last image we're going to assemble everything together. @@ -86,8 +86,8 @@ COPY --from=wasmtime /wasmtime/target/release/wasmtime /usr/bin/ # executable with the right sysroot, and then we're sure to turn off the # crt-static feature to ensure that the CRT that we're specifying with `clang` # is used. -ENV CARGO_TARGET_WASM32_UNKNOWN_WASI_RUNNER=wasmtime \ - CARGO_TARGET_WASM32_UNKNOWN_WASI_LINKER=/wasi-sysroot/bin/clang \ - CC_wasm32_unknown_wasi=/wasi-sysroot/bin/clang \ +ENV CARGO_TARGET_WASM32_WASI_RUNNER=wasmtime \ + CARGO_TARGET_WASM32_WASI_LINKER=/wasi-sysroot/bin/clang \ + CC_wasm32_wasi=/wasi-sysroot/bin/clang \ PATH=$PATH:/rust/bin \ RUSTFLAGS=-Ctarget-feature=-crt-static diff --git a/ci/docker/wasm32-wasi/clang.sh b/ci/docker/wasm32-wasi/clang.sh new file mode 100755 index 0000000000000..6f298128ab8c3 --- /dev/null +++ b/ci/docker/wasm32-wasi/clang.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env sh +exec /wasmcc/bin/clang --target=wasm32-wasi --sysroot /wasi-sysroot "$@" diff --git a/libc-test/build.rs b/libc-test/build.rs index aba2a3056852c..08bc44127d0cc 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -1883,6 +1883,7 @@ fn test_wasi(target: &str) { "locale.h", "malloc.h", "poll.h", + "sched.h", "stdbool.h", "stddef.h", "stdint.h", diff --git a/src/wasi.rs b/src/wasi.rs index a014e4c0fa330..b93486129f046 100644 --- a/src/wasi.rs +++ b/src/wasi.rs @@ -10,8 +10,13 @@ pub type c_long = i32; pub type c_ulong = u32; pub type c_longlong = i64; pub type c_ulonglong = u64; +pub type intmax_t = i64; +pub type uintmax_t = u64; pub type size_t = usize; pub type ssize_t = isize; +pub type ptrdiff_t = isize; +pub type intptr_t = isize; +pub type uintptr_t = usize; pub type off_t = i64; pub type pid_t = i32; pub type int8_t = i8; @@ -619,11 +624,13 @@ extern { pub fn getenv(s: *const c_char) -> *mut c_char; pub fn malloc(amt: size_t) -> *mut c_void; pub fn malloc_usable_size(ptr: *mut c_void) -> size_t; + pub fn sbrk(increment: ::intptr_t) -> *mut ::c_void; pub fn rand() -> c_int; pub fn read(fd: c_int, ptr: *mut c_void, size: size_t) -> ssize_t; pub fn realloc(ptr: *mut c_void, amt: size_t) -> *mut c_void; pub fn setenv(k: *const c_char, v: *const c_char, a: c_int) -> c_int; pub fn unsetenv(k: *const c_char) -> c_int; + pub fn clearenv() -> ::c_int; pub fn write(fd: c_int, ptr: *const c_void, size: size_t) -> ssize_t; pub static mut environ: *mut *mut c_char; pub fn fopen(a: *const c_char, b: *const c_char) -> *mut FILE; @@ -724,6 +731,7 @@ extern { pub fn fgets(buf: *mut c_char, n: c_int, stream: *mut FILE) -> *mut c_char; pub fn atoi(s: *const c_char) -> c_int; + pub fn atof(s: *const c_char) -> c_double; pub fn strtod(s: *const c_char, endp: *mut *mut c_char) -> c_double; pub fn strtol( s: *const c_char, @@ -822,6 +830,7 @@ extern { pub fn readdir(dirp: *mut ::DIR) -> *mut ::dirent; pub fn closedir(dirp: *mut ::DIR) -> ::c_int; pub fn rewinddir(dirp: *mut ::DIR); + pub fn dirfd(dirp: *mut ::DIR) -> ::c_int; pub fn openat( dirfd: ::c_int, @@ -902,9 +911,11 @@ extern { pub fn lstat(path: *const c_char, buf: *mut stat) -> ::c_int; pub fn fsync(fd: ::c_int) -> ::c_int; + pub fn fdatasync(fd: ::c_int) -> ::c_int; pub fn symlink(path1: *const c_char, path2: *const c_char) -> ::c_int; + pub fn truncate(path: *const c_char, length: off_t) -> ::c_int; pub fn ftruncate(fd: ::c_int, length: off_t) -> ::c_int; pub fn getrusage(resource: ::c_int, usage: *mut rusage) -> ::c_int; @@ -954,6 +965,11 @@ extern { whence: ::c_int, ) -> ::c_int; pub fn ftello(stream: *mut ::FILE) -> ::off_t; + pub fn posix_fallocate( + fd: ::c_int, + offset: ::off_t, + len: ::off_t, + ) -> ::c_int; pub fn strcasestr(cs: *const c_char, ct: *const c_char) -> *mut c_char; pub fn getline( @@ -1019,13 +1035,14 @@ extern { base: ::locale_t, ) -> ::locale_t; pub fn uselocale(loc: ::locale_t) -> ::locale_t; + pub fn sched_yield() -> ::c_int; pub fn __wasilibc_register_preopened_fd( fd: c_int, path: *const c_char, ) -> c_int; pub fn __wasilibc_fd_renumber(fd: c_int, newfd: c_int) -> c_int; - pub fn __wasilibc_rmfileat(fd: c_int, path: *const c_char) -> c_int; + pub fn __wasilibc_unlinkat(fd: c_int, path: *const c_char) -> c_int; pub fn __wasilibc_rmdirat(fd: c_int, path: *const c_char) -> c_int; pub fn __wasilibc_init_preopen(); pub fn __wasilibc_find_relpath( @@ -1034,6 +1051,7 @@ extern { rights_inheriting: __wasi_rights_t, relative_path: *mut *const c_char, ) -> c_int; + pub fn __wasilibc_tell(fd: c_int) -> ::off_t; pub fn arc4random() -> u32; pub fn arc4random_buf(a: *mut c_void, b: size_t);