Add WASM binding for a crate which has C lib dependency

⚓ Rust    📅 2025-07-21    👤 surdeus    👁️ 2      

surdeus

Hi, I have problem about C, Rust and WASM. There is a C lib called libspot, which implement an algorithm with pure C(without c stdlib). I wrap it by Rust ffi, and built a lib crate named with libspot too(GitHub - shenxiangzhuang/libspot-rs: A Rust wrapper for the libspot). To be clear, let's call the wrapper crate with libspot-rs(just as repo name). Based on the libspot-rs, I built another lib crate, let's just call it X.

The problem is that I can not add wasm binding for the X crate, because it dependents on libspot-rs, and libspot-rs use C lib libspot by ffi.

All I want is that use libspot-rs as a regular pure rust crate and can add wasm binding by wasm-bindgen normally. And I want to know how to do this. Any suggestion would be greatly appreciated!

For references: the orignal libspot c lib already has a wasm binding and has beed published to npm.

3 posts - 2 participants

Read full topic

🏷️ rust_feed