I’m writing a medium-sized C++ program (around 900 lines; quite a few templates, idiomatic C++, only RAII and collections, no raw arrays, no pointers, no manual memory allocation). Native build for my application takes around 5 minutes, but problems start with emscripten build.
Webassembly is emitted relatively quickly, in a few seconds. The build stalls on acorn-optimizer trying to optimize the libstdc++ runtime (?). It’s been running for 20 minutes, and i tried to re-run and kill it multiple times to get it to build my application.
I use the following commandline:
em++ -std=c++20 -o tau.html lexer.cpp symtab.cpp parser.cpp decl.cpp tau.cpp -O3 -s WASM=1
em++ launches a process with the following commandline:
/usr/bin/node /usr/share/emscripten/tools/acorn-optimizer.js /tmp/emscripten_temp_gwg74gkp/tau.js AJSDCE minifyWhitespace
which is constantly using a single core of my processor and ~50MB (fluctuating) of RAM, and due to it, the compilation doesn’t finish.
tau.js contents follow: link. I managed to (somewhat) track down the issue – a 800-line C++ project seems to be too big for Emscripten to handle. asm.js output is well over 6 megabytes on
-g3 -O0 build (the one which doesn’t run the minifier)
I was surprised at the inefficiency and horribleness of the Emscripten ABI.
My question follows – how do I get this project to build and optimize? Do i have to leave the build overnight every time I want to compile something? Is there a better tool for compiling C++ and targetting webasm or asm.js?
I gave up on
-O3 and decided that I’ll try
-O1, without success – compiler crashes:
em++ -std=c++20 -o tau.html lexer.cpp symtab.cpp parser.cpp decl.cpp tau.cpp -O1 -s WASM=0 Traceback (most recent call last): File "/usr/share/emscripten/em++.py", line 14, in <module> sys.exit(emcc.run(sys.argv)) File "/usr/share/emscripten/emcc.py", line 2156, in run post_link(options, wasm_target, wasm_target, target) File "/usr/share/emscripten/emcc.py", line 2320, in post_link generate_html(target, options, js_target, target_basename, File "/usr/share/emscripten/emcc.py", line 3075, in generate_html minify_html(target) File "/usr/share/emscripten/emcc.py", line 3049, in minify_html shared.check_call(['htmlmin', opts, '--', filename, filename]) File "/usr/share/emscripten/tools/shared.py", line 104, in check_call return run_process(cmd, *args, **kw) File "/usr/share/emscripten/tools/shared.py", line 94, in run_process ret = subprocess.run(cmd, check=check, input=input, *args, **kw) File "/usr/lib/python3.9/subprocess.py", line 505, in run with Popen(*popenargs, **kwargs) as process: File "/usr/lib/python3.9/subprocess.py", line 951, in __init__ self._execute_child(args, executable, preexec_fn, close_fds, File "/usr/lib/python3.9/subprocess.py", line 1756, in _execute_child self.pid = _posixsubprocess.fork_exec( TypeError: expected str, bytes or os.PathLike object, not list make: *** [Makefile:44: webasm] Error 1
I also tried
-g3 -O0, but the output code doesn’t work:
7zipped output of emscripten for -g3 -O0 follows: link. I don’t think my source code is significant here – the issue clearly happens within emscripten runtime.
For the record, I’m using emscripten built using emsdk on 24 January this year, that is, 2021.
Source: Windows Questions C++