Skip to content

Commit b119e28

Browse files
authored
Prepare tests to run on WASIp3 (#1688)
* Prepare tests to run on WASIp3 This commit updates various bits/pieces of infrastructure/tests to ensure that all tests can run on WASIp3 targets in addition to WASIp2 targets. This isn't yet added to CI because toolchains aren't published quite just yet, but everything's been tested locally for now. The changes here are: * The wit-component/wasm-tools dependencies are updated. * Task state in Rust bindings is now stored in a TLS variable for wasip3 instead of a context slot like in wasip2. This is because context slots are taken in wasip3 for ABI details (stack pointer and TLS base). * Task state management in TLS on no-std builds requires an auxiliary C file to store the actual thread local. * Tests in C using context slots have a similar change where for wasip2 they use the context slot but for wasip3 they're now using a TLS variable. * Tests in Rust using TLS and relying on that being global are updated to use `static` variables instead as on wasip3 targets TLS is per-task, not global. * Fix C++ compat in tests
1 parent bd5e46c commit b119e28

14 files changed

Lines changed: 277 additions & 112 deletions

File tree

Cargo.lock

Lines changed: 38 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ syn = { version = "2.0.89", features = ["printing"] }
4848
futures = "0.3.31"
4949
macro-string = "0.2.0"
5050

51-
wat = "1.254.0"
52-
wasmparser = "0.254.0"
53-
wasm-encoder = "0.254.0"
54-
wasm-metadata = { version = "0.254.0", default-features = false }
55-
wit-parser = "0.254.0"
56-
wit-component = "0.254.0"
57-
wasm-compose = "0.254.0"
51+
wat = "1.257.0"
52+
wasmparser = "0.257.0"
53+
wasm-encoder = "0.257.0"
54+
wasm-metadata = { version = "0.257.0", default-features = false }
55+
wit-parser = "0.257.0"
56+
wit-component = "0.257.0"
57+
wasm-compose = "0.257.0"
5858

5959
wit-bindgen-core = { path = 'crates/core', version = '0.60.0' }
6060
wit-bindgen-c = { path = 'crates/c', version = '0.60.0' }

ci/rebuild-libwit-bindgen-cabi.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ set -ex
4242
version=$(./ci/print-current-version.sh | sed 's/\./_/g')
4343

4444
realloc=cabi_realloc_wit_bindgen_$version
45+
wasip3_get=wit_bindgen_${version}_get_task_context
46+
wasip3_set=wit_bindgen_${version}_set_task_context
4547

4648
rm -f crates/guest-rust/src/rt/wit_bindgen_*.{rs,o,c}
4749
rm -f crates/guest-rust/src/rt/libwit_bindgen_cabi.a
@@ -60,6 +62,17 @@ pub unsafe extern "C" fn $realloc(
6062
}
6163
EOF
6264

65+
cat >./crates/guest-rust/src/rt/async_support/wasip3_context.rs <<-EOF
66+
// This file is generated by $0
67+
68+
unsafe extern "C" {
69+
#[link_name = "$wasip3_get"]
70+
pub fn get() -> *mut u8;
71+
#[link_name = "$wasip3_set"]
72+
pub fn set(ptr: *mut u8);
73+
}
74+
EOF
75+
6376
cat >./crates/guest-rust/src/rt/wit_bindgen_cabi_realloc.c <<-EOF
6477
// This file is generated by $0
6578
@@ -86,6 +99,16 @@ void *wasip3_task_set(void *ptr) {
8699
WASIP3_TASK = ptr;
87100
return ret;
88101
}
102+
103+
static _Thread_local void *task_context = NULL;
104+
105+
void *$wasip3_get(void) {
106+
return task_context;
107+
}
108+
109+
void $wasip3_set(void *ptr) {
110+
task_context = ptr;
111+
}
89112
EOF
90113

91114
build() {

0 commit comments

Comments
 (0)