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

A little experiment with macros instead of build scripts. #386

Closed
wants to merge 1 commit into from

Conversation

rfk
Copy link
Collaborator

@rfk rfk commented Feb 15, 2021

This commit is basically me messing around with procedural macros,
to try them out as a potential future iteration of the UniFFI
developer experience.

As a crate author, I think it would be amazing not to have to
worry about .udl files and built scripts and what-not, but
instead be able to declare my API with a macro and have Rust
just take care of the details. This commit is a tiny experiment
in that direction, based on existing features of UniFFI.

The idea is that I can wrap my Rust code in a little macro
like this:

[uniffi_macros::declare_interface]
pub mod my_component {
  ...my rust code goes here...
}

And I can provide a corresponding my_component.udl file that
declares the interface, and all the Rust scaffolding code just
gets taken care of automagically.

I still have to provide a .udl file, but I hope you can imagine
one day the possibility of generating the interface definition
directly from the Rust code that is decorated by the macro.
Not any time soon! But one day...

Curious to hear any early impressions on these shenanigans :-)

@rfk rfk force-pushed the cheeky-bindgen-macro branch 2 times, most recently from dfc4e9f to cffaaf3 Compare February 16, 2021 01:53
This commit is basically me messing around with procedural macros,
to try them out as a potential future iteration of the UniFFI
developer experience.

As a crate author, I think it would be amazing not to have to
worry about .udl files and build scripts and what-not, but
instead be able to declare my API with a macro and have Rust
just take care of the details. This commit is a tiny experiment
in that direction, based on existing features of UniFFI.

The idea is that I can wrap my Rust code in a little macro
like this:

```
[uniffi_macros::declare_interface]
pub mod my_component {
  ...my rust code goes here...
}
```

And I can provide a corresponding `my_component.udl` file that
declares the interface, and all the Rust scaffolding code just
gets taken care of automagically.

I still have to provide a `.udl` file, but I hope you can imagine
one day the possibility of generating the interface definition
directly from the Rust code that is decorated by the macro.
Not any time soon! But one day...
@rfk
Copy link
Collaborator Author

rfk commented Feb 22, 2021

(I converted this to draft because we really don't need to be merging it anytime soon; the convenience macro to include generated scaffolding though I think is quite nice and have pushed separately at #397)

@rfk
Copy link
Collaborator Author

rfk commented Mar 5, 2021

I don't intend for this to actually be merged, so I'm going to close it to avoid confusion. (I hope to find a bit of downtime to open an alternative macro-based PR for further discussion)

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.

1 participant