Emscripten shared library support
I wasn't sure if the library is not supposed to have emscripten support or if I was doing something wrong so I decided to create the issue. `wasm-streams` is dependent on by a bunch of popular crates including [reqwest](https://crates.io/crates/reqwest) and [tonic-web-wasm-client](https://crates.io/crates/tonic-web-wasm-client) so having emscripten support would be great. It's possible the issue is related to compiling a shared library specifically and a standalone emscripten wasm would work fine.
I'm getting a linker error pasted at the end even though the project is compiled with `-C link-args=-fPIC -C relocation-model=pic`. The environment used for the compilation is:
```
RUSTFLAGS=-C link-args=-fPIC -C relocation-model=pic -C target-feature=+mutable-globals
EMCC_CFLAGS=-s SIDE_MODULE=1 -shared
CARGO_PROFILE_RELEASE_OPT_LEVEL=s
CARGO_PROFILE_RELEASE_OVERFLOW_CHECKS=false
CARGO_PROFILE_RELEASE_DEBUG_ASSERTIONS=false
CARGO_PROFILE_RELEASE_PANIC=abort
EM_CACHE=/tmp/emscripten_cache
```
I also tried to add `-pthread` flag to no avail. My project has a lot of other dependencies and they all compile fine with this setup.
The full error is:
```
error: linking with `/project/docker/emcc-wrapper.sh` failed: exit status: 1
|
= note: "/project/docker/emcc-wrapper.sh" "-s" "EXPORTED_FUNCTIONS=[\"___externref_drop_slice\",\"___externref_heap_live_count\",\"___externref_table_alloc\",\"___externref_table_dealloc\",\"___wbindgen_exn_store\",\"___wbindgen_free\",\"___wbindgen_malloc\",\"___wbindgen_realloc\",\"_rust_eh_personality\"]" "/target/wasm32-unknown-emscripten/release/deps/wasm_streams-bbefbee90a915798.wasm_streams.47a61ed7-cgu.0.rcgu.o" "/target/wasm32-unknown-emscripten/release/deps/wasm_streams-bbefbee90a915798.wasm_streams.47a61ed7-cgu.1.rcgu.o" "/target/wasm32-unknown-emscripten/release/deps/wasm_streams-bbefbee90a915798.wasm_streams.47a61ed7-cgu.10.rcgu.o" "/target/wasm32-unknown-emscripten/release/deps/wasm_streams-bbefbee90a915798.wasm_streams.47a61ed7-cgu.11.rcgu.o" "/target/wasm32-unknown-emscripten/release/deps/wasm_streams-bbefbee90a915798.wasm_streams.47a61ed7-cgu.12.rcgu.o" "/target/wasm32-unknown-emscripten/release/deps/wasm_streams-bbefbee90a915798.wasm_streams.47a61ed7-cgu.13.rcgu.o" "/target/wasm32-unknown-emscripten/release/deps/wasm_streams-bbefbee90a915798.wasm_streams.47a61ed7-cgu.14.rcgu.o" "/target/wasm32-unknown-emscripten/release/deps/wasm_streams-bbefbee90a915798.wasm_streams.47a61ed7-cgu.15.rcgu.o" "/target/wasm32-unknown-emscripten/release/deps/wasm_streams-bbefbee90a915798.wasm_streams.47a61ed7-cgu.2.rcgu.o" "/target/wasm32-unknown-emscripten/release/deps/wasm_streams-bbefbee90a915798.wasm_streams.47a61ed7-cgu.3.rcgu.o" "/target/wasm32-unknown-emscripten/release/deps/wasm_streams-bbefbee90a915798.wasm_streams.47a61ed7-cgu.4.rcgu.o" "/target/wasm32-unknown-emscripten/release/deps/wasm_streams-bbefbee90a915798.wasm_streams.47a61ed7-cgu.5.rcgu.o" "/target/wasm32-unknown-emscripten/release/deps/wasm_streams-bbefbee90a915798.wasm_streams.47a61ed7-cgu.6.rcgu.o" "/target/wasm32-unknown-emscripten/release/deps/wasm_streams-bbefbee90a915798.wasm_streams.47a61ed7-cgu.7.rcgu.o" "/target/wasm32-unknown-emscripten/release/deps/wasm_streams-bbefbee90a915798.wasm_streams.47a61ed7-cgu.8.rcgu.o" "/target/wasm32-unknown-emscripten/release/deps/wasm_streams-bbefbee90a915798.wasm_streams.47a61ed7-cgu.9.rcgu.o" "/target/wasm32-unknown-emscripten/release/deps/wasm_streams-bbefbee90a915798.3ptydmnl2qpxl0wc.rcgu.o" "-L" "/target/wasm32-unknown-emscripten/release/deps" "-L" "/target/release/deps" "-L" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-emscripten/lib" "/target/wasm32-unknown-emscripten/release/deps/libweb_sys-8a5a6187d27dbaa7.rlib" "/target/wasm32-unknown-emscripten/release/deps/libwasm_bindgen_futures-3bb037bfa8f0a06f.rlib" "/target/wasm32-unknown-emscripten/release/deps/libjs_sys-f7b7ebaeb913e4dc.rlib" "/target/wasm32-unknown-emscripten/release/deps/libfutures_util-a8f1e804ead8f597.rlib" "/target/wasm32-unknown-emscripten/release/deps/libmemchr-d30c6d9b864a7388.rlib" "/target/wasm32-unknown-emscripten/release/deps/libfutures_io-b2a07ec3e0f2e685.rlib" "/target/wasm32-unknown-emscripten/release/deps/libslab-1780b725ea666a36.rlib" "/target/wasm32-unknown-emscripten/release/deps/libfutures_channel-a6360815805cce6a.rlib" "/target/wasm32-unknown-emscripten/release/deps/libpin_project_lite-f302220b5fa82ce7.rlib" "/target/wasm32-unknown-emscripten/release/deps/libfutures_sink-acd83134cf138a01.rlib" "/target/wasm32-unknown-emscripten/release/deps/libfutures_task-bea00c7a3c9e332d.rlib" "/target/wasm32-unknown-emscripten/release/deps/libpin_utils-63e77d1b97174837.rlib" "/target/wasm32-unknown-emscripten/release/deps/libfutures_core-9fc21edde8d6f307.rlib" "/target/wasm32-unknown-emscripten/release/deps/libwasm_bindgen-59c870add582b85b.rlib" "/target/wasm32-unknown-emscripten/release/deps/libcfg_if-89660aee188a8006.rlib" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-emscripten/lib/libstd-0e96e91c18cd4057.rlib" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-emscripten/lib/libpanic_abort-d81851b237bd9dcb.rlib" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-emscripten/lib/librustc_demangle-f8b5fb10609706d7.rlib" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-emscripten/lib/libstd_detect-0d142c0e032a8625.rlib" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-emscripten/lib/libhashbrown-edb3d6b244d075e1.rlib" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-emscripten/lib/librustc_std_workspace_alloc-881958f55e8dc119.rlib" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-emscripten/lib/libunwind-435278ae90eb10ec.rlib" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-emscripten/lib/libcfg_if-d2f8c107668e093e.rlib" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-emscripten/lib/liblibc-42168d6be60acab4.rlib" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-emscripten/lib/liballoc-e23ace87be715576.rlib" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-emscripten/lib/librustc_std_workspace_core-1d77cf1ecd25093f.rlib" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-emscripten/lib/libcore-6fb14a8f0eea3792.rlib" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-emscripten/lib/libcompiler_builtins-4b011e7108c2ae7b.rlib" "-l" "c" "-s" "DISABLE_EXCEPTION_CATCHING=1" "-L" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-emscripten/lib" "-L" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-emscripten/lib/self-contained" "-o" "/target/wasm32-unknown-emscripten/release/deps/wasm_streams-bbefbee90a915798.wasm" "-Os" "--memory-init-file" "0" "-g0" "-s" "DEFAULT_LIBRARY_FUNCS_TO_INCLUDE=[]" "-fPIC" "-s" "ERROR_ON_UNDEFINED_SYMBOLS=1" "-s" "ASSERTIONS=1" "-s" "ABORTING_MALLOC=0" "-Wl,--fatal-warnings"
= note: emcc-wrapper: extracting /target/wasm32-unknown-emscripten/release/deps/libweb_sys-8a5a6187d27dbaa7.rlib
emcc-wrapper: extracting /target/wasm32-unknown-emscripten/release/deps/libwasm_bindgen_futures-3bb037bfa8f0a06f.rlib
emcc-wrapper: extracting /target/wasm32-unknown-emscripten/release/deps/libjs_sys-f7b7ebaeb913e4dc.rlib
emcc-wrapper: extracting /target/wasm32-unknown-emscripten/release/deps/libfutures_util-a8f1e804ead8f597.rlib
emcc-wrapper: extracting /target/wasm32-unknown-emscripten/release/deps/libmemchr-d30c6d9b864a7388.rlib
emcc-wrapper: extracting /target/wasm32-unknown-emscripten/release/deps/libfutures_io-b2a07ec3e0f2e685.rlib
emcc-wrapper: extracting /target/wasm32-unknown-emscripten/release/deps/libslab-1780b725ea666a36.rlib
emcc-wrapper: extracting /target/wasm32-unknown-emscripten/release/deps/libfutures_channel-a6360815805cce6a.rlib
emcc-wrapper: extracting /target/wasm32-unknown-emscripten/release/deps/libpin_project_lite-f302220b5fa82ce7.rlib
emcc-wrapper: extracting /target/wasm32-unknown-emscripten/release/deps/libfutures_sink-acd83134cf138a01.rlib
emcc-wrapper: extracting /target/wasm32-unknown-emscripten/release/deps/libfutures_task-bea00c7a3c9e332d.rlib
emcc-wrapper: extracting /target/wasm32-unknown-emscripten/release/deps/libpin_utils-63e77d1b97174837.rlib
emcc-wrapper: extracting /target/wasm32-unknown-emscripten/release/deps/libfutures_core-9fc21edde8d6f307.rlib
emcc-wrapper: extracting /target/wasm32-unknown-emscripten/release/deps/libwasm_bindgen-59c870add582b85b.rlib
emcc-wrapper: extracting /target/wasm32-unknown-emscripten/release/deps/libcfg_if-89660aee188a8006.rlib
emcc-wrapper: extracting /usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-emscripten/lib/libstd-0e96e91c18cd4057.rlib
emcc-wrapper: extracting /usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-emscripten/lib/libpanic_abort-d81851b237bd9dcb.rlib
emcc-wrapper: extracting /usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-emscripten/lib/librustc_demangle-f8b5fb10609706d7.rlib
emcc-wrapper: extracting /usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-emscripten/lib/libstd_detect-0d142c0e032a8625.rlib
emcc-wrapper: extracting /usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-emscripten/lib/libhashbrown-edb3d6b244d075e1.rlib
emcc-wrapper: extracting /usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-emscripten/lib/librustc_std_workspace_alloc-881958f55e8dc119.rlib
emcc-wrapper: extracting /usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-emscripten/lib/libunwind-435278ae90eb10ec.rlib
emcc-wrapper: extracting /usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-emscripten/lib/libcfg_if-d2f8c107668e093e.rlib
emcc-wrapper: extracting /usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-emscripten/lib/liblibc-42168d6be60acab4.rlib
emcc-wrapper: extracting /usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-emscripten/lib/liballoc-e23ace87be715576.rlib
emcc-wrapper: extracting /usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-emscripten/lib/librustc_std_workspace_core-1d77cf1ecd25093f.rlib
emcc-wrapper: extracting /usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-emscripten/lib/libcore-6fb14a8f0eea3792.rlib
emcc-wrapper: extracting /usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-emscripten/lib/libcompiler_builtins-4b011e7108c2ae7b.rlib
shared:INFO: (Emscripten: Running sanity checks)
emcc: warning: EXPORTED_FUNCTIONS is not valid with LINKABLE set (normally due to SIDE_MODULE=1/MAIN_MODULE=1) since all functions are exported this mode. To export only a subset use SIDE_MODULE=2/MAIN_MODULE=2 [-Wunused-command-line-argument]
wasm-ld: error: /tmp/emcc-wrapper.KDQKL1/tmp.mpvnge0Keh/std-0e96e91c18cd4057.std.26ff312d-cgu.0.rcgu.o: relocation R_WASM_MEMORY_ADDR_LEB cannot be used against symbol `std::panicking::panic_count::LOCAL_PANIC_COUNT::__getit::__KEY::hc77586dfefcc5598 (.0)`; recompile with -fPIC
wasm-ld: error: /tmp/emcc-wrapper.KDQKL1/tmp.mpvnge0Keh/std-0e96e91c18cd4057.std.26ff312d-cgu.0.rcgu.o: relocation R_WASM_MEMORY_ADDR_LEB cannot be used against symbol `std::panicking::panic_count::LOCAL_PANIC_COUNT::__getit::__KEY::hc77586dfefcc5598 (.0)`; recompile with -fPIC
wasm-ld: error: /tmp/emcc-wrapper.KDQKL1/tmp.mpvnge0Keh/std-0e96e91c18cd4057.std.26ff312d-cgu.0.rcgu.o: relocation R_WASM_MEMORY_ADDR_LEB cannot be used against symbol `std::panicking::panic_count::LOCAL_PANIC_COUNT::__getit::__KEY::hc77586dfefcc5598 (.1)`; recompile with -fPIC
wasm-ld: error: /tmp/emcc-wrapper.KDQKL1/tmp.mpvnge0Keh/std-0e96e91c18cd4057.std.26ff312d-cgu.0.rcgu.o: relocation R_WASM_MEMORY_ADDR_LEB cannot be used against symbol `std::panicking::panic_count::LOCAL_PANIC_COUNT::__getit::__KEY::hc77586dfefcc5598 (.1)`; recompile with -fPIC
wasm-ld: error: /tmp/emcc-wrapper.KDQKL1/tmp.mpvnge0Keh/std-0e96e91c18cd4057.std.26ff312d-cgu.0.rcgu.o: relocation R_WASM_MEMORY_ADDR_SLEB cannot be used against symbol `.Lanon.a692f5b51657799feaab45a2bc2ac8ce.580`; recompile with -fPIC
wasm-ld: error: /tmp/emcc-wrapper.KDQKL1/tmp.mpvnge0Keh/std-0e96e91c18cd4057.std.26ff312d-cgu.0.rcgu.o: relocation R_WASM_MEMORY_ADDR_LEB cannot be used against symbol `std::sys_common::thread_info::THREAD_INFO::__getit::VAL::h306edbb032a765dd`; recompile with -fPIC
wasm-ld: error: /tmp/emcc-wrapper.KDQKL1/tmp.mpvnge0Keh/std-0e96e91c18cd4057.std.26ff312d-cgu.0.rcgu.o: relocation R_WASM_MEMORY_ADDR_LEB cannot be used against symbol `std::sys_common::thread_info::THREAD_INFO::__getit::VAL::h306edbb032a765dd`; recompile with -fPIC
wasm-ld: error: /tmp/emcc-wrapper.KDQKL1/tmp.mpvnge0Keh/std-0e96e91c18cd4057.std.26ff312d-cgu.0.rcgu.o: relocation R_WASM_MEMORY_ADDR_LEB cannot be used against symbol `std::sys_common::thread_info::THREAD_INFO::__getit::VAL::h306edbb032a765dd`; recompile with -fPIC
wasm-ld: error: /tmp/emcc-wrapper.KDQKL1/tmp.mpvnge0Keh/std-0e96e91c18cd4057.std.26ff312d-cgu.0.rcgu.o: relocation R_WASM_MEMORY_ADDR_LEB cannot be used against symbol `std::sys_common::thread_info::THREAD_INFO::__getit::VAL::h306edbb032a765dd`; recompile with -fPIC
wasm-ld: error: /tmp/emcc-wrapper.KDQKL1/tmp.mpvnge0Keh/std-0e96e91c18cd4057.std.26ff312d-cgu.0.rcgu.o: relocation R_WASM_MEMORY_ADDR_LEB cannot be used against symbol `__THREW__`; recompile with -fPIC
wasm-ld: error: /tmp/emcc-wrapper.KDQKL1/tmp.mpvnge0Keh/std-0e96e91c18cd4057.std.26ff312d-cgu.0.rcgu.o: relocation R_WASM_TABLE_INDEX_SLEB cannot be used against symbol `std::thread::Thread::new::hc1b25c6f9f2095ee`; recompile with -fPIC
wasm-ld: error: /tmp/emcc-wrapper.KDQKL1/tmp.mpvnge0Keh/std-0e96e91c18cd4057.std.26ff312d-cgu.0.rcgu.o: relocation R_WASM_MEMORY_ADDR_LEB cannot be used against symbol `__THREW__`; recompile with -fPIC
wasm-ld: error: /tmp/emcc-wrapper.KDQKL1/tmp.mpvnge0Keh/std-0e96e91c18cd4057.std.26ff312d-cgu.0.rcgu.o: relocation R_WASM_MEMORY_ADDR_LEB cannot be used against symbol `__THREW__`; recompile with -fPIC
wasm-ld: error: /tmp/emcc-wrapper.KDQKL1/tmp.mpvnge0Keh/std-0e96e91c18cd4057.std.26ff312d-cgu.0.rcgu.o: relocation R_WASM_MEMORY_ADDR_LEB cannot be used against symbol `std::sys_common::thread_info::THREAD_INFO::__getit::VAL::h306edbb032a765dd`; recompile with -fPIC
wasm-ld: error: /tmp/emcc-wrapper.KDQKL1/tmp.mpvnge0Keh/std-0e96e91c18cd4057.std.26ff312d-cgu.0.rcgu.o: relocation R_WASM_MEMORY_ADDR_LEB cannot be used against symbol `std::sys_common::thread_info::THREAD_INFO::__getit::VAL::h306edbb032a765dd`; recompile with -fPIC
wasm-ld: error: /tmp/emcc-wrapper.KDQKL1/tmp.mpvnge0Keh/std-0e96e91c18cd4057.std.26ff312d-cgu.0.rcgu.o: relocation R_WASM_MEMORY_ADDR_LEB cannot be used against symbol `std::sys_common::thread_info::THREAD_INFO::__getit::VAL::h306edbb032a765dd`; recompile with -fPIC
wasm-ld: error: /tmp/emcc-wrapper.KDQKL1/tmp.mpvnge0Keh/std-0e96e91c18cd4057.std.26ff312d-cgu.0.rcgu.o: relocation R_WASMsymbol `std::io::stdio::OUTPUT_CAPTURE_USED::h066a4a9a650eb19e (.0)`; recompile with -fPIC wasm-ld: error: too many errors emitted, stopping now (use -error-limit=0 to see all errors)
emcc: error: '/emsdk/upstream/bin/wasm-ld @/tmp/emscripten_dnty0ec7.rsp.utf-8' failed (returned 1)
error: could not compile `wasm-streams` due to previous error
```
6 条评论