webrtc-sdp
webrtc-sdp copied to clipboard
Generate interface to C++ code
Looks like there is some documentation for getting rust into FF:
- https://developer.mozilla.org/en-US/Firefox/Building_Firefox_with_Rust_code
- https://gecko.readthedocs.io/en/latest/build/buildsystem/rust.html
This appears to list of the current (root level) rust components of FF.
For example this is a URL parser written in rust. It looks like they split it up into a pure rust part, and the code you see in dxr is the interface into the rest of FF.
Juicy bits
Looking at the example of the mp4 parser, it looks like they use repr(C)
to make rust use the C struct layout. eg rust & C++ version of the mp4parse_track_video_info
struct. And then pass it around as a raw pointer. To get a raw pointer it appears you Box::into_raw(Box::new(foo))
, example 1 example 2
It might be worth considering using https://github.com/eqrion/cbindgen/ for this. It's what we use to generate c bindings for webrender.
@jrmuizel thanks for the pointer. We briefly looked at other binding generators, but failed to find a suitable one. cbindgen looks interesting
We should definitely provide them as a first class part of the library. That is we should be able to annotate the structs and functions in the library without the need of any wrapper library. That way we can have CI coverage of the FFI, the FFI will always be in sync, and it will prevent us from accidentally making commits that cause problems for cbindgen.