From 3f1e8b9c457343402fc733eb7649d3e218788151 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 5 Apr 2019 08:03:03 -0700 Subject: [PATCH 1/2] Enable the wasi target on CI Now that wasi is in nightlies, we can run it on PRs! --- .travis.yml | 3 +++ ci/docker/wasm32-unknown-wasi/Dockerfile | 10 +++++----- src/wasi.rs | 21 ++++++++++++--------- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/.travis.yml b/.travis.yml index d56112a3..7175ae4a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -204,6 +204,9 @@ matrix: stage: tier2 - env: TARGET=x86_64-unknown-linux-musl stage: tier2 + - env: TARGET=wasm32-unknown-wasi + rust: nightly + stage: tier2 allow_failures: # FIXME: android build bots time out irregularly diff --git a/ci/docker/wasm32-unknown-wasi/Dockerfile b/ci/docker/wasm32-unknown-wasi/Dockerfile index b09cacb6..1017d369 100644 --- a/ci/docker/wasm32-unknown-wasi/Dockerfile +++ b/ci/docker/wasm32-unknown-wasi/Dockerfile @@ -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 320054e84f8f2440def3b1c8700cedb8fd697bf8 + git reset --hard 3ca44511c298cbbc99e690b761310070b3527fe8 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 @@ -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-wasi wasmtime && \ +RUN git clone https://github.com/CraneStation/wasmtime wasmtime && \ cd wasmtime && \ - git reset --hard 4fe2d6084e5b5cc74e69a26860f12750df51d339 + git reset --hard a1c123c3dd8f9766990efe0f1734a646f61ba8a0 RUN cargo build --release --manifest-path wasmtime/Cargo.toml # And finally in the last image we're going to assemble everything together. @@ -75,9 +75,9 @@ RUN apt-get update && \ libxml2 # Copy over clang we downloaded to link executables ... -COPY --from=reference-sysroot /wasmcc /wasmcc/ +COPY --from=wasi-sysroot /wasmcc /wasmcc/ # ... and the sysroot we built to link executables against ... -COPY --from=reference-sysroot /wasi-sysroot/ /wasi-sysroot/ +COPY --from=wasi-sysroot /wasi-sysroot/ /wasi-sysroot/ # ... and finally wasmtime to actually execute binaries COPY --from=wasmtime /wasmtime/target/release/wasmtime /usr/bin/ diff --git a/src/wasi.rs b/src/wasi.rs index 13af0b53..6fd3736c 100644 --- a/src/wasi.rs +++ b/src/wasi.rs @@ -388,12 +388,15 @@ pub const __WASI_WHENCE_CUR: u8 = 0; pub const __WASI_WHENCE_END: u8 = 1; pub const __WASI_WHENCE_SET: u8 = 2; -#[cfg_attr(feature = "rustc-dep-of-std", - link(name = "c", kind = "static", - cfg(target_feature = "crt-static")))] -#[cfg_attr(feature = "rustc-dep-of-std", - link(name = "c", cfg(not(target_feature = "crt-static"))))] -extern { +#[cfg_attr( + feature = "rustc-dep-of-std", + link(name = "c", kind = "static", cfg(target_feature = "crt-static")) +)] +#[cfg_attr( + feature = "rustc-dep-of-std", + link(name = "c", cfg(not(target_feature = "crt-static"))) +)] +extern "C" { pub fn _Exit(code: c_int) -> !; pub fn _exit(code: c_int) -> !; pub fn abort() -> !; @@ -452,8 +455,8 @@ extern { pub fn puts(a: *const c_char) -> c_int; pub fn perror(a: *const c_char); pub fn srand(a: c_uint); - pub fn atexit(a: extern fn()) -> c_int; - pub fn at_quick_exit(a: extern fn()) -> c_int; + pub fn atexit(a: extern "C" fn()) -> c_int; + pub fn at_quick_exit(a: extern "C" fn()) -> c_int; pub fn quick_exit(a: c_int) -> !; pub fn posix_memalign(a: *mut *mut c_void, b: size_t, c: size_t) -> c_int; pub fn rand_r(a: *mut c_uint) -> c_int; @@ -501,7 +504,7 @@ extern { } #[link(wasm_import_module = "wasi_unstable")] -extern { +extern "C" { #[link_name = "clock_res_get"] pub fn __wasi_clock_res_get( clock_id: __wasi_clockid_t, From cc0310146eb87ca1dee1c8d370be745bf5ad29fd Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 5 Apr 2019 08:06:18 -0700 Subject: [PATCH 2/2] Add binding for new `__wasilibc_find_relpath` API Added recently and will be used in libstd! --- ci/docker/wasm32-unknown-wasi/Dockerfile | 5 +++-- libc-test/build.rs | 1 + src/wasi.rs | 14 ++++++++++---- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/ci/docker/wasm32-unknown-wasi/Dockerfile b/ci/docker/wasm32-unknown-wasi/Dockerfile index 1017d369..6f464404 100644 --- a/ci/docker/wasm32-unknown-wasi/Dockerfile +++ b/ci/docker/wasm32-unknown-wasi/Dockerfile @@ -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 3ca44511c298cbbc99e690b761310070b3527fe8 + git reset --hard e5f14be38362f1ab83302895a6e74b2ffd0e2302 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 @@ -72,7 +72,8 @@ RUN apt-get update && \ apt-get install -y --no-install-recommends \ gcc \ libc6-dev \ - libxml2 + libxml2 \ + ca-certificates # Copy over clang we downloaded to link executables ... COPY --from=wasi-sysroot /wasmcc /wasmcc/ diff --git a/libc-test/build.rs b/libc-test/build.rs index 3d8ddce4..6419a3b0 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -1890,6 +1890,7 @@ fn test_wasi(target: &str) { "unistd.h", "wasi/core.h", "wasi/libc.h", + "wasi/libc-find-relpath.h", "wchar.h", } diff --git a/src/wasi.rs b/src/wasi.rs index 6fd3736c..77c48f50 100644 --- a/src/wasi.rs +++ b/src/wasi.rs @@ -396,7 +396,7 @@ pub const __WASI_WHENCE_SET: u8 = 2; feature = "rustc-dep-of-std", link(name = "c", cfg(not(target_feature = "crt-static"))) )] -extern "C" { +extern { pub fn _Exit(code: c_int) -> !; pub fn _exit(code: c_int) -> !; pub fn abort() -> !; @@ -455,8 +455,8 @@ extern "C" { pub fn puts(a: *const c_char) -> c_int; pub fn perror(a: *const c_char); pub fn srand(a: c_uint); - pub fn atexit(a: extern "C" fn()) -> c_int; - pub fn at_quick_exit(a: extern "C" fn()) -> c_int; + pub fn atexit(a: extern fn()) -> c_int; + pub fn at_quick_exit(a: extern fn()) -> c_int; pub fn quick_exit(a: c_int) -> !; pub fn posix_memalign(a: *mut *mut c_void, b: size_t, c: size_t) -> c_int; pub fn rand_r(a: *mut c_uint) -> c_int; @@ -497,6 +497,12 @@ extern "C" { pub fn __wasilibc_rmfileat(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( + path: *const c_char, + rights_base: __wasi_rights_t, + rights_inheriting: __wasi_rights_t, + relative_path: *mut *const c_char, + ) -> c_int; pub fn arc4random() -> u32; pub fn arc4random_buf(a: *mut c_void, b: size_t); @@ -504,7 +510,7 @@ extern "C" { } #[link(wasm_import_module = "wasi_unstable")] -extern "C" { +extern { #[link_name = "clock_res_get"] pub fn __wasi_clock_res_get( clock_id: __wasi_clockid_t,