@@ -42,10 +42,11 @@ set -ex
4242version=$( ./ci/print-current-version.sh | sed ' s/\./_/g' )
4343
4444realloc=cabi_realloc_wit_bindgen_$version
45- wasip3_task_set=wasip3_task_set_wit_bindgen_$version
46- wasip3_task_get=wasip3_task_get_wit_bindgen_$version
4745
48- cat > ./crates/guest-rust/rt/src/wit_bindgen_cabi.rs << -EOF
46+ rm -f crates/guest-rust/rt/src/wit_bindgen_* .{rs,o,c}
47+ rm -f crates/guest-rust/rt/src/libwit_bindgen_cabi.a
48+
49+ cat > ./crates/guest-rust/rt/src/wit_bindgen_cabi_realloc.rs << -EOF
4950// This file is generated by $0
5051
5152#[unsafe(no_mangle)]
@@ -57,20 +58,9 @@ pub unsafe extern "C" fn $realloc(
5758) -> *mut u8 {
5859 crate::cabi_realloc(old_ptr, old_len, align, new_len)
5960}
60-
61- static mut WASIP3_TASK: *mut u8 = core::ptr::null_mut();
62-
63- #[unsafe(no_mangle)]
64- pub unsafe extern "C" fn $wasip3_task_set (ptr: *mut u8) -> *mut u8 {
65- unsafe {
66- let ret = WASIP3_TASK;
67- WASIP3_TASK = ptr;
68- ret
69- }
70- }
7161EOF
7262
73- cat > ./crates/guest-rust/rt/src/wit_bindgen_cabi .c << -EOF
63+ cat > ./crates/guest-rust/rt/src/wit_bindgen_cabi_realloc .c << -EOF
7464// This file is generated by $0
7565
7666#include <stdint.h>
@@ -81,25 +71,37 @@ __attribute__((__weak__, __export_name__("cabi_realloc")))
8171void *cabi_realloc(void *ptr, size_t old_size, size_t align, size_t new_size) {
8272 return $realloc (ptr, old_size, align, new_size);
8373}
74+ EOF
75+
76+ cat > ./crates/guest-rust/rt/src/wit_bindgen_cabi_wasip3.c << -EOF
77+ // This file is generated by $0
8478
85- extern void *$wasip3_task_set (void *ptr);
79+ #include <stdlib.h>
80+
81+ static void *WASIP3_TASK = NULL;
8682
8783__attribute__((__weak__))
8884void *wasip3_task_set(void *ptr) {
89- return $wasip3_task_set (ptr);
85+ void *ret = WASIP3_TASK;
86+ WASIP3_TASK = ptr;
87+ return ret;
9088}
9189EOF
9290
93- rm -f crates/guest-rust/rt/src/wit_bindgen_cabi.o
94- $WASI_SDK_PATH /bin/clang crates/guest-rust/rt/src/wit_bindgen_cabi.c \
95- -O -c -o crates/guest-rust/rt/src/wit_bindgen_cabi.o
91+ build () {
92+ file=$1
93+ $WASI_SDK_PATH /bin/clang crates/guest-rust/rt/src/$1 .c \
94+ -O -c -o crates/guest-rust/rt/src/$1 .o
95+ # Remove the `producers` section. This appears to differ whether the host for
96+ # clang is either macOS or Linux. Not needed here anyway, so discard it to help
97+ # either host produce the same object.
98+ wasm-tools strip -d producers ./crates/guest-rust/rt/src/$1 .o \
99+ -o ./crates/guest-rust/rt/src/$1 .o
100+ }
96101
97- # Remove the `producers` section. This appears to differ whether the host for
98- # clang is either macOS or Linux. Not needed here anyway, so discard it to help
99- # either host produce the same object.
100- wasm-tools strip -d producers ./crates/guest-rust/rt/src/wit_bindgen_cabi.o \
101- -o ./crates/guest-rust/rt/src/wit_bindgen_cabi.o
102+ build wit_bindgen_cabi_realloc
103+ build wit_bindgen_cabi_wasip3
102104
103- rm -f crates/guest-rust/rt/src/libwit_bindgen_cabi.a
104105$WASI_SDK_PATH /bin/llvm-ar crus crates/guest-rust/rt/src/libwit_bindgen_cabi.a \
105- crates/guest-rust/rt/src/wit_bindgen_cabi.o
106+ crates/guest-rust/rt/src/wit_bindgen_cabi_realloc.o \
107+ crates/guest-rust/rt/src/wit_bindgen_cabi_wasip3.o
0 commit comments