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

Add a procedural macro frontend #1257

Closed
14 of 20 tasks
jplatte opened this issue May 30, 2022 · 11 comments
Closed
14 of 20 tasks

Add a procedural macro frontend #1257

jplatte opened this issue May 30, 2022 · 11 comments
Assignees

Comments

@jplatte
Copy link
Collaborator

jplatte commented May 30, 2022

This is a tracking issue for the proc-macro work, initially discussed in #385, on Matrix and recently in a video meeting.

Outline

  • Introduce an attribute #[uniffi::export] that can go onto functions and impl blocks
    • Attributes like #[uniffi::default] will be used to express binding properties that can't be expressed in Rust directly¹
  • Introduce a derive attribute uniffi::FfiConvertible to allow a custom type to be used in the FFI API²
    • Attributes like #[uniffi(default)] will be used to express binding properties that can't be expressed in Rust directly³

Progress

  • Functions
    • Argument passing
    • Return value passing
    • Fallible (returning Result<T, E>)
    • Argument defaults
  • Types
    • Primitives
    • Arc<_>
    • By-value structs and enums
      • Field defaults
    • Enums
    • External types
  • Parsing #[doc = "…"] attributes
  • impl blocks
    • Associated functions (static methods in some target languages)
    • (True) methods with self parameters
    • Recognize Self keyword
    • Constructors (#[uniffi::constructor])
  • Traits
  • Callback interfaces

¹ Using custom syntax like foo: u32 = 0 the parameter list would be possible, but it's undesireable because (a) it would be confusing and (b) it would degrade IDE functionality
² This could be handled by the same #[uniffi::export] attribute but that's undesireable for technical reasons
³ Syntax difference is warranted due to proc-macro peculiarities

I can elaborate on any of these footnotes if somebody wants to know more ^^

┆Issue is synchronized with this Jira Task
┆friendlyId: UNIFFI-168

@jplatte jplatte self-assigned this May 30, 2022
@jplatte
Copy link
Collaborator Author

jplatte commented May 30, 2022

About the current status: Some things have their boxes ticked but don't have PRs yet. The reason for that is that most of the work I've been doing so far has not been under the assumption that we'll want to mix UDL and proc-macro interface definitions. However, recently I realized that this shouldn't be so hard and has a number of big advantages:

  • Individual proc-macro bits can be tested and used ahead of achieving feature parity
    • This also means small PRs are possible, which makes collaboration on this much easier
  • Incrementally porting an existing UDL-using codebase is possible

You can expect the first proc-macro PRs this week though 😉

@jplatte jplatte changed the title Add a procedural macro "frontend" Add a procedural macro frontend May 30, 2022
@jplatte

This comment was marked as outdated.

@jplatte
Copy link
Collaborator Author

jplatte commented Jun 30, 2022

Also I have a question that I wasn't sure whether to ask here or on Matrix:

Why does the current scaffolding contain a separate FfiConverterTypeFooError instead of implementing RustBufferFfiConverter / FfiError for the user's FooError type directly?

@bendk
Copy link
Contributor

bendk commented Jun 30, 2022

Also I have a question that I wasn't sure whether to ask here or on Matrix:

Why does the current scaffolding contain a separate FfiConverterTypeFooError instead of implementing RustBufferFfiConverter / FfiError for the user's FooError type directly?

It's part of a general policy to not implement the trait on any user types, in case those types came from another crate. It doesn't make that much sense for error types, but I guess there's a chance.

Is this interfering with your work? Maybe we should try to tackle #1250 to simplify things.

@jplatte

This comment was marked as outdated.

@jplatte

This comment was marked as outdated.

@bendk

This comment was marked as resolved.

@jplatte

This comment was marked as resolved.

@bendk

This comment was marked as resolved.

@jplatte

This comment was marked as resolved.

@jplatte
Copy link
Collaborator Author

jplatte commented Aug 21, 2024

This issue has definitely served its purpose ^^

@jplatte jplatte closed this as completed Aug 21, 2024
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

No branches or pull requests

2 participants