emscripten-core / emscripten-core/emscripten

Audio Worklet fails with -sMINIMAL_RUNTIME=1

Open
#20,410 1 comment 0 reactions 1 assignee Claimed by @juj View on GitHub
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

Summary: Audio Worklets work with the regular runtime, but not with -sMINIMAL_RUNTIME=1

To reproduce:
1. Compile https://github.com/emscripten-core/emscripten/blob/main/test/webaudio/audioworklet.c, without `-sMINIMAL_RUNTIME=1`. It works and runs.
2. Compile the same file, but with `-sMINIMAL_RUNTIME=1`. This produces this error when opening the html file:

```
TypeError: Module is undefined
[9f4e27db-fa44-43de-ac36-a6e59694df33:1:50](blob:http://127.0.0.1:8000/9f4e27db-fa44-43de-ac36-a6e59694df33)
blob:http://127.0.0.1:8000/9f4e27db-fa44-43de-ac36-a6e59694df33:1
TypeError: Module.wasmTable is undefined
[test.aw.js:1:379](http://127.0.0.1:8000/test.aw.js)
WasmAudioWorkletProcessor http://127.0.0.1:8000/test.aw.js:1
(Async: AudioWorkletProcessorConstructor)
onmessage http://127.0.0.1:8000/test.aw.js:1
(Async: EventHandlerNonNull)
BootstrapMessages http://127.0.0.1:8000/test.aw.js:1
(Async: AudioWorkletProcessorConstructor)
http://127.0.0.1:8000/test.aw.js:1
```

You can use your own method to compile `audioworklet.c`, or follow my steps:

