Skip to content
Closed
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
143 changes: 143 additions & 0 deletions .github/workflows/ffi-flutter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
name: FFI - Flutter Bindings

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
verify-flutter-bindings:
name: Verify Flutter Bindings
runs-on: ubuntu-latest
steps:
- name: Checkout CDK
uses: actions/checkout@v4

- name: Install Flutter
uses: subosito/flutter-action@v2
with:
channel: 'stable'

- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
components: clippy, rustfmt

- name: Rust Cache
uses: Swatinem/rust-cache@v2

- name: Install Flutter Rust Bridge Codegen
run: cargo install flutter_rust_bridge_codegen --version 2.11.1

- name: Scaffold Test Project
run: |
# Create project structure
mkdir -p cdk_flutter_test/rust/src/api
mkdir -p cdk_flutter_test/lib

# 1. Create pubspec.yaml
cat <<EOF > cdk_flutter_test/pubspec.yaml
name: cdk_flutter_test
description: "Test project for CDK Flutter bindings"
version: 0.1.0
environment:
sdk: ^3.0.0
dependencies:
flutter:
sdk: flutter
flutter_rust_bridge: 2.11.1
dev_dependencies:
ffigen: ^13.0.0
build_runner: ^2.4.14
freezed: ^2.5.7
flutter:
plugin:
platforms:
android:
ffiPlugin: true
ios:
ffiPlugin: true
linux:
ffiPlugin: true
macos:
ffiPlugin: true
windows:
ffiPlugin: true
EOF

# 2. Create Cargo.toml
# We point dependencies to the local checkout of CDK
cat <<EOF > cdk_flutter_test/rust/Cargo.toml
[package]
name = "cdk_flutter_test"
version = "0.1.0"
edition = "2021"

[lib]
crate-type = ["cdylib", "staticlib"]

[dependencies]
cdk = { path = "../../crates/cdk", default-features = false, features = ["wallet"] }
cdk-common = { path = "../../crates/cdk-common", default-features = false }
cdk-sqlite = { path = "../../crates/cdk-sqlite", default-features = false, features = ["wallet"] }
flutter_rust_bridge = { version = "=2.11.1", features = ["anyhow", "dart-opaque", "portable-atomic", "rust-async", "thread-pool", "wasm-start"] }
tokio = { version = "1", features = ["full"] }
anyhow = "1"
EOF

# 3. Create Rust Source

# rust/src/lib.rs
cat <<EOF > cdk_flutter_test/rust/src/lib.rs
pub mod api;
EOF

# rust/src/api/mod.rs
cat <<EOF > cdk_flutter_test/rust/src/api/mod.rs
pub mod wallet;
EOF

# rust/src/api/wallet.rs
# This mimics a subset of the actual cdk-flutter bindings to verify API compatibility
cat <<EOF > cdk_flutter_test/rust/src/api/wallet.rs
use flutter_rust_bridge::frb;
use cdk::wallet::Wallet;
use cdk::Amount;
use std::sync::Arc;

#[frb(opaque)]
pub struct CdkWallet {
pub inner: Wallet,
}

impl CdkWallet {
pub fn new() -> Self {
panic!("Scaffold test only")
}

pub fn get_unit(&self) -> String {
self.inner.unit.to_string()
}
}

pub fn verify_amount_type() {
let _ = Amount::from(100);
}
EOF

echo "✅ Scaffolded test project"

- name: Generate Bindings
run: |
cd cdk_flutter_test
flutter pub get

# Generate bindings
# This verifies that the Rust API matches what FRB expects and that types are compatible
flutter_rust_bridge_codegen generate

- name: Verify Compilation
run: |
cd cdk_flutter_test/rust
cargo check
42 changes: 42 additions & 0 deletions .github/workflows/ffi-kotlin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: FFI - Kotlin Bindings

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
verify-kotlin:
name: Verify Kotlin Bindings
runs-on: ubuntu-latest
steps:
- name: Checkout CDK
uses: actions/checkout@v4
with:
path: cdk

- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v17

- name: Nix Cache
uses: DeterminateSystems/magic-nix-cache-action@main

- name: Rust Cache
uses: Swatinem/rust-cache@v2
with:
workspaces: cdk

- name: Generate Bindings
run: |
cd cdk
# Builds cdk-ffi and generates kotlin bindings
nix develop .#ffi --command just ffi-generate-kotlin

- name: Verify Artifacts
run: |
if [ ! -f "cdk/target/bindings/kotlin/org/cashudevkit/cdk_ffi.kt" ]; then
echo "Error: Kotlin bindings not found"
exit 1
fi
echo "Kotlin bindings generated successfully"
184 changes: 184 additions & 0 deletions .github/workflows/ffi-python.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
name: FFI - Python Bindings

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
build-wheel-x86_64:
name: Build Python Wheel (x86_64)
runs-on: ubuntu-latest
container: quay.io/pypa/manylinux_2_28_x86_64
steps:
- name: Checkout CDK
uses: actions/checkout@v4

