uniffi-rs icon indicating copy to clipboard operation
uniffi-rs copied to clipboard

Namespace metadata items in library files

Open bendk opened this issue 3 years ago • 1 comments

With the new proc-macro code, we generate the ComponentInterface used to build the bindings from metadata stored in the library file. One issue here is if multiple crates that use the uniffi::export macro get compiled together. This happens with the app-services megazord and jplatte points out that it could also happen with just regular dependencies. In addition to leading to code bloat, this could lead to name conflicts if 2 crates have an item with the same name.

I think we should namespace metadata items to avoid this. When generating the metadata, we also store a namespace string (or make the namespace part of the symbol name). This defaults the crate name, but maybe there would be a way to override this. Then when generating the bindings, we ignore metadata items that don't match the UDL namespace. Once we abandon the UDL file, we can make the namespace a CLI argument.

┆Issue is synchronized with this Jira Task ┆Issue Number: UNIFFI-194

bendk avatar Sep 02 '22 14:09 bendk

Right, namespacing could be a solution. The function metadata already contains module_path where the first element is always the crate name. I'll look into adding the crate name to Type::Object in uniffi_bindgen!

jplatte avatar Sep 02 '22 15:09 jplatte