--- /dev/null
+Add experimental wasi-threads support. Patch by Takashi Yamamoto.
{
if (!initialized)
exit(0);
+#if defined(__wasi__)
+ /*
+ * wasi-threads doesn't have pthread_exit right now
+ * cf. https://github.com/WebAssembly/wasi-threads/issues/7
+ */
+ abort();
+#else
pthread_exit(0);
+#endif
}
#ifdef USE_SEMAPHORES
cmd.append(f"--{opt}-wasm-dynamic-linking")
if self.pthreads is not None:
- assert self.host.is_emscripten
opt = "enable" if self.pthreads else "disable"
cmd.append(f"--{opt}-wasm-pthreads")
support_level=SupportLevel.supported,
host=Host.wasm32_wasi,
),
+ # wasm32-wasi-threads
+ BuildProfile(
+ "wasi-threads",
+ support_level=SupportLevel.experimental,
+ host=Host.wasm32_wasi,
+ pthreads=True,
+ ),
# no SDK available yet
# BuildProfile(
# "wasm64-wasi",
# if defined(__EMSCRIPTEN__)
wasm32-emscripten
# elif defined(__wasi__)
+# if defined(_REENTRANT)
+ wasm32-wasi-threads
+# else
wasm32-wasi
+# endif
# else
# error unknown wasm32 platform
# endif
Emscripten) :
;; #(
WASI) :
- as_fn_error $? "WASI threading is not implemented yet." "$LINENO" 5 ;; #(
+ ;; #(
*) :
as_fn_error $? "--enable-wasm-pthreads only applies to Emscripten and WASI" "$LINENO" 5
;;
LIBS="$LIBS -lwasi-emulated-signal -lwasi-emulated-getpid -lwasi-emulated-process-clocks"
echo "#define _WASI_EMULATED_SIGNAL 1" >> confdefs.h
+ if test "x$enable_wasm_pthreads" = xyes
+then :
+
+ # Note: update CFLAGS because ac_compile/ac_link needs this too.
+ # without this, configure fails to find pthread_create, sem_init,
+ # etc because they are only available in the sysroot for
+ # wasm32-wasi-threads.
+ as_fn_append CFLAGS " -target wasm32-wasi-threads -pthread"
+ as_fn_append CFLAGS_NODIST " -target wasm32-wasi-threads -pthread"
+ as_fn_append LDFLAGS_NODIST " -target wasm32-wasi-threads -pthread"
+ as_fn_append LDFLAGS_NODIST " -Wl,--import-memory"
+ as_fn_append LDFLAGS_NODIST " -Wl,--max-memory=10485760"
+
+fi
+
as_fn_append LDFLAGS_NODIST " -z stack-size=524288 -Wl,--stack-first -Wl,--initial-memory=10485760"
;; #(
# if defined(__EMSCRIPTEN__)
wasm32-emscripten
# elif defined(__wasi__)
+# if defined(_REENTRANT)
+ wasm32-wasi-threads
+# else
wasm32-wasi
+# endif
# else
# error unknown wasm32 platform
# endif
[
AS_CASE([$ac_sys_system],
[Emscripten], [],
- [WASI], [AC_MSG_ERROR([WASI threading is not implemented yet.])],
+ [WASI], [],
[AC_MSG_ERROR([--enable-wasm-pthreads only applies to Emscripten and WASI])]
)
], [
LIBS="$LIBS -lwasi-emulated-signal -lwasi-emulated-getpid -lwasi-emulated-process-clocks"
echo "#define _WASI_EMULATED_SIGNAL 1" >> confdefs.h
+ AS_VAR_IF([enable_wasm_pthreads], [yes], [
+ # Note: update CFLAGS because ac_compile/ac_link needs this too.
+ # without this, configure fails to find pthread_create, sem_init,
+ # etc because they are only available in the sysroot for
+ # wasm32-wasi-threads.
+ AS_VAR_APPEND([CFLAGS], [" -target wasm32-wasi-threads -pthread"])
+ AS_VAR_APPEND([CFLAGS_NODIST], [" -target wasm32-wasi-threads -pthread"])
+ AS_VAR_APPEND([LDFLAGS_NODIST], [" -target wasm32-wasi-threads -pthread"])
+ AS_VAR_APPEND([LDFLAGS_NODIST], [" -Wl,--import-memory"])
+ AS_VAR_APPEND([LDFLAGS_NODIST], [" -Wl,--max-memory=10485760"])
+ ])
+
dnl increase initial memory and stack size, move stack first
dnl https://github.com/WebAssembly/wasi-libc/issues/233
AS_VAR_APPEND([LDFLAGS_NODIST], [" -z stack-size=524288 -Wl,--stack-first -Wl,--initial-memory=10485760"])