I'm trying to compile rust-onig
to wasm
and I'm running into issues. I'm creating a markdown
to html
plugin library using wasm
, and I want to utilize rust-onig
for its performance benefits. I've already successfully built a version of the library using pulldown-cmark
, syntect
, and ammonia
, but I want to try using rust-onig
instead because it's supposed to be faster.
When I build with cargo build --lib --release
, everything works fine, but when I add --target wasm32-unknown-unknown
, I start getting errors. I've managed to work around the missing <stdlib.h>
errors by including the relevant libc
headers from the emscripten
source. However, I'm now getting a new error about duplicate symbols of OnigEncodingASCII
, etc. in the object files regexec.o
and regerror.o
.
I've checked the object files at target/wasm32-unknown-unknown/release/build/onig_sys*/out
with wasm-objdump -x
, and sure enough, the symbols are duplicated. I'm supplying rustflags = ['-Z', 'wasm-c-abi=spec']
. I've also tried building with the wasm32-unknown-emscripten
target, but I get the same error.
I've tried using Clang as the linker, so that wasm-ld
is used, but I get the same error. I've also found some potential solutions online, such as passing --redefine-sym
to objcopy
, but I don't know how to use that flag. Another solution I found was using --disable-shared
, but I don't know how to use that flag either.
Can anyone help me resolve this issue? I'm a newbie, so please let me know if I'm making some rookie mistake.
Specifically, I have three questions:
- Why is this happening, especially on the
wasm
target/withwasm-bindgen
? - How can I ignore or resolve this issue? Can I use
--redefine-sym
byobjcopy
, and if so, how do I pass this argument viaCargo.toml/config.toml
? - Is there anything else I can try to resolve this issue?