-
Notifications
You must be signed in to change notification settings - Fork 321
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
Support having multiple FFI crates #658
Comments
With existing cbindgen I solve this problem by slicing the crate into parts using #[cfg(cbindgen_low_level_data_structures)]
mod low_level_data_structures;
#[cfg(cbindgen_low_level_data_processor)]
mod low_level_data_processor;
#[cfg(cbindgen_high_level_data_structures)]
mod high_level_data_structures;
#[cfg(cbindgen_high_level_data_processor)]
mod high_level_data_processor; and with 4 runs of cbingen with 4 different configs I generate four headers for each module. It's mildly annoying because
but the whole setup is more or less usable. |
So, how would the ideal API for this look like? Would a way to parse, but not emit items in an specific module / crate be enough here? |
Yeah! It's fine if you have to say |
Maybe we add a "/// cbindgen header: xyz.h" attribute for modules. When called in a "--multiple" mode, cbindgen would generate a header file for each module with this annotation only containing the publicly definied or reexported items in this module. The annotated module itself doesn't need to be public, so it can be created purely for cbindgen use. |
Going along with @Manishearth's example, I think having the single top level FFI crate with something like |
I believe that right now cbindgen can basically be used once per project to generate a single header file, with no dependencies.
I'm working on ICU4X, which is a modular project, and we'd like the FFI story to be modular as well. It would be nice if individual crates could have their own FFI layers that can be selectively pulled in, but the duplicate definition problem doesn't occur if you import headers from a crate and its dependency.
For example, I might have the
langid
andpluralrules
crate, withpluralrules
depending onlangid
. It would be nice iflangid
andpluralrules
could maintain their own FFI layers, withpluralrules
building on that oflangid
, and if a project needspluralrules
it can pull in both header files. But if a project needslangid
and a different crate, it can also do that.The text was updated successfully, but these errors were encountered: