Hiya,
So I’m trying to build a raylib to wasm tutorial project and I’ve run into trouble installing emscripten.
Here is my dev shell flake.nix.
First of all, the shell hook is necessary, because otherwise emscripten tries to write to its own installation folder. This thread helped.
However, now on launching emcc
the following way
emcc -o index.html \
basic_window.c \
-lraylib -Os -Wall \
external/raylib-5.5/src/*.a \
-I external/raylib-5.5/src/ \
-L external/raylib-5.5/src/ \
-s USE_GLFW=3 \
-s ASYNCIFY \
--shell-file shell.html \
-s TOTAL_STACK=64MB \
-s INITIAL_MEMORY=128MB \
-s ASSERTIONS \
-DPLATFORM_WEB
I get an error
emcc: error: html-minifier-terser was not found! Please run "npm install" in Emscripten root directory to set up npm dependencies
Looking through the derivation and the emscripten code, it looks to me like the derivation puts node modules in ${emscripten}/share/emscripten/node_modules
, and emcc
is looking for them in ${emscripten}/share/emscripten/node_modules/.bin
and it is hardcoded and can not be reconfigured.
So then I did something very stupid that ended up working. I made a local copy of pkgs/development/compilers/emscripten/default.nix
, changed a line in installPhase
from
mkdir -p $appdir/node_modules
cp -r ${nodeModules}/* $appdir/node_modules
to
mkdir -p $appdir/node_modules/.bin
cp -r ${nodeModules}/* $appdir/node_modules
cp -r ${nodeModules}/* $appdir/node_modules/.bin
… and like magic it worked.
Here is the repo with the dumb solution: GitHub - glebdovzhenko/wasm_template
Assuming none of what I did is the nix way, any advice on how to do this the normal way? Thanks in advance.
This appears to be an edge case we haven’t taken into account — to date I’ve never needed a binary installed by a node module, so the existing logic sufficed. Do you have an interest in contributing this change as a PR? I’d be more than happy to review and commit if that helps!
Sure, I can submit this as a PR. For me this solution works for latest emscripten too, so I’ll update the version to 4.0.8. Thank you for responding!
Thanks! Note that we also managed to get the version bumped to 4.0.8 just yesterday (emscripten: 3.1.73 -> 4.0.8 by willcohen · Pull Request #380263 · NixOS/nixpkgs · GitHub, though it may not have hit the unstable release channel yet, looks like that one is a little backed up: Hydra - nixpkgs:trunk:unstable), so you shouldn’t need to mess with the version at all.
1 Like
That’s really nice! For now I’d circumvented the node_module issue by only compiling in DEBUG, where the minifier is not run after being unsuccessful in fixing the root cause.
Just tried out the new emscripten version and to me it looks like upstream reintroduced the 2021 issue [1] of copying the read-only flags of headers it copies from the store. I set EM_CACHE=/tmp/emscripten-cache/
and emcmake cmake
already fails in the compilation of the test program for compiler detection…
I think i found the upstream commit[2] that reintroduced it, but I’m a bit hesitant of reporting it since it looks like others are successfully using that version. I’d like to first exclude that I’m doing something weird here or it is something that should better be fixed on the nixpkgs side of things.
Would it be useful to add a few tests to nixpkgs that build a few small emscripten hello-world projects via the different tooling (directly emcc, emcmake, …) and different build flags, to make sure these things work? It feels a bit like there are many different ways to actually use/call emscripten and the testing by usage inside other packages and manual testing doesn’t seem to cover all usecases.
[1] Caching from a read-only base folder is impossible due to safe_copy copying the permissions bits · Issue #15374 · emscripten-core/emscripten · GitHub
[2] Update min python version from 3.6 to 3.8 (#23417) · emscripten-core/emscripten@e3dce64 · GitHub