Skip to content

Upgrade uniffi dependency to v0.29.5 switch to proc macros (mostly)#812

Open
tnull wants to merge 10 commits intolightningdevkit:mainfrom
tnull:2026-01-bump-to-uniffi-0.29
Open

Upgrade uniffi dependency to v0.29.5 switch to proc macros (mostly)#812
tnull wants to merge 10 commits intolightningdevkit:mainfrom
tnull:2026-01-bump-to-uniffi-0.29

Conversation

@tnull
Copy link
Collaborator

@tnull tnull commented Feb 27, 2026

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. (see uniffi-rs CHANGELOG). We also had to find workarounds for remote enum interface definitions, and discovered that uniffi lost 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/VssHeaderProviderError and 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:

git diff --diff-algorithm=patience --color-moved --color-moved-ws=ignore-all-space

(cc @vincenzopalazzo)

@ldk-reviews-bot
Copy link

ldk-reviews-bot commented Feb 27, 2026

👋 I see @joostjager was un-assigned.
If you'd like another reviewer assignment, please click here.

@tnull tnull force-pushed the 2026-01-bump-to-uniffi-0.29 branch from 8f4909a to a6f5d63 Compare February 27, 2026 13:49
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
@tnull tnull force-pushed the 2026-01-bump-to-uniffi-0.29 branch from a6f5d63 to 18699d3 Compare February 27, 2026 14:00
@tnull tnull requested a review from joostjager February 27, 2026 14:01
@tnull tnull changed the title Upgrade uniffi dependency to v0.29.5 Upgrade uniffi dependency to v0.29.5 switch to proc macros (mostly) Feb 27, 2026
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
@tnull tnull requested review from jkczyz and removed request for joostjager February 27, 2026 14:56
@tnull
Copy link
Collaborator Author

tnull commented Feb 27, 2026

Failure of the VSS CI is pre-existing and hence expected.

Comment on lines 49 to 51
/// Errors around providing headers for each VSS request.
#[derive(Debug)]
pub enum VssHeaderProviderError {
Copy link
Contributor

Choose a reason for hiding this comment

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

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.

Comment on lines +91 to +108
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 }
},
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I take it wrapping the underlying enum and providing From doesn't really help clients needing to use a variant?

Ok(maybe_wrap(invoice))
}

pub(crate) fn receive_inner(
Copy link
Contributor

Choose a reason for hiding this comment

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

Could just use multiple impl blocks to avoid the code moves, fwiw.

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.

3 participants