emscripten-core / emscripten

Emscripten: An LLVM-to-WebAssembly Compiler
Other
25.39k stars 3.26k forks source link

Discrepancy between CMake toolchain file and emcmake #16382

Open mmarczell-graphisoft opened 2 years ago

mmarczell-graphisoft commented 2 years ago

Why is the --experimental-wasm-threads argument only set in emcmake and not in Emscripten.cmake?

https://github.com/emscripten-core/emscripten/blob/7df40381247896886e918b5e7086ec7fe6df3e5b/emcmake.py#L41 vs https://github.com/emscripten-core/emscripten/blob/7df40381247896886e918b5e7086ec7fe6df3e5b/cmake/Modules/Platform/Emscripten.cmake#L411

If it was set in the latter, it would make using emcmake and using just the toolchain file more equivalent. One usecase for this is VSCode based development, where the editor's CMake plugin runs the CMake 'configure' step automatically whenever CMake files change. A so called "kit" file (link) can specify a toolchain file, but not a wrapper executable.

sbc100 commented 2 years ago

The changes was originally made here: https://github.com/emscripten-core/emscripten/pull/15590. I don't see any immediate reason why it should be in Emscripten.cmake instead.

I guess we want to avoid duplication we would need to find a way to set NODE_JS_EXECUTABLE from emcmake.py rather than CMAKE_CROSSCOMPILING_EMULATOR.

Feel free to propose a change

mmarczell-graphisoft commented 1 year ago

For posterity, an easy workaround is to put this in your CMakeLists.txt:


if (DEFINED NODE_JS_EXECUTABLE)
    set(CMAKE_CROSSCOMPILING_EMULATOR "${NODE_JS_EXECUTABLE};--experimental-wasm-threads")
endif()
david-fong commented 1 week ago

Now CMAKE_CROSSCOMPILING_EMULATOR seems to be defined in both emcmake.py and the toolchain file? Is this necessary?