Skip to content

Commit 48bf11d

Browse files
committed
build(docker): use emulated pthreads
Until wasmtime supports threads in its C-API.
1 parent c890071 commit 48bf11d

File tree

5 files changed

+17
-7
lines changed

5 files changed

+17
-7
lines changed

src/docker/itk-wasm-base/Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ RUN . /itk_wasm_env_vars.sh && sed -i -e "/^set(DCMTK_GIT_REPOSITORY/c\set(DCMTK
4343
RUN . /itk_wasm_env_vars.sh && sed -i -e "/^set(DCMTK_GIT_TAG/c\set(DCMTK_GIT_TAG \"${ITK_WASM_DCMTK_GIT_TAG}\")" \
4444
/ITK/Modules/ThirdParty/DCMTK/DCMTKGitTag.cmake
4545

46+
# Current overwrite for the dockcross image to use emulated threads.
47+
# This can be removed after wasmtime supports threads in its C-API.
48+
COPY clang-wasi-threads-sysroot.sh clang++-wasi-threads-sysroot.sh /usr/local/bin/
49+
4650
ARG CMAKE_BUILD_TYPE=Release
4751

4852
ARG LDFLAGS

src/docker/itk-wasm-base/build.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ done
3131
set -- "${newparams[@]}" # overwrites the original positional params
3232

3333
# Note: also need to set in wasi-sdk-pthread-itkwasm.cmake
34-
wasi_ld_flags="-flto -lwasi-emulated-process-clocks -lwasi-emulated-signal -lc-printscan-long-double"
35-
wasi_c_flags="-flto -msimd128 -D_WASI_EMULATED_PROCESS_CLOCKS -D_WASI_EMULATED_SIGNAL"
34+
wasi_ld_flags="-D_WASI_EMULATED_PTHREAD -flto -lwasi-emulated-process-clocks -lwasi-emulated-signal -lc-printscan-long-double"
35+
wasi_c_flags="-lwasi-emulated-pthread -flto -msimd128 -D_WASI_EMULATED_PROCESS_CLOCKS -D_WASI_EMULATED_SIGNAL"
3636

3737
emscripten_debug_ld_flags="-fno-lto -s ALLOW_MEMORY_GROWTH=1 -s MAXIMUM_MEMORY=4GB"
3838
emscripten_debug_c_flags="-fno-lto -Wno-warn-absolute-paths"
3939

40-
wasi_debug_ld_flags="-fno-lto -lwasi-emulated-process-clocks -lwasi-emulated-signal -lc-printscan-long-double"
41-
wasi_debug_c_flags="-fno-lto -D_WASI_EMULATED_PROCESS_CLOCKS -D_WASI_EMULATED_SIGNAL"
40+
wasi_debug_ld_flags="-D_WASI_EMULATED_PTHREAD -fno-lto -lwasi-emulated-process-clocks -lwasi-emulated-signal -lc-printscan-long-double"
41+
wasi_debug_c_flags="-lwasi-emulated-pthread -fno-lto -D_WASI_EMULATED_PROCESS_CLOCKS -D_WASI_EMULATED_SIGNAL"
4242

4343
$exe $build_cmd $tag_flag quay.io/itkwasm/emscripten-base:latest-$host_arch \
4444
--build-arg IMAGE=quay.io/itkwasm/emscripten-base \
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env sh
2+
3+
exec ${WASI_SDK_PATH}/bin/clang++ --target=wasm32-wasi-threads --sysroot=${WASI_SYSROOT} "$@"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env sh
2+
3+
exec ${WASI_SDK_PATH}/bin/clang --target=wasm32-wasi-threads --sysroot=${WASI_SYSROOT} "$@"

src/docker/itk-wasm-base/wasi-sdk-pthread-itkwasm.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ set(CMAKE_SYSTEM_NAME WASI)
44
set(CMAKE_SYSTEM_VERSION 1)
55
set(CMAKE_SYSTEM_PROCESSOR wasm32)
66
set(triple wasm32-wasi-threads)
7-
set(CMAKE_C_FLAGS "-pthread -matomics -mbulk-memory -flto -msimd128 -D_WASI_EMULATED_PROCESS_CLOCKS -D_WASI_EMULATED_SIGNAL ${CMAKE_C_FLAGS}")
7+
set(CMAKE_C_FLAGS "-D_WASI_EMULATED_PTHREAD -mbulk-memory -flto -msimd128 -D_WASI_EMULATED_PROCESS_CLOCKS -D_WASI_EMULATED_SIGNAL ${CMAKE_C_FLAGS}")
88
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_CXX_FLAGS}")
99
# wasi-threads requires --import-memory.
1010
# wasi requires --export-memory.
1111
# (--export-memory is implicit unless --import-memory is given)
12-
set(CMAKE_EXE_LINKER_FLAGS "-Wl,--import-memory ${CMAKE_EXE_LINKER_FLAGS}")
12+
# set(CMAKE_EXE_LINKER_FLAGS "-Wl,--import-memory ${CMAKE_EXE_LINKER_FLAGS}")
1313
set(CMAKE_EXE_LINKER_FLAGS "-Wl,--export-memory ${CMAKE_EXE_LINKER_FLAGS}")
1414
# ITK-Wasm
15-
set(CMAKE_EXE_LINKER_FLAGS "-Wl,--initial-memory=8388608,--max-memory=4294967296,--shared-memory -flto -lwasi-emulated-process-clocks -lwasi-emulated-signal -lc-printscan-long-double ${CMAKE_EXE_LINKER_FLAGS}")
15+
set(CMAKE_EXE_LINKER_FLAGS "-lwasi-emulated-pthread -flto -lwasi-emulated-process-clocks -lwasi-emulated-signal -lc-printscan-long-double ${CMAKE_EXE_LINKER_FLAGS}")
1616

1717
if(WIN32)
1818
set(WASI_HOST_EXE_SUFFIX ".exe")

0 commit comments

Comments
 (0)