emscripten icon indicating copy to clipboard operation
emscripten copied to clipboard

emrun does not work well with `PROXY_TO_WORKER`

Open stevenwdv opened this issue 8 months ago • 4 comments

--emrun arguments are not passed from the URL to the program when using -sPROXY_TO_WORKER. Output capturing also doesn't work.

Build

print_args.cpp:

#include <iostream>

int main(int argc, char **argv) {
	std::cout << argc << " argument(s):" << '\n';
	for (int i{}; i < argc; ++i)
		std::cout << "- " << argv[i] << '\n';
}
Command & output
em++ print_args.cpp --emrun -sDEFAULT_LIBRARY_FUNCS_TO_INCLUDE='$addOnExit' -sPROXY_TO_WORKER -o print_args.html
 "/home/swdv/emsdk/upstream/bin/clang++" -target wasm32-unknown-emscripten -fignore-exceptions -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --sysroot=/home/swdv/emsdk/upstream/emscripten/cache/sysroot -DEMSCRIPTEN -Xclang -iwithsysroot/include/fakesdl -Xclang -iwithsysroot/include/compat -v -c print_args.cpp -o /tmp/emscripten_temp_69ogm86d/print_args_0.o
clang version 21.0.0git (https:/github.com/llvm/llvm-project 148111fdcf0e807fe74274b18fcf65c4cff45d63)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /home/swdv/emsdk/upstream/bin
 (in-process)
 "/home/swdv/emsdk/upstream/bin/clang-21" -cc1 -triple wasm32-unknown-emscripten -emit-obj -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name print_args.cpp -mrelocation-model static -mframe-pointer=none -ffp-contract=on -fno-rounding-math -mconstructor-aliases -target-cpu generic -fvisibility=hidden -debugger-tuning=gdb -fdebug-compilation-dir=/home/swdv/core -v -fcoverage-compilation-dir=/home/swdv/core -resource-dir /home/swdv/emsdk/upstream/lib/clang/21 -D EMSCRIPTEN -isysroot /home/swdv/emsdk/upstream/emscripten/cache/sysroot -internal-isystem /home/swdv/emsdk/upstream/emscripten/cache/sysroot/include/wasm32-emscripten/c++/v1 -internal-isystem /home/swdv/emsdk/upstream/emscripten/cache/sysroot/include/c++/v1 -internal-isystem /home/swdv/emsdk/upstream/lib/clang/21/include -internal-isystem /home/swdv/emsdk/upstream/emscripten/cache/sysroot/include/wasm32-emscripten -internal-isystem /home/swdv/emsdk/upstream/emscripten/cache/sysroot/include -fdeprecated-macro -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcxx-exceptions -fignore-exceptions -fexceptions -fcolor-diagnostics -iwithsysroot/include/fakesdl -iwithsysroot/include/compat -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -o /tmp/emscripten_temp_69ogm86d/print_args_0.o -x c++ print_args.cpp
clang -cc1 version 21.0.0git based upon LLVM 21.0.0git default target x86_64-unknown-linux-gnu
ignoring nonexistent directory "/home/swdv/emsdk/upstream/emscripten/cache/sysroot/include/wasm32-emscripten/c++/v1"
ignoring nonexistent directory "/home/swdv/emsdk/upstream/emscripten/cache/sysroot/include/wasm32-emscripten"
#include "..." search starts here:
#include <...> search starts here:
 /home/swdv/emsdk/upstream/emscripten/cache/sysroot/include/fakesdl
 /home/swdv/emsdk/upstream/emscripten/cache/sysroot/include/compat
 /home/swdv/emsdk/upstream/emscripten/cache/sysroot/include/c++/v1
 /home/swdv/emsdk/upstream/lib/clang/21/include
 /home/swdv/emsdk/upstream/emscripten/cache/sysroot/include
