From 0a3e73232bad9deb815e422f0a930b5c38d118b6 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Mon, 23 Jan 2023 12:47:02 +0900 Subject: [PATCH 1/4] Rename thread_spawn import Following the wit-defined ABI: https://github.com/WebAssembly/wasi-threads/pull/26 cf. https://github.com/WebAssembly/wasi-libc/pull/387 --- .../libraries/lib-wasi-threads/lib_wasi_threads_wrapper.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/iwasm/libraries/lib-wasi-threads/lib_wasi_threads_wrapper.c b/core/iwasm/libraries/lib-wasi-threads/lib_wasi_threads_wrapper.c index 46db6d524b..81efc67515 100644 --- a/core/iwasm/libraries/lib-wasi-threads/lib_wasi_threads_wrapper.c +++ b/core/iwasm/libraries/lib-wasi-threads/lib_wasi_threads_wrapper.c @@ -148,12 +148,12 @@ thread_spawn_wrapper(wasm_exec_env_t exec_env, uint32 start_arg) } /* clang-format off */ -#define REG_NATIVE_FUNC(func_name, signature) \ - { #func_name, func_name##_wrapper, signature, NULL } +#define REG_NATIVE_FUNC(name, func_name, signature) \ + { name, func_name##_wrapper, signature, NULL } /* clang-format on */ static NativeSymbol native_symbols_lib_wasi_threads[] = { REG_NATIVE_FUNC( - thread_spawn, "(i)i") }; + "thread-spawn", thread_spawn, "(i)i") }; uint32 get_lib_wasi_threads_export_apis(NativeSymbol **p_lib_wasi_threads_apis) From 193f11d778a8f3510287808a5a45985de2f66c58 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Wed, 25 Jan 2023 12:14:51 +0900 Subject: [PATCH 2/4] use the latest wasi-libc as samples/wasi-threads relies on it --- .github/workflows/compilation_on_android_ubuntu.yml | 7 ++++++- .github/workflows/compilation_on_macos.yml | 9 +++++++-- .github/workflows/compilation_on_sgx.yml | 7 ++++++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/.github/workflows/compilation_on_android_ubuntu.yml b/.github/workflows/compilation_on_android_ubuntu.yml index bf31c499fc..b8e2edd23e 100644 --- a/.github/workflows/compilation_on_android_ubuntu.yml +++ b/.github/workflows/compilation_on_android_ubuntu.yml @@ -326,8 +326,13 @@ jobs: - name: build wasi-libc (needed for wasi-threads) run: | - git clone --branch wasi-sdk-17 https://github.com/WebAssembly/wasi-libc + mkdir wasi-libc cd wasi-libc + git init + # "Rename thread_spawn import" commit on main branch + git fetch https://github.com/WebAssembly/wasi-libc \ + 8f5275796a82f8ecfd0833a4f3f444fa37ed4546 + git checkout FETCH_HEAD make \ AR=/opt/wasi-sdk/bin/llvm-ar \ NM=/opt/wasi-sdk/bin/llvm-nm \ diff --git a/.github/workflows/compilation_on_macos.yml b/.github/workflows/compilation_on_macos.yml index 1e5ff415b6..31bd424bae 100644 --- a/.github/workflows/compilation_on_macos.yml +++ b/.github/workflows/compilation_on_macos.yml @@ -268,8 +268,13 @@ jobs: - name: build wasi-libc (needed for wasi-threads) run: | - git clone --branch wasi-sdk-17 https://github.com/WebAssembly/wasi-libc + mkdir wasi-libc cd wasi-libc + git init + # "Rename thread_spawn import" commit on main branch + git fetch https://github.com/WebAssembly/wasi-libc \ + 8f5275796a82f8ecfd0833a4f3f444fa37ed4546 + git checkout FETCH_HEAD make \ AR=/opt/wasi-sdk/bin/llvm-ar \ NM=/opt/wasi-sdk/bin/llvm-nm \ @@ -329,4 +334,4 @@ jobs: mkdir build && cd build cmake -DWASI_SYSROOT=`pwd`/../../../core/deps/wasi-libc/sysroot .. cmake --build . --config Release --parallel 4 - ./iwasm wasm-apps/no_pthread.wasm \ No newline at end of file + ./iwasm wasm-apps/no_pthread.wasm diff --git a/.github/workflows/compilation_on_sgx.yml b/.github/workflows/compilation_on_sgx.yml index c4d4142dde..efcb294ae8 100644 --- a/.github/workflows/compilation_on_sgx.yml +++ b/.github/workflows/compilation_on_sgx.yml @@ -270,8 +270,13 @@ jobs: - name: build wasi-libc (needed for wasi-threads) run: | - git clone --branch wasi-sdk-17 https://github.com/WebAssembly/wasi-libc + mkdir wasi-libc cd wasi-libc + git init + # "Rename thread_spawn import" commit on main branch + git fetch https://github.com/WebAssembly/wasi-libc \ + 8f5275796a82f8ecfd0833a4f3f444fa37ed4546 + git checkout FETCH_HEAD make \ AR=/opt/wasi-sdk/bin/llvm-ar \ NM=/opt/wasi-sdk/bin/llvm-nm \ From efa6d2ae8eb2d073578b4918792a3a22d08467f2 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Thu, 26 Jan 2023 00:11:54 +0900 Subject: [PATCH 3/4] samples/wasi-threads: Update the target to match the latest wasi-libc --- samples/wasi-threads/wasm-apps/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/wasi-threads/wasm-apps/CMakeLists.txt b/samples/wasi-threads/wasm-apps/CMakeLists.txt index 0da9aa749f..4836c4f09a 100644 --- a/samples/wasi-threads/wasm-apps/CMakeLists.txt +++ b/samples/wasi-threads/wasm-apps/CMakeLists.txt @@ -14,7 +14,7 @@ endif () set (CMAKE_SYSROOT "${WASI_SYSROOT}") set (CMAKE_C_COMPILER "${WASI_SDK_DIR}/bin/clang") set (CMAKE_ASM_COMPILER "${WASI_SDK_DIR}/bin/clang") -set (CMAKE_C_COMPILER_TARGET "wasm32-wasi") +set (CMAKE_C_COMPILER_TARGET "wasm32-wasi-threads") function (compile_sample SOURCE_FILE) get_filename_component (FILE_NAME ${SOURCE_FILE} NAME_WLE) @@ -36,4 +36,4 @@ function (compile_sample SOURCE_FILE) endfunction () compile_sample(no_pthread.c wasi_thread_start.S) -compile_sample(thread_termination.c wasi_thread_start.S) \ No newline at end of file +compile_sample(thread_termination.c wasi_thread_start.S) From b9947b23e3d75fe0734ec870259c3157d62f008b Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Thu, 26 Jan 2023 04:08:25 +0900 Subject: [PATCH 4/4] samples/wasi-threads: Fix wasm app target As far as I know, cmake can't handle two different compilers and targets within a project as this sample is trying to do. This commit is a band-aid fix. While CMAKE_C_COMPILER_TARGET here happens to work when both of host compiler and wasm compiler are clang, it doesn't seem working if the host compiler is gcc. (as it is on the linux jobs on the CI.) --- samples/wasi-threads/wasm-apps/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/wasi-threads/wasm-apps/CMakeLists.txt b/samples/wasi-threads/wasm-apps/CMakeLists.txt index 4836c4f09a..c586978685 100644 --- a/samples/wasi-threads/wasm-apps/CMakeLists.txt +++ b/samples/wasi-threads/wasm-apps/CMakeLists.txt @@ -14,7 +14,7 @@ endif () set (CMAKE_SYSROOT "${WASI_SYSROOT}") set (CMAKE_C_COMPILER "${WASI_SDK_DIR}/bin/clang") set (CMAKE_ASM_COMPILER "${WASI_SDK_DIR}/bin/clang") -set (CMAKE_C_COMPILER_TARGET "wasm32-wasi-threads") +set (CMAKE_EXE_LINKER_FLAGS "-target wasm32-wasi-threads") function (compile_sample SOURCE_FILE) get_filename_component (FILE_NAME ${SOURCE_FILE} NAME_WLE)