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 binding docstrings #512

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
257 changes: 97 additions & 160 deletions lib/Cargo.lock

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ log = "0.4.20"
once_cell = "1.19"
thiserror = "1.0"
# Version must match that used by uniffi-bindgen-go
uniffi = "0.25.0"
uniffi_macros = "0.25.0"
uniffi = { git = "https://github.com/NordSecurity/uniffi-rs.git", tag = "v0.3.1+v0.25.0" }
uniffi_bindgen = { git = "https://github.com/NordSecurity/uniffi-rs.git", tag = "v0.3.1+v0.25.0" }
uniffi_build = { git = "https://github.com/NordSecurity/uniffi-rs.git", tag = "v0.3.1+v0.25.0" }
uniffi_macros = { git = "https://github.com/NordSecurity/uniffi-rs.git", tag = "v0.3.1+v0.25.0" }

[patch.crates-io]
# https://github.com/BlockstreamResearch/rust-secp256k1-zkp/pull/48/commits
Expand Down
3 changes: 2 additions & 1 deletion lib/bindings/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ breez-sdk-liquid = { path = "../core" }
log = { workspace = true }
uniffi = { workspace = true, features = [ "bindgen-tests", "cli" ] }
# Bindgen used by KMP, version has to match the one supported by KMP
uniffi_bindgen = "0.25.2"
uniffi_bindgen = { workspace = true }
uniffi_bindgen_kmp = { version = "0.25.2", package = "uniffi_bindgen" }
Copy link
Contributor

Choose a reason for hiding this comment

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

With the new uniffi_bindgen_kmp, is the uniffi_bindgen_kotlin_multiplatform below still necessary?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I had to split the use of uniffi_bindgen because of compatibility issues, so uniffi_bindgen_kmp is uniffi_bindgen 0.25.2 for use with uniffi_bindgen_kotlin_multiplatform.

I will play around a bit more to see if I can get them to use the same uniffi_bindgen.

uniffi_bindgen_kotlin_multiplatform = { git = "https://gitlab.com/trixnity/uniffi-kotlin-multiplatform-bindings", rev = "e8e3a88df5b657787c1198425c16008232b26548" }
camino = "1.1.1"
thiserror = { workspace = true }
Expand Down
117 changes: 117 additions & 0 deletions lib/bindings/langs/flutter/scripts/pubspec.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
args:
dependency: "direct main"
description:
name: args
sha256: "7cf60b9f0cc88203c5a190b4cd62a99feea42759a7fa695010eb5de1c0b2252a"
url: "https://pub.dev"
source: hosted
version: "2.5.0"
async:
dependency: transitive
description:
name: async
sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c"
url: "https://pub.dev"
source: hosted
version: "2.11.0"
charcode:
dependency: transitive
description:
name: charcode
sha256: fb98c0f6d12c920a02ee2d998da788bca066ca5f148492b7085ee23372b12306
url: "https://pub.dev"
source: hosted
version: "1.3.1"
cli_script:
dependency: "direct main"
description:
name: cli_script
sha256: "3463c6e8e57271faaf557eee56cb455522f1ab1ebe618bbfb7454f74fc793967"
url: "https://pub.dev"
source: hosted
version: "0.3.1"
collection:
dependency: transitive
description:
name: collection
sha256: a1ace0a119f20aabc852d165077c036cd864315bd99b7eaa10a60100341941bf
url: "https://pub.dev"
source: hosted
version: "1.19.0"
file:
dependency: transitive
description:
name: file
sha256: "5fc22d7c25582e38ad9a8515372cd9a93834027aacf1801cf01164dac0ffa08c"
url: "https://pub.dev"
source: hosted
version: "7.0.0"
glob:
dependency: "direct main"
description:
name: glob
sha256: "0e7014b3b7d4dac1ca4d6114f82bf1782ee86745b9b42a92c9289c23d8a0ab63"
url: "https://pub.dev"
source: hosted
version: "2.1.2"
meta:
dependency: transitive
description:
name: meta
sha256: e3641ec5d63ebf0d9b41bd43201a66e3fc79a65db5f61fc181f04cd27aab950c
url: "https://pub.dev"
source: hosted
version: "1.16.0"
path:
dependency: transitive
description:
name: path
sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af"
url: "https://pub.dev"
source: hosted
version: "1.9.0"
source_span:
dependency: transitive
description:
name: source_span
sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c"
url: "https://pub.dev"
source: hosted
version: "1.10.0"
stack_trace:
dependency: transitive
description:
name: stack_trace
sha256: "9f47fd3630d76be3ab26f0ee06d213679aa425996925ff3feffdec504931c377"
url: "https://pub.dev"
source: hosted
version: "1.12.0"
string_scanner:
dependency: transitive
description:
name: string_scanner
sha256: "688af5ed3402a4bde5b3a6c15fd768dbf2621a614950b17f04626c431ab3c4c3"
url: "https://pub.dev"
source: hosted
version: "1.3.0"
term_glyph:
dependency: transitive
description:
name: term_glyph
sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84
url: "https://pub.dev"
source: hosted
version: "1.2.1"
tuple:
dependency: transitive
description:
name: tuple
sha256: a97ce2013f240b2f3807bcbaf218765b6f301c3eff91092bcfa23a039e7dd151
url: "https://pub.dev"
source: hosted
version: "2.0.2"
sdks:
dart: ">=3.4.0 <4.0.0"
14 changes: 8 additions & 6 deletions lib/bindings/langs/react-native/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,22 @@ edition = "2021"
anyhow = { version = "1.0.57", features = ["backtrace"] }
thiserror = "1.0"
tokio = { version = "1", features = ["full"] }
uniffi = { version = "0.23.0", features = ["bindgen-tests", "cli"] }
uniffi_bindgen = "0.23.0"
uniffi_macros = "0.23.0"
uniffi = { workspace = true, features = ["bindgen-tests", "cli"] }
uniffi_bindgen = { workspace = true }
uniffi_macros = { workspace = true }
camino = "1.1.1"
log = { workspace = true }
serde = "*"
askama = { version = "0.11.1", default-features = false, features = ["config"] }
askama = { version = "0.12", default-features = false, features = ["config"] }
toml = "0.5"
clap = { version = "3.2.22", features = ["derive"] }
heck = "0.4"
paste = "1.0"
once_cell = { workspace = true }
textwrap = "0.16"
regex = "1.11.0"

