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

bindings: Narrow uniffi interface #351

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
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
Loading