Skip to content

Commit

Permalink
bindings: First version of the uniffi bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
cdecker committed May 31, 2024
1 parent 3b13604 commit 7a41cad
Show file tree
Hide file tree
Showing 11 changed files with 595 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ members = [
"libs/gl-client-py",
"libs/gl-plugin",
"libs/gl-signerproxy",
"libs/gl-client-bindings",
]

[workspace.dependencies]
Expand Down
19 changes: 19 additions & 0 deletions libs/gl-client-bindings/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "gl-client-bindings"
version = "0.1.0"
edition = "2021"

[lib]
crate-type = ["cdylib"]
name = "glclient"

[dependencies]
anyhow.workspace = true
gl-client = { path = "../gl-client", features = ["permissive"] }
thiserror = "1.0.56"
tokio = { version = "1", features = [], default-features = false}
uniffi = { version = "0.24" }
once_cell = "*"

[build-dependencies]
uniffi = { version = "0.24", features = [ "build" ] }
34 changes: 34 additions & 0 deletions libs/gl-client-bindings/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

.PHONY: generate

GENERATED := \
src/glclient.py \
src/glclient.rb \
src/glclient.swift \
src/glclient/glclient.go \
src/glclient/glclient.c \
src/glclient/glclient.h \
src/uniffi/glclient/glclient.kt

generate: src/glclient.py src/glclient.go src/glclient.rb src/glclient.swift src/glclient.kt

src/glclient.swift: src/glclient.udl src/glclient.uniffi.rs
cargo run -p uniffi-bindgen --features=uniffi/cli generate src/glclient.udl --language swift --no-format

src/glclient.rb: src/glclient.udl src/glclient.uniffi.rs
cargo run -p uniffi-bindgen --features=uniffi/cli generate src/glclient.udl --language ruby --no-format

src/uniffi/glclient/glclient.kt: src/glclient.udl src/glclient.uniffi.rs
cargo run -p uniffi-bindgen --features=uniffi/cli generate src/glclient.udl --language kotlin --no-format

src/glclient.py: src/glclient.udl src/glclient.uniffi.rs
cargo run -p uniffi-bindgen --features=uniffi/cli generate src/glclient.udl --language python --no-format

src/glclient/glclient.h src/glclient/glclient.c src/glclientglclient.go: src/glclient.udl src/glclient.uniffi.rs
uniffi-bindgen-go src/glclient.udl --no-format

src/glclient.uniffi.rs: src/glclient.udl
cargo run -p uniffi-bindgen --features=uniffi/cli scaffolding src/glclient.udl --no-format

clean:
rm -fv ${GENERATED}
3 changes: 3 additions & 0 deletions libs/gl-client-bindings/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
uniffi::generate_scaffolding("src/glclient.udl").unwrap();
}
12 changes: 12 additions & 0 deletions libs/gl-client-bindings/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("unhandled error: {0}")]
Other(#[from] anyhow::Error),
#[error("Invalid argument error: {0}")]
InvalidArgument(Box<dyn std::error::Error + Send + Sync>),
#[error("Error while calling {method}: {error}")]
Call {
method: String,
error: String,
},
}
32 changes: 32 additions & 0 deletions libs/gl-client-bindings/src/glclient.udl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
namespace glclient {
};

[Error]
enum Error {
"Call",
"Other",
"InvalidArgument",
};

interface Scheduler {

[Throws=Error]
constructor(bytes node_id, string network);

[Throws=Error]
void authenticate(bytes cert_pem, bytes key_pem);
};

interface RawClient {
[Throws=Error]
constructor(
bytes node_id,
string network,
bytes cert_pem,
bytes key_pem,
string node_uri
);

[Throws=Error]
bytes call(string method, bytes payload);
};
Loading

0 comments on commit 7a41cad

Please sign in to comment.