[build-dependencies]
uniffi_build = { version = "0.23.0" }
uniffi_bindgen = "0.23.0"
uniffi_build = { workspace = true }
uniffi_bindgen = { workspace = true }
anyhow = { version = "1.0.57", features = ["backtrace"] }
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use uniffi_bindgen::ComponentInterface;

use super::CodeType;

#[derive(Debug)]
pub struct CallbackInterfaceCodeType {
id: String,
}

impl CallbackInterfaceCodeType {
pub fn new(id: String) -> Self {
Self { id }
}
}

impl CodeType for CallbackInterfaceCodeType {
fn type_label(&self, ci: &ComponentInterface) -> String {
super::KotlinCodeOracle.class_name(ci, &self.id)
}

fn canonical_name(&self) -> String {
format!("Type{}", self.id)
}

fn initialization_fn(&self) -> Option<String> {
Some(format!("{}.register", self.ffi_converter_name()))
}
}
101 changes: 101 additions & 0 deletions lib/bindings/langs/react-native/src/gen_kotlin/compounds.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use super::CodeType;
use paste::paste;
use uniffi_bindgen::{
backend::{Literal, Type},
ComponentInterface,
};

#[allow(dead_code)]
fn render_literal(literal: &Literal, inner: &Type, ci: &ComponentInterface) -> String {
match literal {
Literal::Null => "null".into(),
Literal::EmptySequence => "listOf()".into(),
Literal::EmptyMap => "mapOf()".into(),

// For optionals
_ => super::KotlinCodeOracle.find(inner).literal(literal, ci),
}
}

macro_rules! impl_code_type_for_compound {
($T:ty, $type_label_pattern:literal, $canonical_name_pattern: literal) => {
paste! {
#[derive(Debug)]
pub struct $T {
inner: Type,
}

impl $T {
pub fn new(inner: Type) -> Self {
Self { inner }
}
fn inner(&self) -> &Type {
&self.inner
}
}

impl CodeType for $T {
fn type_label(&self, ci: &ComponentInterface) -> String {
format!($type_label_pattern, super::KotlinCodeOracle.find(self.inner()).type_label(ci))
}

fn canonical_name(&self) -> String {
format!($canonical_name_pattern, super::KotlinCodeOracle.find(self.inner()).canonical_name())
}

fn literal(&self, literal: &Literal, ci: &ComponentInterface) -> String {
render_literal(literal, self.inner(), ci)
}
}
}
}
}

impl_code_type_for_compound!(OptionalCodeType, "{}?", "Optional{}");
impl_code_type_for_compound!(SequenceCodeType, "List<{}>", "Sequence{}");

#[derive(Debug)]
pub struct MapCodeType {
key: Type,
value: Type,
}

impl MapCodeType {
pub fn new(key: Type, value: Type) -> Self {
Self { key, value }
}

fn key(&self) -> &Type {
&self.key
}

fn value(&self) -> &Type {
&self.value
}
}

impl CodeType for MapCodeType {
fn type_label(&self, ci: &ComponentInterface) -> String {
format!(
"Map<{}, {}>",
super::KotlinCodeOracle.find(self.key()).type_label(ci),
super::KotlinCodeOracle.find(self.value()).type_label(ci),
)
}

fn canonical_name(&self) -> String {
format!(
"Map{}{}",
super::KotlinCodeOracle.find(self.key()).canonical_name(),
super::KotlinCodeOracle.find(self.value()).canonical_name(),
)
}

fn literal(&self, literal: &Literal, ci: &ComponentInterface) -> String {
render_literal(literal, &self.value, ci)
}
}
28 changes: 28 additions & 0 deletions lib/bindings/langs/react-native/src/gen_kotlin/custom.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use uniffi_bindgen::ComponentInterface;

use super::CodeType;

#[derive(Debug)]
pub struct CustomCodeType {
name: String,
}

impl CustomCodeType {
pub fn new(name: String) -> Self {
CustomCodeType { name }
}
}

impl CodeType for CustomCodeType {
fn type_label(&self, _ci: &ComponentInterface) -> String {
self.name.clone()
}

fn canonical_name(&self) -> String {
format!("Type{}", self.name)
}
}
40 changes: 40 additions & 0 deletions lib/bindings/langs/react-native/src/gen_kotlin/enum_.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use uniffi_bindgen::{backend::Literal, ComponentInterface};

use super::CodeType;

#[derive(Debug)]
pub struct EnumCodeType {
id: String,
}

impl EnumCodeType {
pub fn new(id: String) -> Self {
Self { id }
}
}

impl CodeType for EnumCodeType {
fn type_label(&self, ci: &ComponentInterface) -> String {
super::KotlinCodeOracle.class_name(ci, &self.id)
}

fn canonical_name(&self) -> String {
format!("Type{}", self.id)
}

fn literal(&self, literal: &Literal, ci: &ComponentInterface) -> String {
if let Literal::Enum(v, _) = literal {
format!(
"{}.{}",
self.type_label(ci),
super::KotlinCodeOracle.enum_variant_name(v)
)
} else {
unreachable!();
}
}
}
Loading
Loading