Skip to content

Commit ac6739c

Browse files
alexcrichtontgross35
authored andcommitted
Re-enable testing of WASI on CI
This commit updates CI to resume testing WASI. This updates the container and testing scripts from historical processes to more modern ones, e.g. downloading wasi-sdk instead of compiling a custom toolchain. This should make it easier to update in the future and keep it in sync with rust-lang/rust as well. This also required a few minor fixes such as: * The `S_IFIFO` and `S_IFMT` constants had incorrect values. * The `CLOCK_*` definitions cause `ctest2`'s parsing to panic to they're skipped with a new `#[cfg]`. * A new `langinfo.h` header was added to the list to include. * Some historically skipped checks were removed since they're no longer necessary. * Checks for `__errno_location` are disabled since that doesn't actually exist in headers. * Checks for `select` are disabled because the Rust definition got the `const`-ness swapped for the final `timeval` argument. (backport <rust-lang#3869>) [ resolve conflicts - Trevor ] (cherry picked from commit 7c10562)
1 parent 99bd0f5 commit ac6739c

File tree

7 files changed

+80
-70
lines changed

7 files changed

+80
-70
lines changed

.github/workflows/full_ci.yml

+1-5
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,7 @@ jobs:
118118
powerpc64le-unknown-linux-gnu,
119119
s390x-unknown-linux-gnu,
120120
riscv64gc-unknown-linux-gnu,
121-
# FIXME: A recent nightly causes a linker failure:
122-
# https://github.com/rust-lang/rust/issues/76679
123-
# See this comment for more details:
124-
# https://github.com/rust-lang/libc/pull/2225#issuecomment-880696737
125-
#wasm32-wasi,
121+
wasm32-wasip1,
126122
sparc64-unknown-linux-gnu,
127123
wasm32-unknown-emscripten,
128124
x86_64-linux-android,

build.rs

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const ALLOWED_CFGS: &'static [&'static str] = &[
3030
"libc_thread_local",
3131
"libc_underscore_const_names",
3232
"libc_union",
33+
"libc_ctest",
3334
];
3435

3536
// Extra values to allow for check-cfg.

ci/docker/wasm32-wasi/Dockerfile

-40
This file was deleted.

ci/docker/wasm32-wasi/clang.sh

-2
This file was deleted.

ci/docker/wasm32-wasip1/Dockerfile

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
FROM ubuntu:24.04
2+
3+
RUN apt-get update && \
4+
apt-get install -y --no-install-recommends \
5+
ca-certificates \
6+
curl \
7+
clang \
8+
xz-utils
9+
10+
# Wasmtime is used to execute tests and wasi-sdk is used to compile tests.
11+
# Download appropriate versions here and configure various flags below.
12+
ENV WASMTIME 24.0.0
13+
ENV WASI_SDK 24
14+
15+
RUN curl -L https://github.com/bytecodealliance/wasmtime/releases/download/v$WASMTIME/wasmtime-v$WASMTIME-x86_64-linux.tar.xz | \
16+
tar xJf -
17+
ENV PATH=$PATH:/wasmtime-v$WASMTIME-x86_64-linux
18+
19+
RUN curl -LO https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-$WASI_SDK/wasi-sdk-$WASI_SDK.0-x86_64-linux.deb
20+
RUN dpkg -i ./wasi-sdk-*.deb
21+
22+
# Note that `-D_WASI_EMULATED_PROCESS_CLOCKS` is used to enable access to
23+
# clock-related defines even though they're emulated. Also note that the usage
24+
# of `-Ctarget-feature=-crt-static` here forces usage of the external wasi-libc
25+
# installed via `wasi-sdk` instead of the version that comes with the standard
26+
# library.
27+
ENV CARGO_TARGET_WASM32_WASIP1_RUNNER=wasmtime \
28+
CARGO_TARGET_WASM32_WASIP1_LINKER=/opt/wasi-sdk/bin/clang \
29+
CARGO_TARGET_WASM32_WASIP1_RUSTFLAGS="-lwasi-emulated-process-clocks -Ctarget-feature=-crt-static" \
30+
CC_wasm32_wasip1=/opt/wasi-sdk/bin/clang \
31+
CFLAGS_wasm32_wasip1=-D_WASI_EMULATED_PROCESS_CLOCKS \
32+
PATH=$PATH:/rust/bin

libc-test/build.rs

