Skip to content

Commit 93743ca

Browse files
committed
Update bindings for the wasm32-wasi target
This commit performs a number of updates for libc with the `wasm32-wasi` target: * Updates the `wasi-libc` repository commit used (previously known as `wasi-sysroot`) * Updates the container to Ubuntu 19.10 which has Clang 9 packaged which is all we need. * Avoids building `wasmtime` and instead downloads a precompiled binary. * Updates bindings in `src/wasi.rs` to match the current upstream state.
1 parent 4f11029 commit 93743ca

File tree

5 files changed

+28
-81
lines changed

5 files changed

+28
-81
lines changed

ci/docker/wasm32-wasi/Dockerfile

Lines changed: 14 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,39 @@
1-
# In the first container we want to assemble the `wasi-sysroot` by compiling it
2-
# from source. This requires a clang 8.0+ compiler with enough wasm support and
3-
# then we're just running a standard `make` inside of what we clone.
4-
FROM ubuntu:18.04 as wasi-sysroot
1+
FROM ubuntu:19.10
52

63
RUN apt-get update && \
74
apt-get install -y --no-install-recommends \
85
ca-certificates \
96
clang \
10-
cmake \
117
curl \
12-
g++ \
138
git \
149
libc6-dev \
15-
libclang-dev \
1610
make \
17-
ssh \
1811
xz-utils
1912

20-
# Fetch clang 8.0+ which is used to compile the wasi target and link our
21-
# programs together.
22-
RUN curl http://releases.llvm.org/8.0.0/clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz | tar xJf -
23-
RUN mv /clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-18.04 /wasmcc
24-
2513
# Note that we're using `git reset --hard` to pin to a specific commit for
2614
# verification for now. The sysroot is currently in somewhat of a state of flux
2715
# and is expected to have breaking changes, so this is an attempt to mitigate
2816
# those breaking changes on `libc`'s own CI
29-
RUN git clone https://github.com/CraneStation/wasi-sysroot && \
30-
cd wasi-sysroot && \
31-
git reset --hard eee6ee7566e26f2535eb6088c8494a112ff423b9
32-
RUN make -C wasi-sysroot install -j $(nproc) WASM_CC=/wasmcc/bin/clang INSTALL_DIR=/wasi-sysroot
33-
34-
# This is a small wrapper script which executes the actual clang binary in
35-
# `/wasmcc` and then is sure to pass the right `--sysroot` argument which we
36-
# just built above.
37-
COPY docker/wasm32-wasi/clang.sh /wasi-sysroot/bin/clang
38-
39-
# In the second container we're going to build the `wasmtime` binary which is
40-
# used to execute wasi executables. This is a standard Rust project so we're
41-
# just checking out a known revision (which pairs with the sysroot one we
42-
# downlaoded above) and then we're building it with Cargo
43-
FROM ubuntu:18.04 as wasmtime
17+
RUN git clone https://github.com/CraneStation/wasi-libc && \
18+
cd wasi-libc && \
19+
git reset --hard f645f498dfbbbc00a7a97874d33082d3605c3f21
20+
RUN apt-get install -y --no-install-recommends llvm
21+
RUN make -C wasi-libc install -j $(nproc) INSTALL_DIR=/wasi-libc
4422

45-
RUN apt-get update && \
46-
apt-get install -y --no-install-recommends \
47-
ca-certificates \
48-
clang \
49-
cmake \
50-
curl \
51-
g++ \
52-
git \
53-
libclang-dev \
54-
make \
55-
ssh
56-
57-
RUN curl -sSf https://sh.rustup.rs | sh -s -- -y
58-
ENV PATH=/root/.cargo/bin:$PATH
59-
60-
RUN apt-get install -y --no-install-recommends python
61-
RUN git clone --recursive https://github.com/CraneStation/wasmtime wasmtime && \
62-
cd wasmtime && \
63-
git reset --hard a2647878977726935c3d04c05cabad9607ec7606
64-
RUN cargo build --release --manifest-path wasmtime/Cargo.toml
65-
66-
# And finally in the last image we're going to assemble everything together.
67-
# We'll install things needed at runtime for now and then copy over the
68-
# sysroot/wasmtime artifacts into their final location.
69-
FROM ubuntu:18.04
70-
71-
RUN apt-get update && \
72-
apt-get install -y --no-install-recommends \
73-
gcc \
74-
libc6-dev \
75-
libxml2 \
76-
ca-certificates
23+
RUN curl -L https://github.com/bytecodealliance/wasmtime/releases/download/dev/wasmtime-dev-x86_64-linux.tar.xz | \
24+
tar xJf -
25+
ENV PATH=$PATH:/wasmtime-dev-x86_64-linux
26+
COPY docker/wasm32-wasi/clang.sh /wasi-libc/bin/clang
7727

78-
# Copy over clang we downloaded to link executables ...
79-
COPY --from=wasi-sysroot /wasmcc /wasmcc/
80-
# ... and the sysroot we built to link executables against ...
81-
COPY --from=wasi-sysroot /wasi-sysroot/ /wasi-sysroot/
82-
# ... and finally wasmtime to actually execute binaries
83-
COPY --from=wasmtime /wasmtime/target/release/wasmtime /usr/bin/
28+
RUN apt-get install -y --no-install-recommends lld
29+
ENV PATH=$PATH:/usr/lib/llvm-9/bin
8430

