1- # AWS-LC WASM Toolchain File
1+ # AWS-LC Emscripten Toolchain File
22#
33# This is a wrapper toolchain file for building AWS-LC with Emscripten.
44# It includes the standard Emscripten toolchain and configures pthread support
55# for multithreaded WASM builds.
66#
77# Usage:
8- # cmake -DCMAKE_TOOLCHAIN_FILE=util/wasm -toolchain.cmake ...
8+ # cmake -DCMAKE_TOOLCHAIN_FILE=util/emscripten -toolchain.cmake ...
99#
1010# Prerequisites:
1111# - EMSDK environment must be sourced before running cmake
@@ -30,17 +30,13 @@ endif()
3030# Include the standard Emscripten toolchain file
3131include ("${EMSCRIPTEN_TOOLCHAIN_FILE} " )
3232
33- # Override CMAKE_SYSTEM_NAME to "Generic" so AWS-LC treats this as an embedded
34- # target and skips the pthread requirement check in its CMakeLists.txt.
35- # The Emscripten toolchain sets this to "Emscripten" but AWS-LC's CMakeLists.txt
36- # only recognizes "Generic" and "Android" as systems that don't require pthreads
37- # validation (we handle pthreads via Emscripten's own implementation).
38- set (CMAKE_SYSTEM_NAME Generic)
33+ # The Emscripten toolchain file sets CMAKE_SYSTEM_NAME to "Emscripten" and
34+ # CMAKE_CROSSCOMPILING to TRUE, which AWS-LC's CMakeLists.txt recognizes.
35+ # We must set CMAKE_SYSTEM_PROCESSOR to wasm32 so that AWS-LC's architecture
36+ # detection uses "generic" instead of detecting the host's processor (e.g., x86_64)
37+ # which would add incompatible flags like -msse2.
3938set (CMAKE_SYSTEM_PROCESSOR wasm32)
4039
41- # Ensure cross-compiling is still set
42- set (CMAKE_CROSSCOMPILING TRUE )
43-
4440# Enable pthread support for multithreaded WASM builds.
4541# Emscripten implements pthreads using Web Workers and SharedArrayBuffer.
4642# This requires:
@@ -83,4 +79,4 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
8379# - The main browser thread cannot block (Atomics.wait doesn't work there)
8480# - Moving main() to a worker allows proper blocking on mutexes, joins, etc.
8581# - The main thread remains responsive for handling proxied operations
86- set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -sENVIRONMENT=node,worker -sNODERAWFS=1 -sEXIT_RUNTIME=1 -sALLOW_MEMORY_GROWTH=1 -sINITIAL_MEMORY=134217728 -sASSERTIONS=1 -sSTACK_SIZE=1048576 -pthread -sPTHREAD_POOL_SIZE=8 -sPROXY_TO_PTHREAD -Wno-pthreads-mem-growth" )
82+ set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -sENVIRONMENT=node,worker -sNODERAWFS=1 -sEXIT_RUNTIME=1 -sALLOW_MEMORY_GROWTH=1 -sINITIAL_MEMORY=134217728 -sASSERTIONS=1 -sSTACK_SIZE=1048576 -pthread -sPTHREAD_POOL_SIZE=8 -sPROXY_TO_PTHREAD -Wno-pthreads-mem-growth" )
0 commit comments