End of search list.
 /home/swdv/emsdk/upstream/bin/clang --version
 /home/swdv/emsdk/upstream/bin/wasm-ld -o print_args.wasm /tmp/emscripten_temp_69ogm86d/print_args_0.o -L/home/swdv/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten -L/home/swdv/emsdk/upstream/emscripten/src/lib -lGL-getprocaddr -lal -lhtml5 -lstubs-debug -lc-debug -ldlmalloc-debug -lcompiler_rt -lc++-noexcept -lc++abi-debug-noexcept -lsockets -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr /tmp/tmpvbgx3j35libemscripten_js_symbols.so --strip-debug --export=emscripten_stack_get_end --export=emscripten_stack_get_free --export=emscripten_stack_get_base --export=emscripten_stack_get_current --export=emscripten_stack_init --export=_emscripten_stack_alloc --export=__funcs_on_exit --export=__wasm_call_ctors --export=_emscripten_stack_restore --export-if-defined=__start_em_asm --export-if-defined=__stop_em_asm --export-if-defined=__start_em_lib_deps --export-if-defined=__stop_em_lib_deps --export-if-defined=__start_em_js --export-if-defined=__stop_em_js --export-if-defined=main --export-if-defined=__main_argc_argv --export-if-defined=fflush --export-table -z stack-size=65536 --no-growable-memory --initial-heap=16777216 --no-entry --stack-first --table-base=1
 /home/swdv/emsdk/upstream/bin/llvm-objcopy print_args.wasm print_args.wasm --remove-section=.debug* --remove-section=producers --remove-section=name
 /home/swdv/emsdk/node/20.18.0_64bit/bin/node /home/swdv/emsdk/upstream/emscripten/tools/compiler.mjs -
 /home/swdv/emsdk/node/20.18.0_64bit/bin/node /home/swdv/emsdk/upstream/emscripten/tools/preprocessor.mjs - shell.html
 /home/swdv/emsdk/node/20.18.0_64bit/bin/node /home/swdv/emsdk/upstream/emscripten/tools/preprocessor.mjs - proxyClient.js --expand-macros

Run

emrun print_args.html -- somearg

opens http://localhost:6931/print_args.html?somearg, which prints:

1 argument(s):
- ./this.program

instead of the expected (which we would get without -sPROXY_TO_WORKER):

2 argument(s):
- ./this.program
- somearg

Besides that, there is no output printed in the emrun console.

Version of emscripten/emsdk

emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 4.0.4 (273f0216fede04f2445367765eaf2aabeeb60d84)
clang version 21.0.0git (https:/github.com/llvm/llvm-project 148111fdcf0e807fe74274b18fcf65c4cff45d63)
Target: wasm32-unknown-emscripten
Thread model: posix

stevenwdv avatar Mar 17 '25 12:03 stevenwdv

Ah I guess output capturing also doesn't work with -sPROXY_TO_WORKER, I'll broaden the issue

stevenwdv avatar Mar 17 '25 13:03 stevenwdv

Btw, I needed to add -sDEFAULT_LIBRARY_FUNCS_TO_INCLUDE='$addOnExit' to get output capturing to work without -sPROXY_TO_WORKER. Is that normal? I don't see it in the docs.

stevenwdv avatar Mar 17 '25 13:03 stevenwdv

I think there are likely many feature like this that don't work great with -sPROXY_TO_WORKER. -sPROXY_TO_WORKER is kind of niche flag I think. If you are using it (are you using it is production) and you would like to imrove it in this area then PRs would be welcome, bit I was under the impression very few folks were using (not actually aware of any myself).

sbc100 avatar Mar 17 '25 15:03 sbc100

@sbc100 Fair enough. Since eventually we'll not be using the default HTML shell, we'll probably ditch the -sPROXY_TO_WORKER flag anyway in a bit.

Edit: Wait I thought PROXY_TO_WORKER was required for the default shell file when using threads, but now it seems to work fine without..? Edit 2: Ah, I was assigning var Module = {...} in my --pre-js, which apparently broke the shell when using threading, except when using PROXY_TO_WORKER. But fixing my JS apparently removed my need for the flag even with the default shell.

stevenwdv avatar Mar 18 '25 11:03 stevenwdv