Skip to content

Commit 567c854

Browse files
authored
Merge pull request #3877 from tgross35/backport-butternut
[0.2] Backport of two pull requests
2 parents fa7bb69 + 4d990a5 commit 567c854

File tree

9 files changed

+107
-70
lines changed

9 files changed

+107
-70
lines changed

.github/workflows/full_ci.yml

+2-5
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,8 @@ 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,
122+
wasm32-wasip2,
126123
sparc64-unknown-linux-gnu,
127124
wasm32-unknown-emscripten,
128125
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

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM ubuntu:24.04
2+
3+
COPY wasi.sh /
4+
RUN bash /wasi.sh
5+
6+
# Note that `-D_WASI_EMULATED_PROCESS_CLOCKS` is used to enable access to
7+
# clock-related defines even though they're emulated. Also note that the usage
8+
# of `-Ctarget-feature=-crt-static` here forces usage of the external wasi-libc
9+
# installed via `wasi-sdk` instead of the version that comes with the standard
10+
# library.
11+
ENV CARGO_TARGET_WASM32_WASIP1_RUNNER=wasmtime \
12+
CARGO_TARGET_WASM32_WASIP1_LINKER=/opt/wasi-sdk/bin/clang \
13+
CARGO_TARGET_WASM32_WASIP1_RUSTFLAGS="-lwasi-emulated-process-clocks -Ctarget-feature=-crt-static" \
14+
CC_wasm32_wasip1=/opt/wasi-sdk/bin/clang \
15+
CFLAGS_wasm32_wasip1=-D_WASI_EMULATED_PROCESS_CLOCKS \
16+
PATH=$PATH:/rust/bin:/wasmtime

ci/docker/wasm32-wasip2/Dockerfile

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM ubuntu:24.04
2+
3+
COPY wasi.sh /
4+
RUN bash /wasi.sh
5+
6+
# Note that most of these are copied from `wasm32-wasip1/Dockerfile`
7+
#
8+
# FIXME: the `-Clink-arg` to export `cabi_realloc` is a bug in the target
9+
# itself, this should be fixed upstream.
10+
ENV CARGO_TARGET_WASM32_WASIP2_RUNNER=wasmtime \
11+
CARGO_TARGET_WASM32_WASIP2_LINKER=/opt/wasi-sdk/bin/clang \
12+
CARGO_TARGET_WASM32_WASIP2_RUSTFLAGS="-lwasi-emulated-process-clocks -Ctarget-feature=-crt-static -Clink-arg=-Wl,--export,cabi_realloc" \
13+
CC_wasm32_wasip2=/opt/wasi-sdk/bin/clang \
14+
CFLAGS_wasm32_wasip2=-D_WASI_EMULATED_PROCESS_CLOCKS \
15+
PATH=$PATH:/rust/bin:/wasmtime

ci/wasi.sh

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env bash
2+
3+
set -ex
4+
5+
apt-get update
6+
apt-get install -y --no-install-recommends \
7+
ca-certificates \
8+
curl \
9+
clang \
10+
xz-utils
11+
12+
# Wasmtime is used to execute tests and wasi-sdk is used to compile tests.
13+
# Download appropriate versions here and configure various flags below.
14+
#
15+
# At the time of this writing wasmtime 24.0.0 is the latest release and
16+
# wasi-sdk-24 is the latest release, that these numbers match is just
17+
# coincidence.
18+
wasmtime=24.0.0
19+
wasi_sdk=24
20+
21+
curl -L https://github.com/bytecodealliance/wasmtime/releases/download/v$wasmtime/wasmtime-v$wasmtime-x86_64-linux.tar.xz | \
22+
tar xJf -
23+
mv wasmtime-v$wasmtime-x86_64-linux wasmtime
24+
25+
# The pre-built `*.deb` files for wasi-sdk install to `/opt/wasi-sdk`
26+
curl -LO https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-$wasi_sdk/wasi-sdk-$wasi_sdk.0-x86_64-linux.deb
27+
dpkg -i ./wasi-sdk-*.deb

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)