Skip to content

Commit 6a600c5

Browse files
committed
Address some PR feedback
1 parent 87def1f commit 6a600c5

File tree

4 files changed

+54
-55
lines changed

4 files changed

+54
-55
lines changed

ci/docker/wasm32-unknown-wasi/Dockerfile

+37-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
FROM ubuntu:18.04 as reference-sysroot
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
25

36
RUN apt-get update && \
47
apt-get install -y --no-install-recommends \
@@ -14,15 +17,29 @@ RUN apt-get update && \
1417
ssh \
1518
xz-utils
1619

20+
# Fetch clang 8.0+ which is used to compile the wasi target and link our
21+
# programs together.
1722
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 -
1823
RUN mv /clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-18.04 /wasmcc
1924

20-
RUN git clone https://github.com/CraneStation/reference-sysroot-wasi && \
21-
cd reference-sysroot-wasi && \
22-
git reset --hard d5a609fe63926533e1054e539ba5f2693d51bdf5
23-
RUN make -C reference-sysroot-wasi install -j $(nproc) WASM_CC=/wasmcc/bin/clang INSTALL_DIR=/wasm-sysroot
24-
COPY docker/wasm32-unknown-wasi/clang.sh /wasm-sysroot/bin/clang
25+
# Note that we're using `git reset --hard` to pin to a specific commit for
26+
# verification for now. The sysroot is currently in somewhat of a state of flux
27+
# and is expected to have breaking changes, so this is an attempt to mitigate
28+
# 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 320054e84f8f2440def3b1c8700cedb8fd697bf8
32+
RUN make -C wasi-sysroot install -j $(nproc) WASM_CC=/wasmcc/bin/clang INSTALL_DIR=/wasi-sysroot
2533

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-unknown-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
2643
FROM ubuntu:18.04 as wasmtime
2744

2845
RUN apt-get update && \
@@ -43,13 +60,12 @@ ENV PATH=/root/.cargo/bin:$PATH
4360
RUN apt-get install -y --no-install-recommends python
4461
RUN git clone https://github.com/CraneStation/wasmtime-wasi wasmtime && \
4562
cd wasmtime && \
46-
git reset --hard a7ac05df74759a7536b2b1e30adc6ff4867e36c3
47-
48-
# Install wasmtime in /usr/bin, but make sure to remove rust afterwards because
49-
# we don't want it conflicting with the main Rust we're using to compile
50-
# `libc`.
63+
git reset --hard 4fe2d6084e5b5cc74e69a26860f12750df51d339
5164
RUN cargo build --release --manifest-path wasmtime/Cargo.toml
5265

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.
5369
FROM ubuntu:18.04
5470

5571
RUN apt-get update && \
@@ -58,12 +74,19 @@ RUN apt-get update && \
5874
libc6-dev \
5975
libxml2
6076

77+
# Copy over clang we downloaded to link executables ...
6178
COPY --from=reference-sysroot /wasmcc /wasmcc/
62-
COPY --from=reference-sysroot /wasm-sysroot/ /wasm-sysroot/
79+
# ... and the sysroot we built to link executables against ...
80+
COPY --from=reference-sysroot /wasi-sysroot/ /wasi-sysroot/
81+
# ... and finally wasmtime to actually execute binaries
6382
COPY --from=wasmtime /wasmtime/target/release/wasmtime /usr/bin/
6483

84+
# Of note here is our clang wrapper which just executes a normal clang
85+
# executable with the right sysroot, and then we're sure to turn off the
86+
# crt-static feature to ensure that the CRT that we're specifying with `clang`
87+
# is used.
6588
ENV CARGO_TARGET_WASM32_UNKNOWN_WASI_RUNNER=wasmtime \
66-
CARGO_TARGET_WASM32_UNKNOWN_WASI_LINKER=/wasm-sysroot/bin/clang \
67-
CC_wasm32_unknown_wasi=/wasm-sysroot/bin/clang \
89+
CARGO_TARGET_WASM32_UNKNOWN_WASI_LINKER=/wasi-sysroot/bin/clang \
90+
CC_wasm32_unknown_wasi=/wasi-sysroot/bin/clang \
6891
PATH=$PATH:/rust/bin \
6992
RUSTFLAGS=-Ctarget-feature=-crt-static
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
#!/bin/sh
2-
exec /wasmcc/bin/clang --target=wasm32-unknown-wasi --sysroot /wasm-sysroot "$@"
1+
#!/usr/bin/env sh
2+
exec /wasmcc/bin/clang --target=wasm32-unknown-wasi --sysroot /wasi-sysroot "$@"

libc-test/build.rs

