wasi-sdk icon indicating copy to clipboard operation
wasi-sdk copied to clipboard

with wasi-sdk-p2.cmake, the pthread can't be detected when build with CMake project

Open zhuyipeng opened this issue 10 months ago • 3 comments

hi, all,

I am trying to compile mqtt into webassembly, cmake come out pthread detect error as followed showing. I went with wasi-sdk-pthread.cmake, pthread check passed.

does anyone encounter this issue? how should I fix it?

`cmake -DCMAKE_TOOLCHAIN_FILE=/mnt/d/UserData/z003n71c/workspace/wasi-sdk/build/install/share/cmake/wasi-sdk-p2.cmake -DWITH_TLS=OFF -DWITH_UNIX_SOCKETS=OFF .. -- The C compiler identification is Clang 19.1.5 -- The CXX compiler identification is Clang 19.1.5 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: /mnt/d/UserData/z003n71c/workspace/wasi-sdk/build/install/bin/clang - skipped -- Detecting C compile features -- Detecting C compile features - done -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: /mnt/d/UserData/z003n71c/workspace/wasi-sdk/build/install/bin/clang++ - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done -- WITH_DLT = OFF -- Could NOT find cJSON (missing: CJSON_INCLUDE_DIR CJSON_LIBRARY) -- Optional dependency cJSON not found. Some features will be disabled. -- Performing Test CMAKE_HAVE_LIBC_PTHREAD -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed -- Check if compiler accepts -pthread -- Check if compiler accepts -pthread - no -- Looking for pthread_create in pthreads -- Looking for pthread_create in pthreads - not found -- Looking for pthread_create in pthread -- Looking for pthread_create in pthread - not found CMake Error at /usr/local/cmake-4.0.0-rc3-linux-x86_64/share/cmake-4.0/Modules/FindPackageHandleStandardArgs.cmake:227 (message): Could NOT find Threads (missing: Threads_FOUND) Call Stack (most recent call first): /usr/local/cmake-4.0.0-rc3-linux-x86_64/share/cmake-4.0/Modules/FindPackageHandleStandardArgs.cmake:591 (_FPHSA_FAILURE_MESSAGE) /usr/local/cmake-4.0.0-rc3-linux-x86_64/share/cmake-4.0/Modules/FindThreads.cmake:226 (find_package_handle_standard_args) lib/CMakeLists.txt:97 (find_package)

-- Configuring incomplete, errors occurred!`

zhuyipeng avatar Mar 13 '25 08:03 zhuyipeng

This is currently expected, wasm32-wasip2 doesn't support pthreads. That's different from wasm32-wasip1-threads, which wasi-sdk-pthread.cmake uses, which does support pthreads.

alexcrichton avatar Mar 13 '25 15:03 alexcrichton

@alexcrichton thanks for your quickly feedback, however if I use wasm32-wasip1-threads, the sockets will not be supported. :( any suggestion here? by the way, if the module need interface of 'getaddrinfo' and I see wasi-sdk will not support it, any replace interface I could use? thank you.

zhuyipeng avatar Mar 17 '25 07:03 zhuyipeng

If you want multithreaded sockets, you'll need to wait for https://github.com/WebAssembly/shared-everything-threads, a wasm proposal which will help enable multithreading in the component model. The time-scale of that is likely on the scale of years though.

alexcrichton avatar Mar 17 '25 14:03 alexcrichton