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
@@ -27,20 +27,16 @@ if(NOT EXISTS "${EMSCRIPTEN_TOOLCHAIN_FILE}")
2727 message (FATAL_ERROR "Emscripten toolchain file not found at: ${EMSCRIPTEN_TOOLCHAIN_FILE} " )
2828endif ()
2929
30+ # The Emscripten toolchain file defaults CMAKE_SYSTEM_PROCESSOR to "x86" via
31+ # EMSCRIPTEN_SYSTEM_PROCESSOR. We must set this BEFORE including the toolchain
32+ # to ensure AWS-LC's architecture detection uses "generic" instead of x86,
33+ # which would add incompatible flags like -msse2.
34+ set (EMSCRIPTEN_SYSTEM_PROCESSOR wasm32)
35+
3036# Include the standard Emscripten toolchain file
37+ # This sets CMAKE_SYSTEM_NAME to "Emscripten" and CMAKE_CROSSCOMPILING to TRUE.
3138include ("${EMSCRIPTEN_TOOLCHAIN_FILE} " )
3239
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)
39- set (CMAKE_SYSTEM_PROCESSOR wasm32)
40-
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