Skip to content
Merged
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
42 changes: 41 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
name: CI

# Unless we are on the main branch, the workflow should stop and yield to a new run if new code is pushed.
concurrency:
group: ${{ github.workflow }}-${{ github.ref == 'refs/heads/main' && github.sha || github.ref }}
cancel-in-progress: ${{ !contains(github.ref, 'main')}}

on:
push:
branches: [main]
Expand Down Expand Up @@ -56,6 +61,41 @@ jobs:
- name: Run Swift foreign binding tests
run: ./swift/test_swift.sh

- name: Install SwiftLint
run: |
brew install swiftlint

- name: Lint Swift Tests
run: swiftlint swift/tests

kotlin-build-and-test:
name: Kotlin Build & Foreign Binding Tests
runs-on: ubuntu-latest
permissions:
contents: read

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.92.0

- name: Build and test Kotlin bindings
run: ./kotlin/test_kotlin.sh

- name: Install ktlint
run: |
curl -sSLO https://github.com/pinterest/ktlint/releases/latest/download/ktlint &&
chmod a+x ktlint &&
sudo mv ktlint /usr/local/bin/

- name: Lint Kotlin Tests
run: |
ktlint kotlin/walletkit-tests/src/test/kotlin

test:
name: Tests
runs-on: ubuntu-latest
Expand Down Expand Up @@ -112,7 +152,7 @@ jobs:
- uses: EmbarkStudios/cargo-deny-action@v2
with:
command: check ${{ matrix.checks }}
rust-version: stable
rust-version: 1.92.0

docs:
name: Check docs
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/initiate-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,17 @@ jobs:
env:
BUMP_TYPE: ${{ github.event.inputs.bump_type }}
run: |
# Get current version from Cargo.toml
CURRENT_VERSION=$(grep -m 1 'version = ' Cargo.toml | cut -d '"' -f 2)
# Get current version from workspace package in Cargo.toml
CURRENT_VERSION=$(cargo metadata --no-deps --format-version 1 | jq -r '.workspace_members[0]' | cut -d '#' -f2)

