When trying to compile a minimal C++ example to JS with emscripten via the nix package I get:
em++: error: html-minifier-terser was not found! Please run "npm install" in Emscripten root directory to set up npm dependencies
make[2]: *** [CMakeFiles/EmscriptenNixDev.dir/build.make:98: EmscriptenNixDev.html] Error 1
make[2]: *** Deleting file 'EmscriptenNixDev.html'
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/EmscriptenNixDev.dir/all] Error 2
make: *** [Makefile:136: all] Error 2
It looks like emscripten tries to run html-minifier-terser from the node_modules/.bin directory which does not exist relative to the emscripten store in share/emscripten/node_modules.
[ 50%] Building CXX object CMakeFiles/EmscriptenNixDev.dir/main.cpp.o
[100%] Linking CXX executable EmscriptenNixDev.html
cache:INFO: generating system asset: symbol_lists/5788af184bd9f224858e62d950018500aedeccd3.json... (this will be cached in "/nix/store/cacfb89l26hya9wzfhjn52w2cyfgbgkg-emscripten-3.1.51/share/emscripten/cache/symbol_lists/5788af184bd9f224858e62d950018500aedeccd3.json" for subsequent builds)
cache:INFO: - ok
cache:INFO: generating system library: sysroot/lib/wasm32-emscripten/lto/libGL-webgl2.a... (this will be cached in "/nix/store/cacfb89l26hya9wzfhjn52w2cyfgbgkg-emscripten-3.1.51/share/emscripten/cache/sysroot/lib/wasm32-emscripten/lto/libGL-webgl2.a" for subsequent builds)
system_libs:INFO: compiled 4 inputs in 0.12s
cache:INFO: - ok
cache:INFO: generating system library: sysroot/lib/wasm32-emscripten/lto/libstubs.a... (this will be cached in "/nix/store/cacfb89l26hya9wzfhjn52w2cyfgbgkg-emscripten-3.1.51/share/emscripten/cache/sysroot/lib/wasm32-emscripten/lto/libstubs.a" for subsequent builds)
system_libs:INFO: compiled 2 inputs in 0.12s
cache:INFO: - ok
cache:INFO: generating system library: sysroot/lib/wasm32-emscripten/lto/libc.a... (this will be cached in "/nix/store/cacfb89l26hya9wzfhjn52w2cyfgbgkg-emscripten-3.1.51/share/emscripten/cache/sysroot/lib/wasm32-emscripten/lto/libc.a" for subsequent builds)
system_libs:INFO: compiled 1025 inputs in 5.80s
cache:INFO: - ok
cache:INFO: generating system library: sysroot/lib/wasm32-emscripten/lto/libc++abi-noexcept.a... (this will be cached in "/nix/store/cacfb89l26hya9wzfhjn52w2cyfgbgkg-emscripten-3.1.51/share/emscripten/cache/sysroot/lib/wasm32-emscripten/lto/libc++abi-noexcept.a" for subsequent builds)
system_libs:INFO: compiled 16 inputs in 0.87s
cache:INFO: - ok
em++: error: html-minifier-terser was not found! Please run "npm install" in Emscripten root directory to set up npm dependencies
make[2]: *** [CMakeFiles/EmscriptenNixDev.dir/build.make:98: EmscriptenNixDev.html] Error 1
make[2]: *** Deleting file 'EmscriptenNixDev.html'
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/EmscriptenNixDev.dir/all] Error 2
make: *** [Makefile:136: all] Error 2
Expected behavior
This works perfectly after adding -g2; however results in a huge binary size.
Notify maintainers
Metadata
Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.
Describe the bug
When trying to compile a minimal C++ example to JS with emscripten via the nix package I get:
It looks like emscripten tries to run
html-minifier-terser
from thenode_modules/.bin
directory which does not exist relative to the emscripten store inshare/emscripten/node_modules
.the relevant emcc.py line: https://github.com/emscripten-core/emscripten/blob/423a77f9be2a26d5a86dd9e4aec4e095cd73fb70/emcc.py#L3724
Steps To Reproduce
Steps to reproduce the behavior:
set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # clangd
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -flto") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -O3")
set(CMAKE_EXECUTABLE_SUFFIX ".html") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s USE_GLFW=3 --shell-file ${CMAKE_CURRENT_SOURCE_DIR}/index.html -sWASM=1 -s ASYNCIFY=1" ) add_executable(EmscriptenNixDev main.cpp)
install(TARGETS EmscriptenNixDev RUNTIME DESTINATION bin)
Expected behavior
This works perfectly after adding -g2; however results in a huge binary size.
Notify maintainers
Metadata
Please run
nix-shell -p nix-info --run "nix-info -m"
and paste the result.Add a :+1: reaction to issues you find important.