Rust emscripten - Emterpreter?

I'm trying to build a Rust program using the wasm32-unknown-emscripten target. I need to use the EMTERPRETIFY=1 and EMTERPRETIFY_ASYNC=1 emcc code generation options, primarily to support the Emterpreter-Async feature described here.

Is there any way to compile wasm32-unknown-emscripten to use the Emterpreter?

Ah, I figured it out, sort of.

In my project's .cargo/config:

[target.wasm32-unknown-emscripten]
rustflags=["-Clink-args=-s EMTERPRETIFY=1 -s EMTERPRETIFY_ASYNC=1"]

Unfortunately I get this error:

> cargo build --target wasm32-unknown-emscripten
   Compiling emscripten-sys v0.3.2
   Compiling hello-emscripten v0.1.0 (file:///Users/agaspar/scratch/hello-emscripten)
error: linking with `emcc` failed: exit code: 1
  |
  = note: "emcc" "-s" "DISABLE_EXCEPTION_CATCHING=0" "-L" "/Users/agaspar/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/wasm32-unknown-emscripten/lib" "/Users/agaspar/scratch/hello-emscripten/target/wasm32-unknown-emscripten/debug/deps/hello_emscripten.1y16o1qfye96o7m0.rcgu.o" "/Users/agaspar/scratch/hello-emscripten/target/wasm32-unknown-emscripten/debug/deps/hello_emscripten.3rngp6bm2u2q5z0y.rcgu.o" "/Users/agaspar/scratch/hello-emscripten/target/wasm32-unknown-emscripten/debug/deps/hello_emscripten.46n4svz188tpxi63.rcgu.o" "/Users/agaspar/scratch/hello-emscripten/target/wasm32-unknown-emscripten/debug/deps/hello_emscripten.4xq48u46a1pwiqn7.rcgu.o" "-o" "/Users/agaspar/scratch/hello-emscripten/target/wasm32-unknown-emscripten/debug/deps/hello_emscripten.js" "-s" "EXPORTED_FUNCTIONS=[\"_main\",\"_rust_eh_personality\"]" "/Users/agaspar/scratch/hello-emscripten/target/wasm32-unknown-emscripten/debug/deps/hello_emscripten.crate.allocator.rcgu.o" "-O0" "--memory-init-file" "0" "-g4" "-s" "DEFAULT_LIBRARY_FUNCS_TO_INCLUDE=[]" "-L" "/Users/agaspar/scratch/hello-emscripten/target/wasm32-unknown-emscripten/debug/deps" "-L" "/Users/agaspar/scratch/hello-emscripten/target/debug/deps" "-L" "/Users/agaspar/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/wasm32-unknown-emscripten/lib" "/Users/agaspar/scratch/hello-emscripten/target/wasm32-unknown-emscripten/debug/deps/libemscripten_sys-31b33b6d16416bff.rlib" "/Users/agaspar/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/wasm32-unknown-emscripten/lib/libstd-075ab6f2359a82f1.rlib" "/Users/agaspar/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/wasm32-unknown-emscripten/lib/libpanic_unwind-428f111496747802.rlib" "/Users/agaspar/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/wasm32-unknown-emscripten/lib/libunwind-fbadb5623ab8cc25.rlib" "/Users/agaspar/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/wasm32-unknown-emscripten/lib/liballoc_system-c7afd75849f41e4c.rlib" "/Users/agaspar/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/wasm32-unknown-emscripten/lib/liblibc-42a81d0277a7a698.rlib" "/Users/agaspar/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/wasm32-unknown-emscripten/lib/liballoc-20751df81794b150.rlib" "/Users/agaspar/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/wasm32-unknown-emscripten/lib/libstd_unicode-34dbdc699982f60d.rlib" "/Users/agaspar/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/wasm32-unknown-emscripten/lib/libcore-8e8a91684c5e06e5.rlib" "/Users/agaspar/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/wasm32-unknown-emscripten/lib/libcompiler_builtins-4e85b1507e729192.rlib" "-l" "c" "-s" "EMTERPRETIFY=1" "-s" "EMTERPRETIFY_ASYNC=1" "-s" "BINARYEN=1" "-s" "ERROR_ON_UNDEFINED_SYMBOLS=1"
  = note: Traceback (most recent call last):
            File "/Users/agaspar/Code/emsdk/emscripten/1.38.10/emcc.py", line 3015, in <module>
              sys.exit(run())
            File "/Users/agaspar/Code/emsdk/emscripten/1.38.10/emcc.py", line 1155, in run
              assert not use_source_map(options), 'EMTERPRETIFY is not compatible with source maps (maps are not useful in emterpreted code, and splitting out non-emterpreted source maps is not yet implemented)'
          AssertionError: EMTERPRETIFY is not compatible with source maps (maps are not useful in emterpreted code, and splitting out non-emterpreted source maps is not yet implemented)


error: aborting due to previous error

error: Could not compile `hello-emscripten`.

To learn more, run the command again with --verbose.

I just need to figure out how to tell Cargo not to pass the -g4 option to emcc. :slight_smile:

1 Like

Building for release omits the debuginfo.

You can have debug info in release mode:

[profile.release]
debug = true

Yeah, I was trying to find a way to explicitly disable the debug info in the debug profile, too, but this didn't seem to work:

[profile.debug]
debug=false

I'll just have to build for release for now.

That's because it's [profile.dev].

I've filed a bug about this: https://github.com/rust-lang/cargo/pull/5836

2 Likes

Thank you!