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

External custom types in UDL must use the [Custom] attribute #2371

Merged
merged 1 commit into from
Jan 1, 2025

Conversation

mhammond
Copy link
Member

Previously they were declared with the External attribute, but this mean UniFFI could not know the underlying type, leading to issues like #2025.

This PR does not however fix any such issues, it instead allows UniFFI metadata to carry enough information to fix in the future. This is primarily being done now to include this breaking change in with all other breaking changes we are making in the next release.

Previously they were declared with the `External` attribute, but
this mean UniFFI could not know the underlying type, leading to
issues like mozilla#2025.

This PR does not however fix any such issues, it instead allows
UniFFI metadata to carry enough information to fix in the future.
This is primarily being done now to include this breaking change
in with all other breaking changes we are making in the next release.
@mhammond mhammond requested a review from bendk December 30, 2024 15:20
@mhammond mhammond requested a review from a team as a code owner December 30, 2024 15:20
```
[Custom="crate_name"]
typedef string Url; // replace `string` with any appropriate type.
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't looked over everything, but I think the main question is how this should be spelled out in the UDL. The main alternative in my mind is something like:

[External="crate_name"]
typedef custom Url;

The upside is that this looks like other external type definitions, the downside is that it doesn't define the bridged type. Maybe that's okay though. I think we can get that info from the metadata when --library is used.

The other case is when --library isn't used. In that case, maybe users can specify the bridged type with another attribute:

[External="crate_name", BridgeType="string"]
typedef custom Url;

This feels worse than the proposed syntax, but IMO bindgen without library mode is outdated and we should start deprecating it and/or making it somewhat of a second-class citizen.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The upside is that this looks like other external type definitions, the downside is that it doesn't define the bridged type. Maybe that's okay though. I think we can get that info from the metadata when --library is used.

I don't think this is true - I actually started thinking it was, and started making the builtin elt of Custom an Option - the problem is that this falls apart in the Rust scaffolding - it needs to know the type - even for external types - to know how to lower etc it.

This feels worse than the proposed syntax, but IMO bindgen without library mode is outdated

Agree entirely - I really would prefer to have found a way to not specify the type, but failed (a few times actually :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the problem is that this falls apart in the Rust scaffolding

oops, I should have clarified - we work around that in the rust scaffolding today by assuming a RustBuffer, but that falls apart in #2025.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried for a while to make this work. I made some things work, but I hit a fundamental roadblock: if the user is not using library mode, then we need to generate the bindings directly from the UDL. In that case, there needs to be a way in the UDL to specify the builtin-type, since that's going to determine the FFI type. This proposal seems as good as any other to me.

```
[Custom="crate_name"]
typedef string Url; // replace `string` with any appropriate type.
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried for a while to make this work. I made some things work, but I hit a fundamental roadblock: if the user is not using library mode, then we need to generate the bindings directly from the UDL. In that case, there needs to be a way in the UDL to specify the builtin-type, since that's going to determine the FFI type. This proposal seems as good as any other to me.

@mhammond mhammond merged commit af9bd4c into mozilla:main Jan 1, 2025
5 checks passed
@mhammond mhammond deleted the push-ulpyuvuvonor branch January 1, 2025 01:46
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 this pull request may close these issues.

2 participants