# Ensure CURRENT_VERSION is in semantic versioning format
if [[ ! "$CURRENT_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "CRITICAL ERROR: CURRENT_VERSION '$CURRENT_VERSION' is not in semantic versioning format (MAJOR.MINOR.PATCH)."
exit 1
fi

cargo metadata --no-deps --format-version 1 | jq -r '.workspace_members'

# Split version into components
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION"

Expand Down
31 changes: 14 additions & 17 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ jobs:
components: rustfmt

- name: Build the project (iOS)
run: ./build_swift.sh
run: ./swift/build_swift.sh

- name: Compress XCFramework binary
run: |
zip -r WalletKit.xcframework.zip WalletKit.xcframework
zip -r WalletKit.xcframework.zip swift/WalletKit.xcframework

- name: Checkout swift repo
uses: actions/checkout@v4
Expand Down Expand Up @@ -112,11 +112,11 @@ jobs:

run: |
# Copy non-binary source files
cp -r Sources/ target-repo/Sources
cp -r swift/Sources/ target-repo/Sources

# Prepare Package.swift
brew install swiftlint
./archive_swift.sh --asset-url "$ASSET_URL" --checksum "$CHECKSUM" --release-version "$NEW_VERSION"
./swift/archive_swift.sh --asset-url "$ASSET_URL" --checksum "$CHECKSUM" --release-version "$NEW_VERSION"
cp Package.swift target-repo/

# Commit changes
Expand Down Expand Up @@ -210,7 +210,7 @@ jobs:

- name: Move artifacts
run: |
mkdir -p kotlin/lib/src/main/jniLibs && cd kotlin/lib/src/main/jniLibs
mkdir -p kotlin/walletkit/src/main/jniLibs && cd kotlin/walletkit/src/main/jniLibs
mkdir armeabi-v7a arm64-v8a x86 x86_64
mv /home/runner/work/walletkit/walletkit/android-armv7-linux-androideabi/libwalletkit.so ./armeabi-v7a/libwalletkit.so
mv /home/runner/work/walletkit/walletkit/android-aarch64-linux-android/libwalletkit.so ./arm64-v8a/libwalletkit.so
Expand All @@ -219,11 +219,11 @@ jobs:

- name: Generate bindings
working-directory: kotlin
run: cargo run -p uniffi-bindgen generate ./lib/src/main/jniLibs/arm64-v8a/libwalletkit.so --library --language kotlin --no-format --out-dir lib/src/main/java
run: cargo run -p uniffi-bindgen generate ./walletkit/src/main/jniLibs/arm64-v8a/libwalletkit.so --library --language kotlin --no-format --out-dir walletkit/src/main/java

- name: Publish
working-directory: kotlin
run: ./gradlew lib:publish -PversionName=${{ needs.pre-release-checks.outputs.new_version }}
run: ./gradlew walletkit:publish
env:
GITHUB_ACTOR: wld-walletkit-bot
GITHUB_TOKEN: ${{ github.token }}
Expand All @@ -243,16 +243,13 @@ jobs:
make_latest: true

- name: Create Release in swift repo
uses: softprops/action-gh-release@v2
with:
repository: worldcoin/walletkit-swift
token: ${{ secrets.WALLETKIT_BOT_TOKEN }}
name: ${{ needs.pre-release-checks.outputs.new_version }}
tag_name: ${{ needs.pre-release-checks.outputs.new_version }}
body: |
## Version ${{ needs.pre-release-checks.outputs.new_version }}
For full release notes, see the [main repo release](https://github.com/worldcoin/walletkit/releases/tag/${{ needs.pre-release-checks.outputs.new_version }}).
make_latest: true
env:
GH_TOKEN: ${{ secrets.WALLETKIT_BOT_TOKEN }}
run: |
gh release edit ${{ needs.pre-release-checks.outputs.new_version }} \
--repo worldcoin/walletkit-swift \
--draft=false \
--latest

publish-to-crates-io:
needs: [pre-release-checks, create-github-release]
Expand Down
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,17 @@ target/
# Swift build outputs are not committed to this repo.
WalletKit.xcframework/
Sources/
swift/WalletKit.xcframework/
swift/Sources/
swift/ios_build/
swift/local_build/
swift/tests/Sources/
swift/tests/.build/

# Kotlin bindings and native libs
kotlin/libs/
kotlin/walletkit/src/main/java/uniffi/
kotlin/walletkit-tests/build/
.build/

.env
Expand All @@ -21,4 +31,8 @@ Sources/
cache/
**/out/build-info

# Allow storage cache module sources.
!walletkit-core/src/storage/cache/
!walletkit-core/src/storage/cache/**

# NOTE: Cargo.lock is not ignored because it is used for FFI builds (Swift & Kotlin)
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ WalletKit's bindings for Kotlin are distributed through GitHub packages.
```kotlin
dependencies {
/// ...
implementation "org.world:walletkit-android:VERSION"
implementation "org.world:walletkit:VERSION"
}
```

Expand Down Expand Up @@ -70,7 +70,7 @@ To test local changes before publishing a release, use the build script to compi
This will:
1. Build the Rust library for all Android architectures (arm64-v8a, armeabi-v7a, x86_64, x86)
2. Generate Kotlin UniFFI bindings
3. Publish to `~/.m2/repository/org/world/walletkit-android/`
3. Publish to `~/.m2/repository/org/world/walletkit/`

In your consuming project, ensure `mavenLocal()` is included in your repositories and update your dependency version to the SNAPSHOT version (e.g., `0.3.1-SNAPSHOT`).

Expand Down
6 changes: 3 additions & 3 deletions build_android_local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ cd kotlin

# Publish to Maven Local
echo "Publishing to Maven Local..."
./gradlew :lib:publishToMavenLocal -PversionName="$VERSION"
./gradlew :walletkit:publishToMavenLocal -PversionName="$VERSION"

echo ""
echo "✅ Successfully published $VERSION to Maven Local!"
echo "Published to: ~/.m2/repository/org/world/walletkit-android/$VERSION/"
echo "Published to: ~/.m2/repository/org/world/walletkit/$VERSION/"
echo ""
echo "To use in your project:"
echo " implementation 'org.world:walletkit-android:$VERSION'"
echo " implementation 'org.world:walletkit:$VERSION'"
26 changes: 26 additions & 0 deletions kotlin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Kotlin for WalletKit

This folder contains support files for WalletKit to work in Kotlin:

1. Script to build Kotlin/JNA bindings.
2. Foreign tests (JUnit) for Kotlin in the `walletkit-tests` module.

## Building the Kotlin project

```bash
# run from the walletkit directory
./kotlin/build_kotlin.sh
```

## Running foreign tests for Kotlin

```bash
# run from the walletkit directory
./kotlin/test_kotlin.sh
```

## Kotlin project structure

The Kotlin project has two members:
- `walletkit`: The main WalletKit library with UniFFI bindings for Kotlin.
- `walletkit-tests`: Unit tests to assert the Kotlin bindings behave as intended (foreign tests).
14 changes: 7 additions & 7 deletions kotlin/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -e
echo "Building WalletKit Android SDK..."

# Create jniLibs directories
mkdir -p ./lib/src/main/jniLibs/{arm64-v8a,armeabi-v7a,x86_64,x86}
mkdir -p ./walletkit/src/main/jniLibs/{arm64-v8a,armeabi-v7a,x86_64,x86}

# Build for all Android architectures
echo "Building for aarch64-linux-android..."
Expand All @@ -21,18 +21,18 @@ cross build -p walletkit --release --target=i686-linux-android --features v4

# Move .so files to jniLibs
echo "Moving native libraries..."
mv ../target/aarch64-linux-android/release/libwalletkit.so ./lib/src/main/jniLibs/arm64-v8a/libwalletkit.so
mv ../target/armv7-linux-androideabi/release/libwalletkit.so ./lib/src/main/jniLibs/armeabi-v7a/libwalletkit.so
mv ../target/x86_64-linux-android/release/libwalletkit.so ./lib/src/main/jniLibs/x86_64/libwalletkit.so
mv ../target/i686-linux-android/release/libwalletkit.so ./lib/src/main/jniLibs/x86/libwalletkit.so
mv ../target/aarch64-linux-android/release/libwalletkit.so ./walletkit/src/main/jniLibs/arm64-v8a/libwalletkit.so
mv ../target/armv7-linux-androideabi/release/libwalletkit.so ./walletkit/src/main/jniLibs/armeabi-v7a/libwalletkit.so
mv ../target/x86_64-linux-android/release/libwalletkit.so ./walletkit/src/main/jniLibs/x86_64/libwalletkit.so
mv ../target/i686-linux-android/release/libwalletkit.so ./walletkit/src/main/jniLibs/x86/libwalletkit.so

# Generate Kotlin bindings
echo "Generating Kotlin bindings..."
cargo run -p uniffi-bindgen generate \
./lib/src/main/jniLibs/arm64-v8a/libwalletkit.so \
./walletkit/src/main/jniLibs/arm64-v8a/libwalletkit.so \
--library \
--language kotlin \
--no-format \
--out-dir lib/src/main/java
--out-dir walletkit/src/main/java

echo "✅ Build complete!"
41 changes: 41 additions & 0 deletions kotlin/build_kotlin.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env bash
set -euo pipefail

# Creates Kotlin/JNA bindings for the `walletkit` library.
# This mirrors the Bedrock Kotlin build flow.

PROJECT_ROOT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
KOTLIN_DIR="$PROJECT_ROOT_PATH/kotlin"
JAVA_SRC_DIR="$KOTLIN_DIR/walletkit/src/main/java"
LIBS_DIR="$KOTLIN_DIR/libs"

# Clean previous artifacts
rm -rf "$JAVA_SRC_DIR" "$LIBS_DIR"
mkdir -p "$JAVA_SRC_DIR" "$LIBS_DIR"

echo "🟢 Building Rust cdylib for host platform"
cargo build --package walletkit --release

# Determine the correct library file extension and copy it
if [[ "$OSTYPE" == "darwin"* ]]; then
LIB_FILE="$PROJECT_ROOT_PATH/target/release/libwalletkit.dylib"
cp "$LIB_FILE" "$LIBS_DIR/"
echo "📦 Copied libwalletkit.dylib for macOS"
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
LIB_FILE="$PROJECT_ROOT_PATH/target/release/libwalletkit.so"
cp "$LIB_FILE" "$LIBS_DIR/"
echo "📦 Copied libwalletkit.so for Linux"
else
echo "❌ Unsupported OS: $OSTYPE"
exit 1
fi

echo "🟡 Generating Kotlin bindings via uniffi-bindgen"
cargo run -p uniffi-bindgen -- generate \
"$LIB_FILE" \
--language kotlin \
--library \
--crate walletkit_core \
--out-dir "$JAVA_SRC_DIR"

echo "✅ Kotlin bindings written to $JAVA_SRC_DIR"
2 changes: 1 addition & 1 deletion kotlin/lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ afterEvaluate {
publications {
create<MavenPublication>("maven") {
groupId = "org.world"
artifactId = "walletkit-android"
artifactId = "walletkit"

version = if (project.hasProperty("versionName")) {
project.property("versionName") as String
Expand Down
4 changes: 3 additions & 1 deletion kotlin/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pluginManagement {
plugins {
id("com.android.library") version "8.3.0"
id("org.jetbrains.kotlin.android") version "1.9.22"
id("org.jetbrains.kotlin.jvm") version "1.9.22"
}
}

Expand All @@ -25,4 +26,5 @@ dependencyResolutionManagement {
}

rootProject.name = "walletkit"
include("lib")
include("walletkit")
include("walletkit-tests")
Loading