bazelbuild / bazelbuild/rules_rust
Linking against cc_library with wasm32 platform/wasm_bindgen
- Dominant language
- Starlark
- Stars
- 843
- Forks
- 651
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 15
Description
Hey all, sorry if this isn't the place for this/I've missed something totally obvious.
I'm working on a small Rust project that wraps a C library. And I figured, might as well cross-compile for wasm since this project supports it.
Things I've tried:
1. Setting up a custom Emscripten toolchain and using that to build a static library. I was eventually able to finagle it into building (sorta, sometimes), but as I later learned, there's a distinction between `wasm32-unknown-unknown` and `wasm32-unknown-emscripten`. Thus none of the Emscripten-supplied stdlib functions were found.
2. Building a `wasm_bindgen` binary. This gets up to linking, before complaining that one of the C object files is in an unrecognized format.
3. Attempting to combine (1) and (2), which then results in an attempt to build the C library as a dylib, which Emscripten doesn't like one bit.
My questions are as follow:
1. Is there an established way of doing this?
2. If not, is this something the project should support?
3. If it is, what would likely be the easiest way to proceed, either as a patch here or in my project?
- Adding support for the `wasm32-unknown-emscripten` target for Rust.
- Adding support for WASI/some other stdlib for C (and possibly Rust? Not very familiar with WASI).
- Modifying/patching the C library to remove stdlib uses (which... might be possible) and using `clang --target=wasm32`.
I don't currently have a public repo for my code, but I can make one if it would help at all.
Thanks in advance.
Contributor guide
Assessment
This issue has not been assessed yet.