mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2025-05-11 20:21:11 +00:00

`wasi-sdk-20` pre-release can be used to avoid building `wasi-libc` to enable threads. It's not possible to use `wasi-sdk-20` pre-release on Ubuntu 20.04 because of incompatibility with the glibc version: ```bash /opt/wasi-sdk/bin/clang: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found (required by /opt/wasi-sdk/bin/clang) ```
48 lines
1.4 KiB
CMake
48 lines
1.4 KiB
CMake
# Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
if (APPLE)
|
|
set (HAVE_FLAG_SEARCH_PATHS_FIRST 0)
|
|
set (CMAKE_C_LINK_FLAGS "")
|
|
set (CMAKE_CXX_LINK_FLAGS "")
|
|
endif ()
|
|
|
|
if (NOT DEFINED WASI_SDK_DIR)
|
|
set (WASI_SDK_DIR "/opt/wasi-sdk")
|
|
endif ()
|
|
|
|
if (DEFINED WASI_SYSROOT)
|
|
set (CMAKE_SYSROOT "${WASI_SYSROOT}")
|
|
endif ()
|
|
|
|
set (CMAKE_C_COMPILER "${WASI_SDK_DIR}/bin/clang")
|
|
set (CMAKE_ASM_COMPILER "${WASI_SDK_DIR}/bin/clang")
|
|
set (CMAKE_EXE_LINKER_FLAGS "-target wasm32-wasi-threads")
|
|
|
|
if ("$ENV{COLLECT_CODE_COVERAGE}" STREQUAL "1" OR COLLECT_CODE_COVERAGE EQUAL 1)
|
|
set (CMAKE_C_FLAGS "")
|
|
set (CMAKE_CXX_FLAGS "")
|
|
endif ()
|
|
|
|
function (compile_sample SOURCE_FILE)
|
|
get_filename_component (FILE_NAME ${SOURCE_FILE} NAME_WLE)
|
|
set (WASM_MODULE ${FILE_NAME}.wasm)
|
|
add_executable (${WASM_MODULE} ${SOURCE_FILE} ${ARGN})
|
|
|
|
target_compile_options (${WASM_MODULE} PRIVATE
|
|
-pthread -ftls-model=local-exec)
|
|
|
|
target_link_options (${WASM_MODULE} PRIVATE
|
|
-z stack-size=32768
|
|
LINKER:--export=__heap_base
|
|
LINKER:--export=__data_end
|
|
LINKER:--shared-memory,--max-memory=1966080
|
|
LINKER:--export=wasi_thread_start
|
|
LINKER:--export=malloc
|
|
LINKER:--export=free
|
|
)
|
|
endfunction ()
|
|
|
|
compile_sample(no_pthread.c wasi_thread_start.S)
|
|
compile_sample(thread_termination.c wasi_thread_start.S)
|