Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ci/wasi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ apt-get install -y --no-install-recommends \

# Wasmtime is used to execute tests and wasi-sdk is used to compile tests.
# Download appropriate versions here and configure various flags below.
wasmtime=38.0.2
wasi_sdk=29
wasmtime=47.0.2
wasi_sdk=33

curl -L https://github.com/bytecodealliance/wasmtime/releases/download/v$wasmtime/wasmtime-v$wasmtime-x86_64-linux.tar.xz |
tar xJf -
Expand Down
30 changes: 30 additions & 0 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1942,6 +1942,7 @@ fn which_dragonfly() -> Option<u32> {
fn test_wasi(target: &str) {
assert!(target.contains("wasi"));
let p2 = target.contains("wasip2");
let wasi_sdk = VERSIONS.wasi_sdk.unwrap();

let mut cfg = ctest_cfg();
cfg.define("_GNU_SOURCE", None);
Expand Down Expand Up @@ -2005,6 +2006,15 @@ fn test_wasi(target: &str) {
// used here to generate a pointer to them in bindings so skip these tests.
cfg.skip_static(|s| s.ident().starts_with("_CLOCK_"));

match wasi_sdk.1 {
WasiVersion::P1 => {}
// This was removed in wasip2 target for wasi-sdk-30+, but it's just a
// typedef, so ignore it.
_ => {
cfg.skip_alias(|s| s.ident() == "__wasi_rights_t");
}
}

cfg.skip_const(|c| match c.ident() {
// These constants aren't yet defined in wasi-libc.
// Exposing them is being tracked by https://github.com/WebAssembly/wasi-libc/issues/531.
Expand Down Expand Up @@ -6393,6 +6403,15 @@ struct Versions {
netbsd: Option<(u32, u32)>,
macos: Option<(u32, u32)>,
emscripten: Option<(u32, u32)>,
wasi_sdk: Option<(u32, WasiVersion)>,
}

#[derive(Clone, Copy, Debug, Default)]
enum WasiVersion {
#[default]
P1,
P2,
P3,
}

impl Versions {
Expand Down Expand Up @@ -6429,6 +6448,11 @@ impl Versions {
/* Provides __EMSCRIPTEN_MAJOR__, __EMSCRIPTEN_MINOR__ */
#include "emscripten/version.h"
#endif

#if __has_include(<wasi/version.h>)
/* provides __wasi_sdk_major__, __wasi_sdk_version__ */
#include <wasi/version.h>
#endif
"#;

let mut ret = Versions::default();
Expand Down Expand Up @@ -6509,6 +6533,12 @@ impl Versions {
"__EMSCRIPTEN_minor__" => {
ret.emscripten.get_or_insert_default().1 = value.parse().unwrap()
}
"__wasi_sdk_major__" => {
ret.wasi_sdk.get_or_insert_default().0 = value.parse().unwrap()
}
"__wasip1__" => ret.wasi_sdk.get_or_insert_default().1 = WasiVersion::P1,
"__wasip2__" => ret.wasi_sdk.get_or_insert_default().1 = WasiVersion::P2,
"__wasip3__" => ret.wasi_sdk.get_or_insert_default().1 = WasiVersion::P3,
_ => (),
}
}
Expand Down
91 changes: 91 additions & 0 deletions src/wasi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ pub type blkcnt_t = i64;
pub type nfds_t = c_ulong;
pub type wchar_t = i32;
pub type nl_item = c_int;
#[cfg_attr(
not(target_env = "p1"),
deprecated(since = "0.2.190", note = "not present on wasip2/3 targets")
)]
pub type __wasi_rights_t = u64;
pub type locale_t = *mut __locale_struct;
pub type pthread_t = *mut c_void;
Expand Down Expand Up @@ -611,6 +615,40 @@ pub const NOEXPR: crate::nl_item = 0x50001;
pub const YESSTR: crate::nl_item = 0x50002;
pub const NOSTR: crate::nl_item = 0x50003;

pub const PTHREAD_CREATE_JOINABLE: c_int = 0;
pub const PTHREAD_CREATE_DETACHED: c_int = 1;
pub const PTHREAD_MUTEX_NORMAL: c_int = 0;
pub const PTHREAD_MUTEX_DEFAULT: c_int = 0;
pub const PTHREAD_MUTEX_RECURSIVE: c_int = 1;
pub const PTHREAD_MUTEX_ERRORCHECK: c_int = 2;
pub const PTHREAD_MUTEX_STALLED: c_int = 0;
pub const PTHREAD_MUTEX_ROBUST: c_int = 1;
pub const PTHREAD_PRIO_NONE: c_int = 0;
pub const PTHREAD_PRIO_INHERIT: c_int = 1;
pub const PTHREAD_PRIO_PROTECT: c_int = 2;
pub const PTHREAD_INHERIT_SCHED: c_int = 0;
pub const PTHREAD_EXPLICIT_SCHED: c_int = 1;
pub const PTHREAD_SCOPE_SYSTEM: c_int = 0;
pub const PTHREAD_SCOPE_PROCESS: c_int = 1;
pub const PTHREAD_PROCESS_PRIVATE: c_int = 0;
pub const PTHREAD_PROCESS_SHARED: c_int = 1;
pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t {
size: [ptr::null_mut(); 6],
};
pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t {
size: [ptr::null_mut(); 8],
};
pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t {
size: [ptr::null_mut(); 12],
};
Comment thread
alexcrichton marked this conversation as resolved.
pub const PTHREAD_ONCE_INIT: pthread_once_t = 0;
pub const PTHREAD_CANCEL_ENABLE: c_int = 0;
pub const PTHREAD_CANCEL_DISABLE: c_int = 1;
pub const PTHREAD_CANCEL_MASKED: c_int = 2;
pub const PTHREAD_CANCEL_DEFERRED: c_int = 0;
pub const PTHREAD_CANCEL_ASYNCHRONOUS: c_int = 1;
pub const PTHREAD_CANCELED: *mut c_void = usize::MAX as *mut c_void;
pub const PTHREAD_BARRIER_SERIAL_THREAD: c_int = -1;
pub const PTHREAD_STACK_MIN: usize = 2048;
pub const TIMER_ABSTIME: c_int = 1;

Expand Down Expand Up @@ -1036,8 +1074,21 @@ extern "C" {
pub fn pthread_attr_destroy(attr: *mut pthread_attr_t) -> c_int;
pub fn pthread_attr_getstacksize(attr: *const pthread_attr_t, stacksize: *mut size_t) -> c_int;
pub fn pthread_attr_setstacksize(attr: *mut pthread_attr_t, stack_size: size_t) -> c_int;
pub fn pthread_attr_getdetachstate(attr: *const pthread_attr_t, state: *mut c_int) -> c_int;
pub fn pthread_attr_setdetachstate(attr: *mut pthread_attr_t, state: c_int) -> c_int;
pub fn pthread_attr_getguardsize(attr: *const pthread_attr_t, b: *mut size_t) -> c_int;
pub fn pthread_attr_setguardsize(attr: *mut pthread_attr_t, b: size_t) -> c_int;
pub fn pthread_attr_getstack(
attr: *const pthread_attr_t,
b: *mut *mut c_void,
c: *mut size_t,
) -> c_int;
pub fn pthread_attr_setstack(attr: *mut pthread_attr_t, b: *mut c_void, c: size_t) -> c_int;
pub fn pthread_detach(thread: pthread_t) -> c_int;
pub fn pthread_setcancelstate(a: c_int, b: *mut c_int) -> c_int;
pub fn pthread_setcanceltype(a: c_int, b: *mut c_int) -> c_int;
pub fn pthread_testcancel();
pub fn pthread_once(a: *mut pthread_once_t, b: extern "C" fn()) -> c_int;

pub fn pthread_key_create(
key: *mut pthread_key_t,
Expand All @@ -1054,10 +1105,20 @@ extern "C" {
pub fn pthread_mutex_lock(lock: *mut pthread_mutex_t) -> c_int;
pub fn pthread_mutex_trylock(lock: *mut pthread_mutex_t) -> c_int;
pub fn pthread_mutex_unlock(lock: *mut pthread_mutex_t) -> c_int;
pub fn pthread_mutex_timedlock(lock: *mut pthread_mutex_t, ts: *const timespec) -> c_int;
pub fn pthread_mutex_consistent(lock: *mut pthread_mutex_t) -> c_int;
pub fn pthread_mutex_getprioceiling(lock: *mut pthread_mutex_t, b: *mut c_int) -> c_int;

pub fn pthread_mutexattr_init(attr: *mut pthread_mutexattr_t) -> c_int;
pub fn pthread_mutexattr_destroy(attr: *mut pthread_mutexattr_t) -> c_int;
pub fn pthread_mutexattr_settype(attr: *mut pthread_mutexattr_t, _type: c_int) -> c_int;
pub fn pthread_mutexattr_getprotocol(attr: *const pthread_mutexattr_t, b: *mut c_int) -> c_int;
pub fn pthread_mutexattr_getpshared(attr: *const pthread_mutexattr_t, b: *mut c_int) -> c_int;
pub fn pthread_mutexattr_getrobust(attr: *const pthread_mutexattr_t, b: *mut c_int) -> c_int;
pub fn pthread_mutexattr_gettype(attr: *const pthread_mutexattr_t, b: *mut c_int) -> c_int;
pub fn pthread_mutexattr_setprotocol(attr: *const pthread_mutexattr_t, b: c_int) -> c_int;
pub fn pthread_mutexattr_setpshared(attr: *const pthread_mutexattr_t, b: c_int) -> c_int;
pub fn pthread_mutexattr_setrobust(attr: *const pthread_mutexattr_t, b: c_int) -> c_int;

pub fn pthread_cond_init(cond: *mut pthread_cond_t, attr: *const pthread_condattr_t) -> c_int;
pub fn pthread_cond_wait(cond: *mut pthread_cond_t, lock: *mut pthread_mutex_t) -> c_int;
Expand All @@ -1071,6 +1132,8 @@ extern "C" {
pub fn pthread_cond_destroy(cond: *mut pthread_cond_t) -> c_int;
pub fn pthread_condattr_init(attr: *mut pthread_condattr_t) -> c_int;
pub fn pthread_condattr_destroy(attr: *mut pthread_condattr_t) -> c_int;
pub fn pthread_condattr_setpshared(attr: *mut pthread_condattr_t, b: c_int) -> c_int;
pub fn pthread_condattr_getpshared(attr: *const pthread_condattr_t, b: *mut c_int) -> c_int;

pub fn pthread_rwlock_init(
lock: *mut pthread_rwlock_t,
Expand All @@ -1082,8 +1145,36 @@ extern "C" {
pub fn pthread_rwlock_wrlock(lock: *mut pthread_rwlock_t) -> c_int;
pub fn pthread_rwlock_trywrlock(lock: *mut pthread_rwlock_t) -> c_int;
pub fn pthread_rwlock_unlock(lock: *mut pthread_rwlock_t) -> c_int;
pub fn pthread_rwlock_timedrdlock(lock: *mut pthread_rwlock_t, at: *const timespec) -> c_int;
pub fn pthread_rwlock_timedwrlock(lock: *mut pthread_rwlock_t, at: *const timespec) -> c_int;
pub fn pthread_rwlockattr_init(attr: *mut pthread_rwlockattr_t) -> c_int;
pub fn pthread_rwlockattr_destroy(attr: *mut pthread_rwlockattr_t) -> c_int;
pub fn pthread_rwlockattr_setpshared(attr: *mut pthread_rwlockattr_t, b: c_int) -> c_int;
pub fn pthread_rwlockattr_getpshared(attr: *const pthread_rwlockattr_t, b: *mut c_int)
-> c_int;

pub fn pthread_spin_init(lock: *mut pthread_spinlock_t, b: c_int) -> c_int;
pub fn pthread_spin_destroy(lock: *mut pthread_spinlock_t) -> c_int;
pub fn pthread_spin_lock(lock: *mut pthread_spinlock_t) -> c_int;
pub fn pthread_spin_trylock(lock: *mut pthread_spinlock_t) -> c_int;
pub fn pthread_spin_unlock(lock: *mut pthread_spinlock_t) -> c_int;

pub fn pthread_barrier_init(
barrier: *mut pthread_barrier_t,
attr: *const pthread_barrierattr_t,
count: c_uint,
) -> c_int;
pub fn pthread_barrier_destroy(barrier: *mut pthread_barrier_t) -> c_int;
pub fn pthread_barrier_wait(barrier: *mut pthread_barrier_t) -> c_int;
pub fn pthread_barrierattr_init(attr: *mut pthread_barrierattr_t) -> c_int;
pub fn pthread_barrierattr_destroy(attr: *mut pthread_barrierattr_t) -> c_int;
pub fn pthread_barrierattr_setpshared(attr: *mut pthread_barrierattr_t, b: c_int) -> c_int;
pub fn pthread_barrierattr_getpshared(
attr: *const pthread_barrierattr_t,
b: *mut c_int,
) -> c_int;

pub fn pthread_getattr_np(thread: pthread_t, attr: *mut pthread_attr_t) -> c_int;
}

cfg_if! {
Expand Down