1. navigate to `emscripten/test/webaudio/`, which has `audioworklet.c`.
2. Create the folder "test" inside.
3. Open a local web server in `test/`. For example, I put the following file inside `test/`: [corsplease.txt](https://github.com/emscripten-core/emscripten/files/12836752/corsplease.txt), then ran `python corsplease.txt`
4. Run `em++ audioworklet.c -s ENVIRONMENT='web','worker' -sAUDIO_WORKLET=1 -sWASM_WORKERS=1 -o test/test.html -sMINIMAL_RUNTIME=1`
5. Open `http://127.0.0.1:8000/test.html` in your web browser. It will produce the error.
6. Note that if you remove ` -sMINIMAL_RUNTIME=1` in step 4, it'll work.

**Version of emscripten/emsdk:**
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.46 (19607820c447a13fd8d0b7680c56148427d6e1b8)
clang version 18.0.0 (https://github.com/llvm/llvm-project 75501f53624de92aafce2f1da698b249a7293dc7)
Target: wasm32-unknown-emscripten
Thread model: posix

**Full link command and output with `-v` appended:**
```
a@framework:~/Downloads/emsdk/upstream/emscripten/test/webaudio$ em++ audioworklet.c -s ENVIRONMENT='web','worker' -sAUDIO_WORKLET=1 -sWASM_WORKERS=1 -o test/test.html -sMINIMAL_RUNTIME=1 -v
"/home/a/Downloads/emsdk/upstream/bin/clang" --version
"/home/a/Downloads/emsdk/upstream/bin/clang++" -target wasm32-unknown-emscripten -fignore-exceptions -fvisibility=default -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -D__EMSCRIPTEN_SHARED_MEMORY__=1 -D__EMSCRIPTEN_WASM_WORKERS__=1 -DEMSCRIPTEN --sysroot=/home/a/Downloads/emsdk/upstream/emscripten/cache/sysroot -Xclang -iwithsysroot/include/fakesdl -Xclang -iwithsysroot/include/compat -v -matomics -mbulk-memory audioworklet.c -c -o /tmp/emscripten_temp_nr4i_o94/audioworklet_0.o
clang version 18.0.0 (https://github.com/llvm/llvm-project 75501f53624de92aafce2f1da698b249a7293dc7)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /home/a/Downloads/emsdk/upstream/bin
clang++: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]
(in-process)
"/home/a/Downloads/emsdk/upstream/bin/clang-18" -cc1 -triple wasm32-unknown-emscripten -emit-obj -mrelax-all -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name audioworklet.c -mrelocation-model static -mframe-pointer=none -ffp-contract=on -fno-rounding-math -mconstructor-aliases -target-cpu generic -target-feature +atomics -target-feature +bulk-memory -debugger-tuning=gdb -fdebug-compilation-dir=/home/a/Downloads/emsdk/upstream/emscripten/test/webaudio -v -fcoverage-compilation-dir=/home/a/Downloads/emsdk/upstream/emscripten/test/webaudio -resource-dir /home/a/Downloads/emsdk/upstream/lib/clang/18 -D __EMSCRIPTEN_SHARED_MEMORY__=1 -D __EMSCRIPTEN_WASM_WORKERS__=1 -D EMSCRIPTEN -isysroot /home/a/Downloads/emsdk/upstream/emscripten/cache/sysroot -internal-isystem /home/a/Downloads/emsdk/upstream/emscripten/cache/sysroot/include/wasm32-emscripten/c++/v1 -internal-isystem /home/a/Downloads/emsdk/upstream/emscripten/cache/sysroot/include/c++/v1 -internal-isystem /home/a/Downloads/emsdk/upstream/lib/clang/18/include -internal-isystem /home/a/Downloads/emsdk/upstream/emscripten/cache/sysroot/include/wasm32-emscripten -internal-isystem /home/a/Downloads/emsdk/upstream/emscripten/cache/sysroot/include -fdeprecated-macro -ferror-limit 19 -fvisibility=default -fgnuc-version=4.2.1 -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_nr4i_o94/audioworklet_0.o -x c++ audioworklet.c
clang -cc1 version 18.0.0 based upon LLVM 18.0.0git default target x86_64-unknown-linux-gnu
ignoring nonexistent directory "/home/a/Downloads/emsdk/upstream/emscripten/cache/sysroot/include/wasm32-emscripten/c++/v1"
ignoring nonexistent directory "/home/a/Downloads/emsdk/upstream/emscripten/cache/sysroot/include/wasm32-emscripten"
#include "..." search starts here:
#include <...> search starts here:
/home/a/Downloads/emsdk/upstream/emscripten/cache/sysroot/include/fakesdl
/home/a/Downloads/emsdk/upstream/emscripten/cache/sysroot/include/compat
/home/a/Downloads/emsdk/upstream/emscripten/cache/sysroot/include/c++/v1
/home/a/Downloads/emsdk/upstream/lib/clang/18/include
/home/a/Downloads/emsdk/upstream/emscripten/cache/sysroot/include
End of search list.
"/home/a/Downloads/emsdk/upstream/bin/wasm-ld" -o test/test.wasm /tmp/emscripten_temp_nr4i_o94/audioworklet_0.o -L/home/a/Downloads/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten /home/a/Downloads/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/crtbegin.o -lGL-ww -lal -lhtml5 -lbulkmemory -lstubs-debug -lnoexit -lc-ww-debug -ldlmalloc-ww-noerrno -lcompiler_rt-ww -lc++-ww-noexcept -lc++abi-debug-ww-noexcept -lsockets-ww -lwasm_workers-debug -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr /tmp/tmprisv7n9vlibemscripten_js_symbols.so --import-memory --shared-memory --strip-debug --export-if-defined=main --export-if-defined=emscripten_wasm_worker_initialize --export-if-defined=__set_thread_state --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_argc_argv --export-if-defined=fflush --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=stackSave --export=stackRestore --export=stackAlloc --export=__get_temp_ret --export=__set_temp_ret --export=__wasm_call_ctors --export=emscripten_wasm_worker_initialize --export-table -z stack-size=65536 --initial-memory=16777216 --max-memory=16777216 --no-entry --stack-first --table-base=1
"/home/a/Downloads/emsdk/upstream/bin/llvm-objcopy" test/test.wasm test/test.wasm --remove-section=.debug* --remove-section=producers
"/home/a/Downloads/emsdk/upstream/bin/wasm-emscripten-finalize" --dyncalls-i64 --pass-arg=legalize-js-interface-exported-helpers test/test.wasm -o test/test.wasm --detect-features
"/home/a/Downloads/emsdk/node/16.20.0_64bit/bin/node" /home/a/Downloads/emsdk/upstream/emscripten/src/compiler.js /tmp/tmpfdld1k8m.json
"/home/a/Downloads/emsdk/node/16.20.0_64bit/bin/node" /home/a/Downloads/emsdk/upstream/emscripten/tools/preprocessor.js /tmp/emscripten_temp_nr4i_o94/settings.js wasm_worker.js --expandMacros
"/home/a/Downloads/emsdk/node/16.20.0_64bit/bin/node" /home/a/Downloads/emsdk/upstream/emscripten/tools/preprocessor.js /tmp/emscripten_temp_nr4i_o94/settings.js audio_worklet.js --expandMacros
"/home/a/Downloads/emsdk/node/16.20.0_64bit/bin/node" /home/a/Downloads/emsdk/upstream/emscripten/tools/preprocessor.js /tmp/emscripten_temp_nr4i_o94/settings.js tmpi8qa8mxh.js

```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.