webrtc-sdp icon indicating copy to clipboard operation
webrtc-sdp copied to clipboard

Generate interface to C++ code

Open nils-ohlmeier opened this issue 7 years ago • 4 comments

nils-ohlmeier avatar May 28 '17 04:05 nils-ohlmeier

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

Paul-E avatar Jun 06 '17 18:06 Paul-E

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 avatar Aug 18 '17 21:08 jrmuizel

@jrmuizel thanks for the pointer. We briefly looked at other binding generators, but failed to find a suitable one. cbindgen looks interesting

nils-ohlmeier avatar Aug 18 '17 21:08 nils-ohlmeier

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.

na-g avatar Jul 11 '19 02:07 na-g