Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow access to bindings symbols names #907

Open
TheElectronWill opened this issue Dec 15, 2023 · 0 comments · May be fixed by #916
Open

Allow access to bindings symbols names #907

TheElectronWill opened this issue Dec 15, 2023 · 0 comments · May be fixed by #916

Comments

@TheElectronWill
Copy link

TheElectronWill commented Dec 15, 2023

What I'm trying to do:

  1. write a Rust library with a C-compatible interface (extern functions, etc)
  2. use cbindgen to generate a C header, to use the library from C
  3. 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):

  1. 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
  1. 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?) 🙂.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant