Upgrade uniffi dependency to v0.29.5 switch to proc macros (mostly)#812
Upgrade uniffi dependency to v0.29.5 switch to proc macros (mostly)#812tnull merged 10 commits intolightningdevkit:mainfrom
uniffi dependency to v0.29.5 switch to proc macros (mostly)#812Conversation
|
👋 I see @joostjager was un-assigned. |
8f4909a to
a6f5d63
Compare
We here upgrade to `uniffi` v0.29.5. This upgrade requires a few changes and workarounds, in particular `UniffiCustomTypeConverter` are gone and replaced with corresponding macros. We also had to find workarounds for remote enum interface definitions, and discovered that `uniffi` lost the ability to use remote trait interfaces. The latter therefore requires us to add some duplicative code as we added a local copy of `VssHeaderProvider`/`VssHeaderProviderError` and used an adaptor to make it work for the bindings side of the builder.
Migrate `WordCount`, `PaymentDirection`, `PaymentStatus`, and `AsyncPaymentsRole` from UDL enum definitions to proc-macro `#[derive(uniffi::Enum)]` on their Rust source types, replacing the UDL definitions with `typedef enum` references. Generated with the help of AI (Claude Code). Co-Authored-By: HAL 9000
Add `#[derive(uniffi::Error)]` to `EntropyError` and `BuildError`, replacing their UDL definitions with `typedef enum` references. Generated with the help of AI (Claude Code). Co-Authored-By: HAL 9000
Migrate `MaxDustHTLCExposure`, `ConfirmationStatus`, `PaymentKind`, `LightningBalance`, and `PendingSweepBalance` enums, as well as the `LSPFeeLimits` record, from UDL definitions to proc-macro derives. Co-Authored-By: HAL 9000
Migrate `Config`, `AnchorChannelsConfig`, `BackgroundSyncConfig`, `SyncTimeoutsConfig`, `EsploraSyncConfig`, `ElectrumSyncConfig`, `ChannelConfig`, `CustomTlvRecord`, `PeerDetails`, `PaymentDetails`, `BalanceDetails`, `NodeStatus`, `LSPS2ServiceConfig`, and `ChannelDetails` from UDL dictionary definitions to `#[derive(uniffi::Record)]` proc-macro exports. Co-Authored-By: HAL 9000
Migrate `Bolt11InvoiceDescription`, `OfferAmount`, `UnifiedPaymentResult`, `RouteHintHop`, `LogRecord`, `LSPS1PaymentInfo`, `LSPS1Bolt11PaymentInfo`, `LSPS1OnchainPaymentInfo`, `ChannelInfo`, `ChannelUpdateInfo`, `NodeInfo`, `NodeAnnouncementInfo`, and `VssHeaderProviderError` from UDL definitions to proc-macro derives. Co-Authored-By: HAL 9000
…s to UniFFI proc-macro export Move these three simple Object types from UDL interface definitions to `#[derive(uniffi::Object)]` + `#[uniffi::export]` proc-macro annotations, replacing their UDL interface blocks with `typedef interface` references. Generated with the assistance of AI (Claude). Co-Authored-By: HAL 9000
Migrate `Bolt11Invoice`, `Offer`, `HumanReadableName`, `Refund`, and `Bolt12Invoice` from UDL interface definitions to proc-macro derives (`uniffi::Object`) with `#[uniffi::export]` on impl blocks and `#[uniffi::constructor]` on constructors. For types with `[Traits=(Debug, Display, Eq)]`, use `#[uniffi::export(Debug, Display, Eq)]` on the struct. Replace UDL interface definitions with `typedef interface` references. Co-Authored-By: HAL 9000
Migrate `Bolt11Payment`, `Bolt12Payment`, `SpontaneousPayment`, `OnchainPayment`, and `UnifiedPayment` from UDL interface definitions to UniFFI proc-macro export. For each payment struct, split the impl block so that `pub(crate)` and private helper methods remain in a plain impl block while all `pub fn` methods are placed in a `#[cfg_attr(feature = "uniffi", uniffi::export)]` impl block. For `Bolt12Payment`, the cfg-gated `set_paths_to_static_invoice_server` and `blinded_paths_for_async_recipient` methods are placed in separate `#[cfg(not(feature = "uniffi"))]` and `#[cfg(feature = "uniffi")] #[uniffi::export]` impl blocks to avoid proc-macro conflicts. Replace the full interface definitions in the UDL with `typedef interface` one-liners and remove the now-unused `UnifiedPaymentResult` re-export from `ffi/types.rs`. This commit was made with assistance from an AI tool (Claude Code). Co-Authored-By: HAL 9000
a6f5d63 to
18699d3
Compare
uniffi dependency to v0.29.5uniffi dependency to v0.29.5 switch to proc macros (mostly)
With the migration to UniFFI proc-macro exports, many typedefs in the UDL file are no longer needed as their types are only referenced by other proc-macro-defined types. Remove 30 non-custom typedefs that are not directly referenced by any fully UDL-defined type (interfaces, traits, remote types, or namespace functions). Note: `[Custom]` typedefs must be retained as the binding generator needs them regardless of whether the type appears in UDL signatures. Generated with the assistance of an AI coding tool. Co-Authored-By: HAL 9000
|
Failure of the VSS CI is pre-existing and hence expected. |
| /// Errors around providing headers for each VSS request. | ||
| #[derive(Debug)] | ||
| pub enum VssHeaderProviderError { |
There was a problem hiding this comment.
May want to leave a comment on why these are duplicated or if they need to be kept in sync. Or would we just get a compilation error? Likewise for other enums.
There was a problem hiding this comment.
Doc changes won't be directly detected, but actual signature changes would due to the match statements below.
| impl From<VssHeaderProviderError> for VssClientHeaderProviderError { | ||
| fn from(e: VssHeaderProviderError) -> Self { | ||
| match e { | ||
| VssHeaderProviderError::InvalidData { error } => { | ||
| VssClientHeaderProviderError::InvalidData { error } | ||
| }, | ||
| VssHeaderProviderError::RequestError { error } => { | ||
| VssClientHeaderProviderError::RequestError { error } | ||
| }, | ||
| VssHeaderProviderError::AuthorizationError { error } => { | ||
| VssClientHeaderProviderError::AuthorizationError { error } | ||
| }, | ||
| VssHeaderProviderError::InternalError { error } => { | ||
| VssClientHeaderProviderError::InternalError { error } | ||
| }, | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
I take it wrapping the underlying enum and providing From doesn't really help clients needing to use a variant?
There was a problem hiding this comment.
Ah, yes. I initially also attempted to just keep using the upstream/remote enum, but couldn't make it work for now. I hope we can drop all of the copied code as soon as mozilla/uniffi-rs#2823 is resolved.
| Ok(maybe_wrap(invoice)) | ||
| } | ||
|
|
||
| pub(crate) fn receive_inner( |
There was a problem hiding this comment.
Could just use multiple impl blocks to avoid the code moves, fwiw.
There was a problem hiding this comment.
True, though that might be more confusing w.r.t. what's exposed and what not going forward.
|
Going ahead an landing this to avoid any potential rebase conflicts, happy to address feedback in a follow-up if we think it should be addressed. |
We here upgrade to
uniffiv0.29.5. This upgrade requires a few changes and workarounds, in particularUniffiCustomTypeConverterare gone and replaced with corresponding macros. (seeuniffi-rsCHANGELOG). We also had to find workarounds for remote enum interface definitions, and discovered thatuniffilost the ability to use remote trait interfaces (see mozilla/uniffi-rs#2823).The latter therefore requires us to add some duplicative code as we added a local copy of
VssHeaderProvider/VssHeaderProviderErrorand used an adaptor to make it work for the bindings side of the builder.Since we've now already utilized the newer proc macro approach to make this work, we also included a list of commits that switch over some types from the manual definitions in the UDL file to have the bindings auto-derived via the proc macros, which will reduce maintenance overhead going forward. It also means that we will finally get docstrings working in the target language, which is another big win.
Changeset looks large, but most of it are code moves (especially in the last commit) as we split some of the impl blocks into parts that are exposed and parts that are not exposed via
uniffi-procmacros.Best reviewed with:
(cc @vincenzopalazzo)