uniffi-rs
uniffi-rs copied to clipboard
Allow things to be renamed in the bindings config
We should allow functions, types, and other objects to be renamed in the bindings config, overriding the generated names.
One use case for this is Swift, which doesn't support namespaces. This means that if you UniFFI a collection of rust crates, the names of each type needs to be unique or else you can name collisions -- for example if 2 crates defined an Error type and you tried to import both generated modules.
This can be worked around by keeping each type name unique across all the UDL files, but that's not so idiomatic for languages whose modules form namespaces -- For example in Python foo.Error and bar.Error is usually more natural than foo.FooError and bar.BarError.
This means that the in many cases it would be good to allow types to share a name, but rename them for Swift to add a prefix.
A second, related, use case is when a name in the UDL file conflicts with a builtin type or type from another library. application-services currently has this issue with the RemoteTab type.
I think the renames could be specified in uniffi.toml like this:
[bindings.swift.names]
SomeType = "RenamedType"
some_function = "renamed_function"
┆Issue is synchronized with this Jira Task ┆Issue Number: UNIFFI-219
Our Apple team is also interesting in something like this. They would like to use Swift Uniffi interface throughout their code base. However, they have their own interface naming convention, so they would like generated Uniffi interfaces to be named according to their own interface naming convention. Right now the only way to accomplish this would be to fork Uniffi and change the interface naming in template files directly.