- name: Install System Dependencies
run: yum install -y openssl-devel pkg-config

- name: Install Rust
run: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source $HOME/.cargo/env
rustup target add x86_64-unknown-linux-gnu

- name: Scaffold Python Package
run: |
mkdir -p python-package/src/cdk

# Create pyproject.toml
cat <<EOF > python-package/pyproject.toml
[build-system]
requires = ["setuptools>=61.0", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "cdk-python"
version = "0.0.1"
description = "CDK Python Bindings (CI Build)"
requires-python = ">=3.10"
license = {text = "MIT"}
authors = [{name = "CDK Developers", email = "tsk@cashudevkit.org"}]

[tool.setuptools]
packages = ["cdk"]

[tool.setuptools.package-dir]
cdk = "src/cdk"

[tool.setuptools.package-data]
cdk = ["*.so", "*.dylib", "*.dll", "*.pyi"]
EOF

# Create __init__.py
cat <<EOF > python-package/src/cdk/__init__.py
"""CDK Python Bindings"""
from .cdk import *
EOF

- name: Build FFI & Generate Bindings
run: |
source $HOME/.cargo/env
cd crates/cdk-ffi

# Build Rust Library
cargo build --profile release-smaller --target x86_64-unknown-linux-gnu

# Generate Bindings
# Note: We are running natively on x86_64, so we use the native target for the generator
cargo run --target x86_64-unknown-linux-gnu --bin uniffi-bindgen generate \
--library ../../target/x86_64-unknown-linux-gnu/release-smaller/libcdk_ffi.so \
--language python \
--out-dir ../../python-package/src/cdk/

# Copy Shared Object
cp ../../target/x86_64-unknown-linux-gnu/release-smaller/libcdk_ffi.so ../../python-package/src/cdk/

- name: Build Wheel
run: |
cd python-package

# Find Python (Manylinux specific)
PYTHON_BIN="/opt/python/cp310-cp310/bin/python"

$PYTHON_BIN -m pip install build wheel auditwheel
$PYTHON_BIN -m build --wheel

# Auditwheel Repair
mkdir -p wheelhouse
for whl in dist/*.whl; do
$PYTHON_BIN -m auditwheel repair "$whl" --plat manylinux_2_28_x86_64 -w wheelhouse/
done

echo "✅ Wheel built and repaired successfully"
ls -lh wheelhouse/

build-wheel-aarch64:
name: Build Python Wheel (ARM64)
runs-on: ubuntu-24.04-arm
container: quay.io/pypa/manylinux_2_28_aarch64
steps:
- name: Checkout CDK
uses: actions/checkout@v4

- name: Install System Dependencies
run: yum install -y openssl-devel pkg-config

- name: Install Rust
run: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source $HOME/.cargo/env
rustup target add aarch64-unknown-linux-gnu

- name: Scaffold Python Package
run: |
mkdir -p python-package/src/cdk

# Create pyproject.toml
cat <<EOF > python-package/pyproject.toml
[build-system]
requires = ["setuptools>=61.0", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "cdk-python"
version = "0.0.1"
description = "CDK Python Bindings (CI Build)"
requires-python = ">=3.10"
license = {text = "MIT"}
authors = [{name = "CDK Developers", email = "tsk@cashudevkit.org"}]

[tool.setuptools]
packages = ["cdk"]

[tool.setuptools.package-dir]
cdk = "src/cdk"

[tool.setuptools.package-data]
cdk = ["*.so", "*.dylib", "*.dll", "*.pyi"]
EOF

# Create __init__.py
cat <<EOF > python-package/src/cdk/__init__.py
"""CDK Python Bindings"""
from .cdk import *
EOF

- name: Build FFI & Generate Bindings
run: |
source $HOME/.cargo/env
cd crates/cdk-ffi

# Build Rust Library
cargo build --profile release-smaller --target aarch64-unknown-linux-gnu

# Generate Bindings
# Note: We are running natively on ARM64, so we use the native target for the generator
cargo run --target aarch64-unknown-linux-gnu --bin uniffi-bindgen generate \
--library ../../target/aarch64-unknown-linux-gnu/release-smaller/libcdk_ffi.so \
--language python \
--out-dir ../../python-package/src/cdk/

# Copy Shared Object
cp ../../target/aarch64-unknown-linux-gnu/release-smaller/libcdk_ffi.so ../../python-package/src/cdk/

- name: Build Wheel
run: |
cd python-package

# Find Python (Manylinux specific)
PYTHON_BIN="/opt/python/cp310-cp310/bin/python"

$PYTHON_BIN -m pip install build wheel auditwheel
$PYTHON_BIN -m build --wheel

# Auditwheel Repair
mkdir -p wheelhouse
for whl in dist/*.whl; do
$PYTHON_BIN -m auditwheel repair "$whl" --plat manylinux_2_28_aarch64 -w wheelhouse/
done

echo "✅ Wheel built and repaired successfully"
ls -lh wheelhouse/
Loading
Loading