From 655b4d8ec68e6871f049e5250fd3a35d60a9810e Mon Sep 17 00:00:00 2001 From: Roman Volosatovs Date: Thu, 12 Feb 2026 18:50:43 +0100 Subject: [PATCH 1/4] build wasip3 target Signed-off-by: Roman Volosatovs --- CMakeLists.txt | 2 +- cmake/wasi-sdk-sysroot.cmake | 8 ++++---- wasi-sdk-p3.cmake | 37 ++++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 wasi-sdk-p3.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index a0d3fca77..f3f78ccf8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,7 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") project(wasi-sdk) include(ExternalProject) -set(WASI_SDK_TARGETS "wasm32-wasi;wasm32-wasip1;wasm32-wasip2;wasm32-wasip1-threads;wasm32-wasi-threads" +set(WASI_SDK_TARGETS "wasm32-wasi;wasm32-wasip1;wasm32-wasip2;wasm32-wasip3;wasm32-wasip1-threads;wasm32-wasi-threads" CACHE STRING "List of WASI targets to build") option(WASI_SDK_BUILD_TOOLCHAIN "Build a toolchain instead of the sysroot" OFF) diff --git a/cmake/wasi-sdk-sysroot.cmake b/cmake/wasi-sdk-sysroot.cmake index c19d0c60f..b5b9f1c72 100644 --- a/cmake/wasi-sdk-sysroot.cmake +++ b/cmake/wasi-sdk-sysroot.cmake @@ -106,7 +106,7 @@ define_compiler_rt(wasm32-wasip1-threads) # In addition to the default installation of `compiler-rt` itself also copy # around some headers and make copies of the `wasi` directory as `wasip1` and -# `wasip2` +# `wasip2` and `wasip3` execute_process( COMMAND ${CMAKE_C_COMPILER} -print-resource-dir OUTPUT_VARIABLE clang_resource_dir @@ -144,9 +144,9 @@ function(define_wasi_libc_sub target target_suffix lto) get_property(directory_cflags DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY COMPILE_OPTIONS) set(extra_cflags_list "${WASI_SDK_CPU_CFLAGS} ${CMAKE_C_FLAGS} ${directory_cflags}") - if(${target} MATCHES p2) - # Always enable `-fPIC` for the `wasm32-wasip2` target. This makes `libc.a` - # more flexible and usable in dynamic linking situations. + if(${target} MATCHES "p[23]") + # Always enable `-fPIC` for the `wasm32-wasip2` and `wasm32-wasip3` targets. + # This makes `libc.a` more flexible and usable in dynamic linking situations. list(APPEND extra_cflags_list -fPIC) endif() diff --git a/wasi-sdk-p3.cmake b/wasi-sdk-p3.cmake new file mode 100644 index 000000000..f73756225 --- /dev/null +++ b/wasi-sdk-p3.cmake @@ -0,0 +1,37 @@ +# Cmake toolchain description file for the Makefile + +# Until Platform/WASI.cmake is upstream we need to inject the path to it +# into CMAKE_MODULE_PATH. +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}") + +set(CMAKE_SYSTEM_NAME WASI) +set(CMAKE_SYSTEM_VERSION 1) +set(CMAKE_SYSTEM_PROCESSOR wasm32) +set(triple wasm32-wasip3) + +if(WIN32) + set(WASI_HOST_EXE_SUFFIX ".exe") +else() + set(WASI_HOST_EXE_SUFFIX "") +endif() + +# When building from source, WASI_SDK_PREFIX represents the generated directory +if(NOT WASI_SDK_PREFIX) + set(WASI_SDK_PREFIX ${CMAKE_CURRENT_LIST_DIR}/../../) +endif() + +set(CMAKE_C_COMPILER ${WASI_SDK_PREFIX}/bin/clang${WASI_HOST_EXE_SUFFIX}) +set(CMAKE_CXX_COMPILER ${WASI_SDK_PREFIX}/bin/clang++${WASI_HOST_EXE_SUFFIX}) +set(CMAKE_ASM_COMPILER ${WASI_SDK_PREFIX}/bin/clang${WASI_HOST_EXE_SUFFIX}) +set(CMAKE_AR ${WASI_SDK_PREFIX}/bin/llvm-ar${WASI_HOST_EXE_SUFFIX}) +set(CMAKE_RANLIB ${WASI_SDK_PREFIX}/bin/llvm-ranlib${WASI_HOST_EXE_SUFFIX}) +set(CMAKE_C_COMPILER_TARGET ${triple}) +set(CMAKE_CXX_COMPILER_TARGET ${triple}) +set(CMAKE_ASM_COMPILER_TARGET ${triple}) + +# Don't look in the sysroot for executables to run during the build +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +# Only look in the sysroot (not in the host paths) for the rest +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) From 93e00cf89e74d53ee15c4c1fd5b43bbb424392cb Mon Sep 17 00:00:00 2001 From: Roman Volosatovs Date: Fri, 13 Feb 2026 13:52:11 +0100 Subject: [PATCH 2/4] enable CM-async/wasip3 in wasmtime tests Signed-off-by: Roman Volosatovs --- tests/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 3ed477658..c573aea65 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -102,6 +102,9 @@ function(add_testcase runwasi test) if(WASI_SDK_EXCEPTIONS) set(runner "${runner} -Wexceptions") endif() + if(target MATCHES "wasip3") + set(runner "${runner} -Wcomponent-model-async -Sp3") + endif() endif() add_test( NAME test-${target_name} From 48fe4e32ea5412c86d05032a4e10a759fee434a6 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 3 Mar 2026 09:32:35 -0800 Subject: [PATCH 3/4] Adjust wasip3 defaults * Don't build the target by default yet * Build a separate compiler-rt for updated ABI eventually --- CMakeLists.txt | 2 +- cmake/wasi-sdk-sysroot.cmake | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f3f78ccf8..a0d3fca77 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,7 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") project(wasi-sdk) include(ExternalProject) -set(WASI_SDK_TARGETS "wasm32-wasi;wasm32-wasip1;wasm32-wasip2;wasm32-wasip3;wasm32-wasip1-threads;wasm32-wasi-threads" +set(WASI_SDK_TARGETS "wasm32-wasi;wasm32-wasip1;wasm32-wasip2;wasm32-wasip1-threads;wasm32-wasi-threads" CACHE STRING "List of WASI targets to build") option(WASI_SDK_BUILD_TOOLCHAIN "Build a toolchain instead of the sysroot" OFF) diff --git a/cmake/wasi-sdk-sysroot.cmake b/cmake/wasi-sdk-sysroot.cmake index b5b9f1c72..38f804c73 100644 --- a/cmake/wasi-sdk-sysroot.cmake +++ b/cmake/wasi-sdk-sysroot.cmake @@ -101,9 +101,20 @@ function(define_compiler_rt target) add_dependencies(compiler-rt-build compiler-rt-build-${target}) endfunction() +# The `compiler-rt` for `wasm32-wasip1` will be reused for `wasm32-wasip2` and +# `wasm32-wasi`. The version for `wasm32-wasip1-threads` will be reused for +# `wasm32-wasi-threads`. Different builds are needed for different codegen flags +# and such across the threaded/not target. define_compiler_rt(wasm32-wasip1) define_compiler_rt(wasm32-wasip1-threads) +# If a p3 target is requested, also build compiler-rt for that target. WASIp3 +# will eventually have a different ABI than wasm32-wasip2, so this separate +# build is needed. +if(WASI_SDK_TARGETS MATCHES p3) + define_compiler_rt(wasm32-wasip3) +endif() + # In addition to the default installation of `compiler-rt` itself also copy # around some headers and make copies of the `wasi` directory as `wasip1` and # `wasip2` and `wasip3` @@ -134,7 +145,6 @@ add_dependencies(compiler-rt-post-build compiler-rt-build) add_custom_target(compiler-rt DEPENDS compiler-rt-build compiler-rt-post-build) - # ============================================================================= # wasi-libc build logic # ============================================================================= From 551546f8e3f9cc7b08f75b120a66f99ff4386c5e Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 3 Mar 2026 09:34:42 -0800 Subject: [PATCH 4/4] Add wasi-sdk-p3.cmake to the sysroot --- cmake/wasi-sdk-toolchain.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/cmake/wasi-sdk-toolchain.cmake b/cmake/wasi-sdk-toolchain.cmake index c02560d6b..848bd264f 100644 --- a/cmake/wasi-sdk-toolchain.cmake +++ b/cmake/wasi-sdk-toolchain.cmake @@ -156,6 +156,7 @@ copy_misc_file(wasi-sdk.cmake cmake) copy_misc_file(wasi-sdk-pthread.cmake cmake) copy_misc_file(wasi-sdk-p1.cmake cmake) copy_misc_file(wasi-sdk-p2.cmake cmake) +copy_misc_file(wasi-sdk-p3.cmake cmake) copy_misc_file(cmake/Platform/WASI.cmake cmake/Platform) function(copy_cfg_file compiler)