Build `wasip3` target (#593)

Build `wasip3` target

~Requires #592~

There's a lot of failing tests currently, so we'll probably want to
rebase this PR as we pull in more recent versions of `wasi-libc` and
merge once tests pass

---------

Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
Co-authored-by: Alex Crichton <alex@alexcrichton.com>
pull/599/head
Roman Volosatovs 6 months ago committed by GitHub
parent b7d8add13b
commit 3f0e04a053
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -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
@ -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
# =============================================================================
@ -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()

@ -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)

@ -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}

@ -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…
Cancel
Save