+24-11
Original file line numberDiff line numberDiff line change
@@ -1530,6 +1530,7 @@ fn test_wasi(target: &str) {
15301530
"dirent.h",
15311531
"errno.h",
15321532
"fcntl.h",
1533+
"langinfo.h",
15331534
"limits.h",
15341535
"locale.h",
15351536
"malloc.h",
@@ -1541,6 +1542,7 @@ fn test_wasi(target: &str) {
15411542
"stdio.h",
15421543
"stdlib.h",
15431544
"string.h",
1545+
"sys/ioctl.h",
15441546
"sys/resource.h",
15451547
"sys/select.h",
15461548
"sys/socket.h",
@@ -1549,16 +1551,20 @@ fn test_wasi(target: &str) {
15491551
"sys/types.h",
15501552
"sys/uio.h",
15511553
"sys/utsname.h",
1552-
"sys/ioctl.h",
15531554
"time.h",
15541555
"unistd.h",
15551556
"wasi/api.h",
1556-
"wasi/libc.h",
15571557
"wasi/libc-find-relpath.h",
15581558
"wasi/libc-nocwd.h",
1559+
"wasi/libc.h",
15591560
"wchar.h",
15601561
}
15611562

1563+
// Currently `ctest2` doesn't support macros-in-static-expressions and will
1564+
// panic on them. That affects `CLOCK_*` defines in wasi to set this here
1565+
// to omit them.
1566+
cfg.cfg("libc_ctest", None);
1567+
15621568
cfg.type_name(move |ty, is_struct, is_union| match ty {
15631569
"FILE" | "fd_set" | "DIR" => ty.to_string(),
15641570
t if is_union => format!("union {}", t),
@@ -1577,20 +1583,27 @@ fn test_wasi(target: &str) {
15771583
}
15781584
});
15791585

1580-
// Looks like LLD doesn't merge duplicate imports, so if the Rust
1581-
// code imports from a module and the C code also imports from a
1582-
// module we end up with two imports of function pointers which
1583-
// import the same thing but have different function pointers
1584-
cfg.skip_fn_ptrcheck(|f| f.starts_with("__wasi"));
1586+
// These have a different and internal type in header files and are only
1587+
// used here to generate a pointer to them in bindings so skip these tests.
1588+
cfg.skip_static(|c| c.starts_with("_CLOCK_"));
1589+
1590+
cfg.skip_fn(|f| match f {
1591+
// This function doesn't actually exist in libc's header files
1592+
"__errno_location" => true,
1593+
1594+
// The `timeout` argument to this function is `*const` in Rust but
1595+
// mutable in C which causes a mismatch. Avoiding breakage by changing
1596+
// this in wasi-libc and instead accepting that this is slightly
1597+
// different.
1598+
"select" => true,
1599+
1600+
_ => false,
1601+
});
15851602

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

1590-
// Currently Rust/clang disagree on function argument ABI, so skip these
1591-
// tests. For more info see WebAssembly/tool-conventions#88
1592-
cfg.skip_roundtrip(|_| true);
1593-
15941607
cfg.generate("../src/lib.rs", "main.rs");
15951608
}
15961609

src/wasi.rs

+22-12
Original file line numberDiff line numberDiff line change
@@ -245,14 +245,14 @@ pub const AT_SYMLINK_FOLLOW: c_int = 0x2;
245245
pub const AT_REMOVEDIR: c_int = 0x4;
246246
pub const UTIME_OMIT: c_long = 0xfffffffe;
247247
pub const UTIME_NOW: c_long = 0xffffffff;
248-
pub const S_IFIFO: mode_t = 49152;
248+
pub const S_IFIFO: mode_t = 0o1_0000;
249249
pub const S_IFCHR: mode_t = 8192;
250250
pub const S_IFBLK: mode_t = 24576;
251251
pub const S_IFDIR: mode_t = 16384;
252252
pub const S_IFREG: mode_t = 32768;
253253
pub const S_IFLNK: mode_t = 40960;
254254
pub const S_IFSOCK: mode_t = 49152;
255-
pub const S_IFMT: mode_t = 57344;
255+
pub const S_IFMT: mode_t = 0o17_0000;
256256
pub const S_IRWXO: mode_t = 0x7;
257257
pub const S_IXOTH: mode_t = 0x1;
258258
pub const S_IWOTH: mode_t = 0x2;
@@ -372,16 +372,26 @@ pub const _SC_PAGE_SIZE: ::c_int = _SC_PAGESIZE;
372372
pub const _SC_IOV_MAX: c_int = 60;
373373
pub const _SC_SYMLOOP_MAX: c_int = 173;
374374

375-
#[allow(unused_unsafe)] // `addr_of!(EXTERN_STATIC)` is now safe; remove `unsafe` when MSRV >= 1.82
376-
pub static CLOCK_MONOTONIC: clockid_t = unsafe { clockid_t(ptr_addr_of!(_CLOCK_MONOTONIC)) };
377-
#[allow(unused_unsafe)]
378-
pub static CLOCK_PROCESS_CPUTIME_ID: clockid_t =
379-
unsafe { clockid_t(ptr_addr_of!(_CLOCK_PROCESS_CPUTIME_ID)) };
380-
#[allow(unused_unsafe)]
381-
pub static CLOCK_REALTIME: clockid_t = unsafe { clockid_t(ptr_addr_of!(_CLOCK_REALTIME)) };
382-
#[allow(unused_unsafe)]
383-
pub static CLOCK_THREAD_CPUTIME_ID: clockid_t =
384-
unsafe { clockid_t(ptr_addr_of!(_CLOCK_THREAD_CPUTIME_ID)) };
375+
cfg_if! {
376+
if #[cfg(libc_ctest)] {
377+
// skip these constants when this is active because `ctest` currently
378+
// panics on parsing the constants below
379+
} else {
380+
// `addr_of!(EXTERN_STATIC)` is now safe; remove `unsafe` when MSRV >= 1.82
381+
#[allow(unused_unsafe)]
382+
pub static CLOCK_MONOTONIC: clockid_t =
383+
unsafe { clockid_t(ptr_addr_of!(_CLOCK_MONOTONIC)) };
384+
#[allow(unused_unsafe)]
385+
pub static CLOCK_PROCESS_CPUTIME_ID: clockid_t =
386+
unsafe { clockid_t(ptr_addr_of!(_CLOCK_PROCESS_CPUTIME_ID)) };
387+
#[allow(unused_unsafe)]
388+
pub static CLOCK_REALTIME: clockid_t =
389+
unsafe { clockid_t(ptr_addr_of!(_CLOCK_REALTIME)) };
390+
#[allow(unused_unsafe)]
391+
pub static CLOCK_THREAD_CPUTIME_ID: clockid_t =
392+
unsafe { clockid_t(ptr_addr_of!(_CLOCK_THREAD_CPUTIME_ID)) };
393+
}
394+
}
385395

386396
pub const ABDAY_1: ::nl_item = 0x20000;
387397
pub const ABDAY_2: ::nl_item = 0x20001;

0 commit comments

Comments
 (0)