8531
# Of note here is our clang wrapper which just executes a normal clang
8632
# executable with the right sysroot, and then we're sure to turn off the
8733
# crt-static feature to ensure that the CRT that we're specifying with `clang`
8834
# is used.
8935
ENV CARGO_TARGET_WASM32_WASI_RUNNER=wasmtime \
90-
CARGO_TARGET_WASM32_WASI_LINKER=/wasi-sysroot/bin/clang \
91-
CC_wasm32_wasi=/wasi-sysroot/bin/clang \
36+
CARGO_TARGET_WASM32_WASI_LINKER=/wasi-libc/bin/clang \
37+
CC_wasm32_wasi=/wasi-libc/bin/clang \
9238
PATH=$PATH:/rust/bin \
9339
RUSTFLAGS=-Ctarget-feature=-crt-static

ci/docker/wasm32-wasi/clang.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
#!/usr/bin/env sh
2-
exec /wasmcc/bin/clang --target=wasm32-wasi --sysroot /wasi-sysroot "$@"
2+
exec /usr/bin/clang --target=wasm32-wasi --sysroot /wasi-libc/sysroot "$@"

ci/run.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ if [ "$TARGET" = "x86_64-unknown-linux-gnux32" ]; then
8989
opt="--release"
9090
fi
9191

92-
cargo test -vv $opt --no-default-features --manifest-path libc-test/Cargo.toml \
92+
cargo test $opt --no-default-features --manifest-path libc-test/Cargo.toml \
9393
--target "${TARGET}"
9494

95-
cargo test -vv $opt --manifest-path libc-test/Cargo.toml --target "${TARGET}"
95+
cargo test $opt --manifest-path libc-test/Cargo.toml --target "${TARGET}"
9696

97-
cargo test -vv $opt --features extra_traits --manifest-path libc-test/Cargo.toml \
97+
cargo test $opt --features extra_traits --manifest-path libc-test/Cargo.toml \
9898
--target "${TARGET}"

libc-test/build.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1182,7 +1182,7 @@ fn test_wasi(target: &str) {
11821182
"sys/utsname.h",
11831183
"time.h",
11841184
"unistd.h",
1185-
"wasi/core.h",
1185+
"wasi/api.h",
11861186
"wasi/libc.h",
11871187
"wasi/libc-find-relpath.h",
11881188
"wchar.h",
@@ -1218,6 +1218,10 @@ fn test_wasi(target: &str) {
12181218
// doesn't support sizeof.
12191219
cfg.skip_field(|s, field| s == "dirent" && field == "d_name");
12201220

1221+
// Currently Rust/clang disagree on function argument ABI, so skip these
1222+
// tests. For more info see WebAssembly/tool-conventions#88
1223+
cfg.skip_roundtrip(|_| true);
1224+
12211225
cfg.generate("../src/lib.rs", "main.rs");
12221226
}
12231227

src/wasi.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,9 @@ pub const EXIT_FAILURE: c_int = 1;
174174
pub const STDIN_FILENO: c_int = 0;
175175
pub const STDOUT_FILENO: c_int = 1;
176176
pub const STDERR_FILENO: c_int = 2;
177-
pub const SEEK_SET: c_int = 2;
178-
pub const SEEK_CUR: c_int = 0;
179-
pub const SEEK_END: c_int = 1;
177+
pub const SEEK_SET: c_int = 0;
178+
pub const SEEK_CUR: c_int = 1;
179+
pub const SEEK_END: c_int = 2;
180180
pub const _IOFBF: c_int = 0;
181181
pub const _IONBF: c_int = 2;
182182
pub const _IOLBF: c_int = 1;
@@ -207,8 +207,8 @@ pub const AT_EACCESS: c_int = 0x0;
207207
pub const AT_SYMLINK_NOFOLLOW: c_int = 0x1;
208208
pub const AT_SYMLINK_FOLLOW: c_int = 0x2;
209209
pub const AT_REMOVEDIR: c_int = 0x4;
210-
pub const UTIME_OMIT: c_long = 1073741822;
211-
pub const UTIME_NOW: c_long = 1073741823;
210+
pub const UTIME_OMIT: c_long = 0xfffffffe;
211+
pub const UTIME_NOW: c_long = 0xffffffff;
212212

213213
pub const E2BIG: c_int = 1;
214214
pub const EACCES: c_int = 2;
@@ -728,11 +728,8 @@ extern "C" {
728728
pub fn __wasilibc_fd_renumber(fd: c_int, newfd: c_int) -> c_int;
729729
pub fn __wasilibc_unlinkat(fd: c_int, path: *const c_char) -> c_int;
730730
pub fn __wasilibc_rmdirat(fd: c_int, path: *const c_char) -> c_int;
731-
pub fn __wasilibc_init_preopen();
732731
pub fn __wasilibc_find_relpath(
733732
path: *const c_char,
734-
rights_base: __wasi_rights_t,
735-
rights_inheriting: __wasi_rights_t,
736733
relative_path: *mut *const c_char,
737734
) -> c_int;
738735
pub fn __wasilibc_tell(fd: c_int) -> ::off_t;

0 commit comments

Comments
 (0)