write a Rust library with a C-compatible interface (extern functions, etc)
use cbindgen to generate a C header, to use the library from C
compile a Rust program that depends on the library and links with -C link-args=-Wl,--export-dynamic-symbol=<regex of symbols to export> (or another ldd option), in order to load plugins (written in C) that use the library symbols
For step 3, I need the list of symbols in the C header. I can parse the header or fill this information by hand, but cbindgen already has the list! What is missing is a way to access it.
I can see two ways of solving this problem (both may be useful):
Modify the Bindings impl: add a public API to read the items of the bindings (with methods to get the exported name of an item of any type), for instance:
let bindings = cbindgen::Builder::new().with_crate(crate_dir).with_language(C).generate().unwrap(); // usual generation
let symbols_names: Vec<String> = bindings.items.iter().map(|i| i.export_name()).collect(); // would be awesome if possible
Add a way to export the symbols in the linker format, which looks like
{
symbol_1;
symbol_2;
};
I will then be able to use --export-dynamic-symbol-list=<exported file> in order to export the symbols properly.
If someone guides me a little bit, I could try to implement one of the aforementioned features (or both, who knows?) :slightly_smiling_face:.
What I'm trying to do:
cbindgen
to generate a C header, to use the library from C-C link-args=-Wl,--export-dynamic-symbol=<regex of symbols to export>
(or another ldd option), in order to load plugins (written in C) that use the library symbolsFor step 3, I need the list of symbols in the C header. I can parse the header or fill this information by hand, but
cbindgen
already has the list! What is missing is a way to access it.I can see two ways of solving this problem (both may be useful):
Bindings
impl: add a public API to read theitems
of the bindings (with methods to get the exported name of an item of any type), for instance:I will then be able to use
--export-dynamic-symbol-list=<exported file>
in order to export the symbols properly.If someone guides me a little bit, I could try to implement one of the aforementioned features (or both, who knows?) :slightly_smiling_face:.