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
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ target/
**/ios_build
.swiftpm/

# IDE
.idea
*.iml
.vscode
*/settings.json

# Swift build outputs are not committed to this repo.
WalletKit.xcframework/
Sources/
Expand All @@ -13,4 +19,4 @@ Sources/
cache/
**/out/build-info

# NOTE: Cargo.lock is not ignored because it is used for FFI builds (Swift & Kotlin)
# NOTE: Cargo.lock is not ignored because it is used for FFI builds (Swift & Kotlin)
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ edition = "2021"
authors = ["World Contributors"]
readme = "./README.md"
homepage = "https://docs.world.org" # TODO: Update to specific WalletKit page
rust-version = "1.86" # MSRV
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bumped the rust-version as I was running into Format, Clippy & Build and Tests issues https://github.com/worldcoin/walletkit/actions/runs/21117220277

rust-version = "1.91" # MSRV
repository = "https://github.com/worldcoin/walletkit"
exclude = ["tests/", "uniffi-bindgen/"]
keywords = ["ZKP", "WorldID", "World", "Identity", "Semaphore"]
Expand All @@ -26,6 +26,5 @@ world-id-core = { version = "0.3", default-features = false, features = ["authen
[profile.release]
opt-level = 'z' # Optimize for size.
lto = true # Enable Link Time Optimization.
strip = true # Automatically strip symbols from the binary.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the culprit of preventing bindings to get exposed and available from walletkit-android.

panic = "abort"
debug = false
9 changes: 8 additions & 1 deletion Cross.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
[build.env]
passthrough = [
"CARGO_NET_GIT_FETCH_WITH_CLI=true", # to force cargo to use git cli with config --global in homedir
"HOME", # set $HOME to shared dir where we put .gitconfig
"RUSTUP_HOME", # override rustup home to prevent host permission issues
"CARGO_HOME", # override cargo home to prevent host permission issues
]
# max-page-size=16384:
# Android 15 (API 35) introduces support for 16KB page sizes to improve performance on devices with larger RAM.
# Apps with native libraries MUST be compiled with 16KB ELF alignment or they will crash on startup
Expand All @@ -11,4 +18,4 @@ pre-build = [
"apt-get update && apt-get --assume-yes install pkg-config:$CROSS_DEB_ARCH",
"export PKG_CONFIG_ALLOW_CROSS=1",
"export PKG_CONFIG_LIBDIR=/usr/lib/$CROSS_DEB_ARCH/pkgconfig:/usr/lib/$CROSS_DEB_ARCH/lib/pkgconfig:/usr/share/pkgconfig",
]
]
40 changes: 39 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,52 @@ WalletKit's bindings for Kotlin are distributed through GitHub packages.
```kotlin
dependencies {
/// ...
implementation "org.world:walletkit:VERSION"
implementation "org.world:walletkit-android:VERSION"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
implementation "org.world:walletkit-android:VERSION"
implementation "org.world:walletkit:VERSION"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@paolodamico

artifactId = "walletkit-android"
do we want to change it to walletkit?

}
```

Replace `VERSION` with the desired WalletKit version.

2. Sync Gradle.

## Local development (Android/Kotlin)

### Prerequisites

1. **Docker Desktop**: Required for cross-compilation
- The build uses [`cross`](https://github.com/cross-rs/cross) which runs builds in Docker containers with all necessary toolchains
- Install via Homebrew:
```bash
brew install --cask docker
```
- Launch Docker Desktop and ensure it's running before building

2. **Android SDK + NDK**: Required for Gradle Android tasks
- Install via Android Studio > Settings > Android SDK (ensure the NDK is installed)
- Set `sdk.dir` (and `ndk.dir` if needed) in `kotlin/local.properties`

3. **Protocol Buffers compiler**:
```bash
brew install protobuf
```

### Building and publishing

To test local changes before publishing a release, use the build script to compile the Rust library, generate UniFFI bindings, and publish a SNAPSHOT to Maven Local:

```bash
./build_android_local.sh 0.3.1-SNAPSHOT
```

> **Note**: The script sets `RUSTUP_HOME` and `CARGO_HOME` to `/tmp` by default to avoid Docker permission issues when using `cross`. You can override them by exporting your own values.

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/`

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`).

## Overview

WalletKit is broken down into separate crates, offering the following functionality.
Expand Down
35 changes: 35 additions & 0 deletions build_android_local.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash
set -e

echo "Building WalletKit Android SDK for local development..."

# Set rustup and cargo home to /tmp to prevent Docker permission issues
export RUSTUP_HOME="${RUSTUP_HOME:-/tmp/.rustup}"
export CARGO_HOME="${CARGO_HOME:-/tmp/.cargo}"

# Version is required
if [ -z "$1" ]; then
echo "Error: Version parameter is required"
echo "Usage: ./build_android_local.sh <version>"
echo "Example: ./build_android_local.sh 0.2.1-SNAPSHOT"
exit 1
fi

VERSION="$1"
echo "Using version: $VERSION"

# Build using kotlin/build.sh
echo "Building WalletKit SDK..."
cd kotlin
./build.sh

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

echo ""
echo "✅ Successfully published $VERSION to Maven Local!"
echo "Published to: ~/.m2/repository/org/world/walletkit-android/$VERSION/"
echo ""
echo "To use in your project:"
echo " implementation 'org.world:walletkit-android:$VERSION'"
18 changes: 14 additions & 4 deletions kotlin/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Ignore Gradle project-specific cache directory
*.iml
.gradle

# Ignore Gradle build output directory
build
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties
6 changes: 6 additions & 0 deletions kotlin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id("com.android.application") version "8.3.0" apply false
id("com.android.library") version "8.3.0" apply false
id("org.jetbrains.kotlin.android") version "1.9.22" apply false
}
38 changes: 38 additions & 0 deletions kotlin/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash
set -e

echo "Building WalletKit Android SDK..."

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

# Build for all Android architectures
echo "Building for aarch64-linux-android..."
cross build -p walletkit --release --target=aarch64-linux-android

echo "Building for armv7-linux-androideabi..."
cross build -p walletkit --release --target=armv7-linux-androideabi

echo "Building for x86_64-linux-android..."
cross build -p walletkit --release --target=x86_64-linux-android

echo "Building for i686-linux-android..."
cross build -p walletkit --release --target=i686-linux-android

# 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

# Generate Kotlin bindings
echo "Generating Kotlin bindings..."
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

echo "✅ Build complete!"
2 changes: 2 additions & 0 deletions kotlin/lib/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/build
/src/main/java/uniffi/
5 changes: 1 addition & 4 deletions kotlin/lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@ plugins {

android {
namespace = "org.world.walletkit"
compileSdk = 33
compileSdk = 35

defaultConfig {
minSdk = 23

@Suppress("deprecation")
targetSdk = 33

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
}
Expand Down
2 changes: 2 additions & 0 deletions kotlin/lib/src/main/jniLibs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
14 changes: 14 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[toolchain]
channel = "1.91.0"
profile = "default"
components = ["rustfmt", "clippy", "rust-analyzer"]
targets = [
"aarch64-apple-ios-sim",
"aarch64-apple-ios",
"x86_64-apple-ios",
"x86_64-unknown-linux-gnu",
"aarch64-linux-android",
"armv7-linux-androideabi",
"x86_64-linux-android",
"i686-linux-android",
]