+5-15
Original file line numberDiff line numberDiff line change
@@ -1896,37 +1896,27 @@ fn test_wasi(target: &str) {
18961896
cfg.type_name(move |ty, is_struct, is_union| match ty {
18971897
"FILE" => ty.to_string(),
18981898
t if is_union => format!("union {}", t),
1899-
t if t.starts_with("__wasi") && t.ends_with("_u") => format!("union {}", t),
1899+
t if t.starts_with("__wasi") && t.ends_with("_u") => {
1900+
format!("union {}", t)
1901+
}
19001902
t if t.starts_with("__wasi") && is_struct => format!("struct {}", t),
19011903
t if t.ends_with("_t") => t.to_string(),
19021904
t if is_struct => format!("struct {}", t),
19031905
t => t.to_string(),
19041906
});
19051907

1906-
// This is an opaque struct but we go through shenanigans to define values
1907-
// for it
1908-
cfg.skip_struct(move |ty| ty == "__clockid");
1909-
19101908
cfg.field_name(move |_struct, field| {
19111909
match field {
1912-
// deal with fields as rust keywords
1910+
// deal with fields as rust keywords
19131911
"type_" => "type".to_string(),
19141912
s => s.to_string(),
19151913
}
19161914
});
19171915

1918-
cfg.skip_static(move |name| {
1919-
match name {
1920-
// wasi shenanigans for defining CLOCK_REALTIME and such
1921-
s if s.starts_with("__CLOCK") => true,
1922-
_ => false,
1923-
}
1924-
});
1925-
19261916
// Looks like LLD doesn't merge duplicate imports, so if the Rust
19271917
// code imports from a module and the C code also imports from a
19281918
// module we end up with two imports of function pointers which
1929-
// improt the same thing bug have different function pointers
1919+
// import the same thing but have different function pointers
19301920
cfg.skip_fn_ptrcheck(|f| f.starts_with("__wasi"));
19311921

19321922
cfg.generate("../src/lib.rs", "main.rs");

src/wasi.rs

+10-24
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ pub type clock_t = c_longlong;
2626
pub type time_t = c_longlong;
2727
pub type c_double = f64;
2828
pub type c_float = f32;
29-
pub type clockid_t = &'static __clockid;
3029

3130
pub type __wasi_advice_t = u8;
3231
pub type __wasi_clockid_t = u32;
@@ -289,8 +288,6 @@ s! {
289288
pub it_value: timespec,
290289
}
291290

292-
pub struct __clockid {}
293-
294291
pub struct __wasi_dirent_t {
295292
pub d_next: __wasi_dircookie_t,
296293
pub d_ino: __wasi_inode_t,
@@ -367,15 +364,15 @@ s_no_extra_traits! {
367364
#[allow(missing_debug_implementations)]
368365
pub union __wasi_event_u {
369366
pub fd_readwrite: __wasi_event_u_fd_readwrite_t,
370-
_bindgen_union_align: [u64; 2usize],
367+
_bindgen_union_align: [u64; 2],
371368
}
372369

373370
#[allow(missing_debug_implementations)]
374371
pub union __wasi_subscription_u {
375372
pub clock: __wasi_subscription_u_clock_t,
376373
pub fd_readwrite:
377374
__wasi_subscription_u_fd_readwrite_t,
378-
_bindgen_union_align: [u64; 5usize],
375+
_bindgen_union_align: [u64; 5],
379376
}
380377

381378
#[allow(missing_debug_implementations)]
@@ -391,11 +388,6 @@ s_no_extra_traits! {
391388

392389
}
393390

394-
pub static CLOCK_REALTIME: clockid_t = unsafe { &__CLOCK_REALTIME_ADDR };
395-
pub static CLOCK_MONOTONIC: clockid_t = unsafe { &__CLOCK_MONOTONIC_ADDR };
396-
pub static CLOCK_MONOTONIC_RAW: clockid_t =
397-
unsafe { &__CLOCK_MONOTONIC_RAW_ADDR };
398-
399391
#[cfg_attr(feature = "rustc-dep-of-std",
400392
link(name = "c", kind = "static",
401393
cfg(target_feature = "crt-static")))]
@@ -484,21 +476,15 @@ extern "C" {
484476
pub fn asctime_r(a: *const tm, b: *mut c_char) -> *mut c_char;
485477
pub fn ctime_r(a: *const time_t, b: *mut c_char) -> *mut c_char;
486478

487-
#[link_name = "CLOCK_REALTIME"]
488-
pub static __CLOCK_REALTIME_ADDR: __clockid;
489-
#[link_name = "CLOCK_MONOTONIC"]
490-
pub static __CLOCK_MONOTONIC_ADDR: __clockid;
491-
#[link_name = "CLOCK_MONOTONIC_RAW"]
492-
pub static __CLOCK_MONOTONIC_RAW_ADDR: __clockid;
493479
pub fn nanosleep(a: *const timespec, b: *mut timespec) -> c_int;
494-
pub fn clock_getres(a: clockid_t, b: *mut timespec) -> c_int;
495-
pub fn clock_gettime(a: clockid_t, b: *mut timespec) -> c_int;
496-
pub fn clock_nanosleep(
497-
a: clockid_t,
498-
a2: c_int,
499-
b: *const timespec,
500-
c: *mut timespec,
501-
) -> c_int;
480+
// pub fn clock_getres(a: clockid_t, b: *mut timespec) -> c_int;
481+
// pub fn clock_gettime(a: clockid_t, b: *mut timespec) -> c_int;
482+
// pub fn clock_nanosleep(
483+
// a: clockid_t,
484+
// a2: c_int,
485+
// b: *const timespec,
486+
// c: *mut timespec,
487+
// ) -> c_int;
502488

503489
pub fn __wasilibc_register_preopened_fd(
504490
fd: c_int,

0 commit comments

Comments
 (0)