-
Notifications
You must be signed in to change notification settings - Fork 41
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 native binding #784
Closed
Closed
Add native binding #784
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
13ede60
feat: implement native iota sdk
lmoe a20e3d5
Merge branch '1.1' into add_native_binding
0971f09
Merge branch '1.1' into add_native_binding
thibault-martinez f8b4492
Merge branch '1.1' into add_native_binding
thibault-martinez 564525e
Merge branch '1.1' into add_native_binding
thibault-martinez 7938ee5
Merge branch 'develop' into add_native_binding
thibault-martinez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
name: Native prebuilt publish | ||
|
||
on: workflow_dispatch | ||
|
||
env: | ||
CARGO_INCREMENTAL: 0 | ||
|
||
jobs: | ||
native-binding-prebuilt: | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: [ubuntu-20.04, macos-13, windows-2022] | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Select Xcode | ||
uses: maxim-lobanov/setup-xcode@v1 | ||
if: matrix.os == 'macos-13' | ||
with: | ||
xcode-version: '14.3' | ||
|
||
- name: Install Rust toolchain | ||
uses: actions-rs/toolchain@v1 | ||
with: | ||
toolchain: stable | ||
override: true | ||
|
||
- name: Install LLVM and Clang (Windows) # required for bindgen to work, see https://github.com/rust-lang/rust-bindgen/issues/1797 | ||
uses: KyleMayes/install-llvm-action@32c4866ebb71e0949e8833eb49beeebed48532bd | ||
if: matrix.os == 'windows-2022' | ||
with: | ||
version: "11.0" | ||
directory: ${{ runner.temp }}/llvm | ||
|
||
- name: Set LIBCLANG_PATH (Windows) | ||
run: echo "LIBCLANG_PATH=$((gcm clang).source -replace "clang.exe")" >> $env:GITHUB_ENV | ||
if: matrix.os == 'windows-2022' | ||
|
||
- name: Set deployment target (macOS) | ||
run: echo "MACOSX_DEPLOYMENT_TARGET=10.13" >> $GITHUB_ENV | ||
if: matrix.os == 'macos-13' | ||
|
||
- name: Get current date | ||
run: echo "CURRENT_DATE=$(date +'%Y-%m-%d')" >> $GITHUB_ENV | ||
if: matrix.os == 'macos-13' || ${{ startsWith(matrix.os, 'ubuntu') }} | ||
|
||
- name: Get current date | ||
if: matrix.os == 'windows-2022' | ||
run: echo "CURRENT_DATE=$(Get-Date -Format "yyyy-MM-dd")" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append | ||
|
||
- name: Install required packages (Ubuntu) | ||
if: ${{ startsWith(matrix.os, 'ubuntu') }} | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install libudev-dev libusb-1.0-0-dev | ||
|
||
- name: Cache cargo registry | ||
uses: actions/cache@v3 | ||
with: | ||
path: ~/.cargo/registry | ||
# Add date to the cache to keep it up to date | ||
key: ${{ matrix.os }}-stable-cargo-registry-${{ hashFiles('**/Cargo.lock') }}-${{ env.CURRENT_DATE }} | ||
# Restore from outdated cache for speed | ||
restore-keys: | | ||
${{ matrix.os }}-stable-cargo-registry-${{ hashFiles('**/Cargo.lock') }} | ||
${{ matrix.os }}-stable-cargo-registry- | ||
- name: Cache cargo index | ||
uses: actions/cache@v3 | ||
with: | ||
path: ~/.cargo/git | ||
# Add date to the cache to keep it up to date | ||
key: ${{ matrix.os }}-stable-cargo-index-${{ hashFiles('**/Cargo.lock') }}-${{ env.CURRENT_DATE }} | ||
# Restore from outdated cache for speed | ||
restore-keys: | | ||
${{ matrix.os }}-stable-cargo-index-${{ hashFiles('**/Cargo.lock') }} | ||
${{ matrix.os }}-stable-cargo-index- | ||
|
||
# This step is required to support macOS 10.13 | ||
- name: Patch librocksdb-sys (macOS) | ||
if: ${{ startsWith(matrix.os, 'macos') }} | ||
run: | | ||
cargo install cargo-patch | ||
cp ${{ github.workspace }}/.patches/rocksdb_faligned_allocation.patch . | ||
git apply --ignore-space-change --ignore-whitespace ${{ github.workspace }}/.patches/macos_cargo_toml.patch | ||
cat Cargo.toml | ||
cargo patch | ||
|
||
- name: Cargo build | ||
run: cargo build --release | ||
working-directory: bindings/native |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[target.x86_64-pc-windows-msvc] | ||
rustflags = ["-C", "target-feature=+crt-static"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
[package] | ||
name = "iota-sdk-native" | ||
version = "0.1.0" | ||
authors = [ "IOTA Stiftung" ] | ||
edition = "2021" | ||
description = "Native wrapper for the IOTA SDK library" | ||
documentation = "https://wiki.iota.org/iota-sdk/welcome" | ||
homepage = "https://www.iota.org/" | ||
repository = "https://github.com/iotaledger/iota-sdk" | ||
license = "Apache-2.0" | ||
keywords = [ "iota", "client", "wallet", "transaction", "native" ] | ||
categories = [ "cryptography::cryptocurrencies" ] | ||
publish = false | ||
|
||
[lib] | ||
name = "iota_sdk_native" | ||
crate-type = [ "cdylib" ] | ||
doc = false | ||
|
||
[features] | ||
default = ["std"] | ||
std = ["zeroize/std"] | ||
|
||
[dependencies] | ||
iota-sdk-bindings-core = { path = "../core", default-features = false, features = [ "events", "rocksdb", "ledger_nano", "storage", "stronghold" ] } | ||
|
||
futures = { version = "0.3.28", default-features = false } | ||
once_cell = { version = "1.17.2", default-features = false } | ||
serde_json = { version = "1.0.96", default-features = false } | ||
tokio = { version = "1.28.2", default-features = false } | ||
log = { version = "0.4.14" } | ||
zeroize = { version = "1.6.0", default-features = false } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# IOTA SDK Native | ||
|
||
This binding wraps the IOTA SDK into a native, shared library. | ||
|
||
It can be referenced by other languages such as Go, C/C++ or C#. | ||
|
||
It exports the following functions: | ||
|
||
``` | ||
init_logger | ||
binding_get_last_error | ||
|
||
call_client_method | ||
call_secret_manager_method | ||
call_utils_method | ||
call_wallet_method | ||
|
||
create_client | ||
create_secret_manager | ||
create_wallet | ||
listen_wallet | ||
|
||
destroy_client | ||
destroy_secret_manager | ||
destroy_string | ||
destroy_wallet | ||
|
||
get_client_from_wallet | ||
get_secret_manager_from_wallet | ||
``` | ||
|
||
Generated C/C++ headers can be found under `bindings/native/headers`. | ||
|
||
Headers can be regenerated by running `bindings/native/bindgen.sh`. This requires [cbindgen](https://github.com/mozilla/cbindgen/). | ||
|
||
An example implementation in Go can be found [here](https://github.com/iotaledger/wasp-wallet-sdk/blob/main/wrapper.go). | ||
|
||
# Usage | ||
|
||
All strings need to be null terminated. | ||
|
||
All strings coming from the library need to be free'd by calling `destroy_string` after receiving and copying them. | ||
|
||
Any function that either returns a `NULL` pointer or `false` might have catched an error. | ||
|
||
This error can be obtained via `get_last_error`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
|
||
cbindgen --crate iota-sdk-native --output headers/iota_sdk.h --lang c | ||
cbindgen --crate iota-sdk-native --output headers/iota_sdk.hpp --lang c++ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include <stdarg.h> | ||
#include <stdbool.h> | ||
#include <stdint.h> | ||
#include <stdlib.h> | ||
|
||
typedef struct Client Client; | ||
|
||
typedef struct SecretManager SecretManager; | ||
|
||
typedef struct Wallet Wallet; | ||
|
||
bool destroy_string(char *ptr); | ||
|
||
bool init_logger(const char *config_ptr); | ||
|
||
const char *call_utils_method(const char *config_ptr); | ||
|
||
const struct Client *create_client(const char *options_ptr); | ||
|
||
bool destroy_client(struct Client *client_ptr); | ||
|
||
const char *call_client_method(struct Client *client_ptr, char *method_ptr); | ||
|
||
const char *binding_get_last_error(void); | ||
|
||
const struct SecretManager *create_secret_manager(const char *options_ptr); | ||
|
||
bool destroy_secret_manager(struct SecretManager *secret_manager_ptr); | ||
|
||
const char *call_secret_manager_method(struct SecretManager *secret_manager, const char *method); | ||
|
||
bool destroy_wallet(struct Wallet *wallet_ptr); | ||
|
||
const struct Wallet *create_wallet(const char *options_ptr); | ||
|
||
const char *call_wallet_method(struct Wallet *wallet_ptr, const char *method_ptr); | ||
|
||
bool listen_wallet(struct Wallet *wallet_ptr, const char *events, void (*handler)(const char*)); | ||
|
||
const struct Client *get_client_from_wallet(struct Wallet *wallet_ptr); | ||
|
||
const struct SecretManager *get_secret_manager_from_wallet(struct Wallet *wallet_ptr); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#include <cstdarg> | ||
#include <cstdint> | ||
#include <cstdlib> | ||
#include <ostream> | ||
#include <new> | ||
|
||
struct Client; | ||
|
||
struct SecretManager; | ||
|
||
struct Wallet; | ||
|
||
extern "C" { | ||
|
||
bool destroy_string(char *ptr); | ||
|
||
bool init_logger(const char *config_ptr); | ||
|
||
const char *call_utils_method(const char *config_ptr); | ||
|
||
const Client *create_client(const char *options_ptr); | ||
|
||
bool destroy_client(Client *client_ptr); | ||
|
||
const char *call_client_method(Client *client_ptr, char *method_ptr); | ||
|
||
const char *binding_get_last_error(); | ||
|
||
const SecretManager *create_secret_manager(const char *options_ptr); | ||
|
||
bool destroy_secret_manager(SecretManager *secret_manager_ptr); | ||
|
||
const char *call_secret_manager_method(SecretManager *secret_manager, const char *method); | ||
|
||
bool destroy_wallet(Wallet *wallet_ptr); | ||
|
||
const Wallet *create_wallet(const char *options_ptr); | ||
|
||
const char *call_wallet_method(Wallet *wallet_ptr, const char *method_ptr); | ||
|
||
bool listen_wallet(Wallet *wallet_ptr, const char *events, void (*handler)(const char*)); | ||
|
||
const Client *get_client_from_wallet(Wallet *wallet_ptr); | ||
|
||
const SecretManager *get_secret_manager_from_wallet(Wallet *wallet_ptr); | ||
|
||
} // extern "C" |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this actually publish anything?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not super well versed with those workflows.
I've tested it in a private repo and I made it build and create downloadable artifacts.
Where they should be published to or anything else, I don't know how you want that handled and figured you know it better than I do. :)
If you give me some instructions I might be able to complete the workflow on my own.