Skip to content

sdk: Make the entire SDK API synchronous#720

Merged
cdecker merged 5 commits into
mainfrom
2026w20-resolve-input-sync
May 20, 2026
Merged

sdk: Make the entire SDK API synchronous#720
cdecker merged 5 commits into
mainfrom
2026w20-resolve-input-sync

Conversation

@cdecker
Copy link
Copy Markdown
Collaborator

@cdecker cdecker commented May 20, 2026

Summary

Make the entire public API exposed by gl-sdk through UniFFI synchronous. Functions that need async work (LNURL HTTP fetches, gRPC calls) block the calling thread while an internal Tokio runtime executes the underlying operations.

This removes the hacky #[cfg(feature = "cpp-bindings")] conditional compilation that was introduced in #718 to work around uniffi-bindgen-cpp not supporting async exports. Instead of maintaining two implementations of resolve_input (async for non-CPP, sync for CPP), there is now a single synchronous version that works for all bindings.

Rationale

  • Uniform bindings -- every target language (Python, Kotlin, Swift, Ruby, C++) gets the same blocking API without requiring an async runtime, coroutine support, or special feature flags on the caller side.
  • Simpler integration -- callers that need concurrency can use their language's native threading primitives (threading in Python, std::thread in C++, coroutines in Kotlin).
  • No conditional compilation -- a single build of the shared library works for all bindings, avoiding feature-flag divergence between languages.

Changes

  • lib.rs: Replace dual conditional resolve_input with a single sync version using util::exec()
  • Cargo.toml: Remove cpp-bindings feature flag and uniffi tokio feature
  • .tasks.yml: Remove --features cpp-bindings from bindings-cpp task
  • README.md: Add "Synchronous API Design" section documenting the rationale; remove feature flag references from C++ instructions
  • CHANGELOG.md: Document changes in Unreleased section

Testing

All 19 unit tests pass (cargo test -p gl-sdk).

cdecker added 4 commits May 20, 2026 18:41
Replace the two conditional resolve_input implementations (async for
non-CPP, sync for cpp-bindings) with a single synchronous version
that wraps async internals via util::exec().

The entire public API exposed by the SDK through UniFFI is now
synchronous. Functions that need async work (network I/O, gRPC)
block the calling thread while an internal Tokio runtime executes
the underlying operations. This gives every target language (Python,
Kotlin, Swift, Ruby, C++) the same blocking API without requiring an
async runtime or special feature flags on the caller side.

- Remove `#[cfg(feature = "cpp-bindings")]` conditional compilation
- Remove `#[uniffi::export(async_runtime = "tokio")]` attribute
- Remove `cpp-bindings` feature from Cargo.toml
- Drop uniffi `tokio` feature (no longer needed)
The cpp-bindings feature flag no longer exists; the standard build
now produces a library that works for all bindings including C++.
Add a Synchronous API Design section to README.md explaining the
rationale: uniform bindings across all languages, simpler caller-side
integration, and no conditional compilation. Remove references to the
now-deleted cpp-bindings feature from the C++ bindings instructions.
Document the resolve_input() synchronous switch and the removal of
the cpp-bindings feature flag in the Unreleased section.
@cdecker cdecker force-pushed the 2026w20-resolve-input-sync branch from dde2459 to d7f0c84 Compare May 20, 2026 16:41
glsdk::resolve_input is now synchronous (blocks internally via
util::exec). The NAPI binding was still .await-ing the Result,
causing a compile error:

  error[E0277]: Result<ResolvedInput, Error> is not a future

Wrap the call in tokio::task::spawn_blocking, consistent with
every other blocking SDK call in the NAPI bindings.
@cdecker cdecker merged commit c947a18 into main May 20, 2026
16 checks passed
@cdecker cdecker deleted the 2026w20-resolve-input-sync branch May 20, 2026 17:28
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