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
20 changes: 15 additions & 5 deletions cmake/wasi-sdk-sysroot.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,23 @@ 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`
# `wasip2` and `wasip3`
execute_process(
COMMAND ${CMAKE_C_COMPILER} -print-resource-dir
OUTPUT_VARIABLE clang_resource_dir
Expand Down Expand Up @@ -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
# =============================================================================
Expand All @@ -144,9 +154,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()

Expand Down
1 change: 1 addition & 0 deletions cmake/wasi-sdk-toolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
37 changes: 37 additions & 0 deletions wasi-sdk-p3.cmake
Original file line number Diff line number Diff line change
@@ -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)
Loading