Skip to content

Commit

Permalink
Add workflows, opt. patches and updated Cargo file
Browse files Browse the repository at this point in the history
  • Loading branch information
lmoe committed Oct 26, 2023
1 parent bc0e398 commit c4133b6
Show file tree
Hide file tree
Showing 7 changed files with 236 additions and 4 deletions.
21 changes: 21 additions & 0 deletions .github/actions/setup-clang/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Set Up Clang/LLVM
description: "This composite action installs Clang/LLVM to the runner's temporary directory and sets LIBCLANG_PATH for the following steps, which is required for bindgen to work on Windows. See: https://github.com/rust-lang/rust-bindgen/issues/1797."
inputs:
version:
description: The version of Clang/LLVM to install.
type: string
required: false
default: '13'

runs:
using: composite
steps:
- name: Install Clang/LLVM
uses: KyleMayes/install-llvm-action@v1
with:
version: ${{ inputs.version }}
directory: ${{ runner.temp }}/llvm/

- name: Set LIBCLANG_PATH
shell: pwsh
run: Add-Content -Path "$Env:GITHUB_ENV" -Value "LIBCLANG_PATH=$Env:LLVM_PATH\bin"
54 changes: 54 additions & 0 deletions .github/actions/setup-rust/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Set Up Rust
description: Install the Rust toolchain, components, and set up the cache.
inputs:
toolchain:
description: Type of toolchain to install.
required: false
default: stable
targets:
description: Targets triple of the toolchain.
required: false
components:
description: Additional components to install.
required: false
install:
description: Additional tool to install via `cargo install`.
required: false
cache:
description: Whether to set up cache or not.
required: false
default: "true"
cache-root:
description: The root of cargo crate.
required: false
default: "."
additional-cache-dirs:
description: A newline-separated list of additional cache directories.
required: false

runs:
using: composite
steps:
- run: rustup set auto-self-update disable
if: contains(runner.os, 'windows')
shell: bash

- id: install
name: Install Rust Toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ inputs.toolchain }}
targets: ${{ inputs.targets }}
components: ${{ inputs.components }}

- name: Cache dependencies
if: ${{ inputs.cache == 'true' }}
uses: Swatinem/rust-cache@v2
with:
workspaces: "${{ inputs.cache-root }} -> target"
cache-directories: ${{ inputs.additional-cache-dirs }}

- name: Install ${{ inputs.install }}
if: ${{ inputs.install != '' }}
shell: bash
run: cargo install ${{ inputs.install }}
107 changes: 107 additions & 0 deletions .github/workflows/bindings-native-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
name: Native prebuilt publish

on:
release:
types: [published]

env:
CARGO_INCREMENTAL: 0

jobs:
native-binding-prebuilt:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [macos-13, ubuntu-20.04, windows-2022]

steps:
- uses: actions/checkout@v3

- name: List files in the repository
run: |
ls ${{ github.workspace }}
- 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.14" >> $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: matrix.os == 'macos-latest123'
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

- name: Upload package to Github release
uses: softprops/action-gh-release@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
files: |
target/release/libiota_sdk.so
target/release/iota_sdk.dll
target/release/libiota_sdk.dylib
fail_on_unmatched_files: false
tag_name: ${{ steps.prepare_release.outputs.tag_name }}
21 changes: 21 additions & 0 deletions .github/workflows/cancel-jobs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Cancel jobs from merged/closed pull request

on:
pull_request_target:
types: [closed]
# workflow_run:
# workflows: ["*"]
# types: [requested]


jobs:
merge_job:
runs-on: ubuntu-latest
permissions:
actions: write
steps:
- uses: styfle/cancel-workflow-action@0.11.0
with:
ignore_sha: true
access_token: ${{ secrets.GITHUB_TOKEN }}
workflow_id: all
17 changes: 17 additions & 0 deletions .patches/macos_cargo_toml.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
diff --git a/Cargo.toml b/Cargo.toml
index e00fa5df9..209f94d6c 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -25,3 +25,12 @@ codegen-units = 1
inherits = "release"
lto = true
strip = "symbols"
+
+[workspace.metadata.patch.librocksdb-sys]
+version = "0.11.0+8.1.1"
+patches = [
+ { path = "rocksdb_faligned_allocation.patch", source = "GithubPrDiff" },
+]
+
+[patch.crates-io]
+librocksdb-sys = { path = "./target/patch/librocksdb-sys-0.11.0+8.1.1"}
12 changes: 12 additions & 0 deletions .patches/rocksdb_faligned_allocation.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/build.rs b/build.rs
index dccaf29..582aa32 100644
--- a/build.rs
+++ b/build.rs
@@ -155,6 +155,7 @@ fn build_rocksdb() {
config.define("OS_MACOSX", None);
config.define("ROCKSDB_PLATFORM_POSIX", None);
config.define("ROCKSDB_LIB_IO_POSIX", None);
+ config.flag_if_supported("-faligned-allocation");
} else if target.contains("android") {
config.define("OS_ANDROID", None);
config.define("ROCKSDB_PLATFORM_POSIX", None);
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
[package]
name = "iota-sdk-native"
name = "iota-sdk-native-bindings"
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"
repository = "https://github.com/iotaledger/iota-sdk-native-bindings"
license = "Apache-2.0"
keywords = [ "iota", "client", "wallet", "transaction", "native" ]
categories = [ "cryptography::cryptocurrencies" ]
publish = false

[lib]
name = "iota_sdk_native"
name = "iota_sdk"
crate-type = [ "cdylib" ]
doc = false

Expand All @@ -22,7 +22,7 @@ default = ["std"]
std = ["zeroize/std"]

[dependencies]
iota-sdk-bindings-core = { git = "https://github.com/iotaledger/iota-sdk.git", branch = "develop", default-features = false, features = [
iota-sdk-bindings-core = { git = "https://github.com/iotaledger/iota-sdk.git", rev = "8f57f0c50f555b5e62f78ebf0177fc71b78f0396", default-features = false, features = [
"events",
"rocksdb",
"ledger_nano",
Expand Down

0 comments on commit c4133b6

Please sign in to comment.