Skip to content

radixdlt/sargon

Repository files navigation

Sargon

Rust Kotlin Swift Average
Rust Kotlin Swift Average

Sargon is library for sharing code between Radix iOS/Android wallets.

Important

This library is intended for internal use only in the official iOS and Android wallets. Interfaces will be changing regularly, and we do not recommend other developers integrate the library or align with these standards.

Etymology

Named after Sargon of Akkad the first ruler of the Akkadian Empire, the first empire of Mesopotamia. Babylon was a city in southern Mesopotamia, and of course the name of the Radix milestone with which the Radix wallets was launched.

Development

Setup

We recommend installing the Radix Transaction Manifest Extension for VS Code if you use that IDE

Snippets

For VS Code IDE users, we recommend installing the Rust snippet vendored with this repo:

./scripts/install_snippets.sh

Swift

xcode-select --install

Or install Xcode from App Store

Kotlin

brew install kotlin

pre-commit

Recommended to use pre-commit tool

brew install pre-commit

This repo contains a .pre-commit-config.yaml which uses the amazing typos tool, you MUST INSTALL the config, do it by:

pre-commit install

nextest

Nextest is a nice test runner for Rust!

cargo install cargo-nextest

Code coverage

Recommended to use tarpaulin tool for code coverage:

cargo install cargo-tarpaulin

And then run:

cargo tarpaulin --out Html

Run Tests

cargo nextest run

Build local

iOS

Prerequisites

Rust targets for iOS

rustup target add aarch64-apple-ios aarch64-apple-ios-sim

Rust targets (macOS)

rustup target add aarch64-apple-darwin

Build

Find script here

./scripts/ios/build-ios.sh

Test Swift

Find script here

Code coverage

Details

./scripts/ios/test.sh

Summary

./scripts/ios/test.sh --summary

Test only

./scripts/ios/test.sh --testonly

Export code coverage

If you change lcov format in export_code.cov.sh please use an updated file name.

./scripts/ios/test.sh --codecov swift_code_cov.lcov

Alternatively if you wanna skip code cove

Android

Prerequisites

Install jenv

brew install jenv

Dont forget to add to eval to zsh

export PATH="$HOME/.jenv/bin:$PATH"
eval "$(jenv init -)"

(or similar)

Install Java (openjdk@17)

brew install openjdk@17

Add openjdk version to jenv

jenv add /opt/homebrew/Cellar/openjdk@17/17.0.10/libexec/openjdk.jdk/Contents/Home/

(or similar)

ktlint

brew install ktlint

cargo-ndk

cargo install cargo-ndk

Rust targets (Android)

rustup target add aarch64-linux-android armv7-linux-androideabi

Rust targets (Desktop Binaries)

rustup target add aarch64-apple-darwin

NDK

Download the latest NDK from android studio

Then make sure that you have added these in your path

export ANDROID_HOME=<path-to-your-sdk>
export ANDROID_NDK_HOME=$ANDROID_HOME/ndk/<version>

# Make sure to also include the SDK ROOT in order to build the mac os desktop binaries
export SDKROOT="`xcrun --show-sdk-path`"

Then you can build both libraries as a usual

cd jvm

# For android library (Debug)
./gradlew sargon-android:assembleDebug
# For android library (Release)
./gradlew sargon-android:assembleRelease

# For desktop binaries
./gradlew sargon-desktop-bins:assemble

Test JVM

./jvm/gradlew -p jvm/sargon-android testDebugUnitTest

Release

iOS

Locally

Prerequisites

Important

You will need the prerequisites of Build local above.

Install gh
brew install gh
Github PAT

Create a Github Personal Access Token (PAT) labeled "Classic" and give it these permissions: write:packages admin:org -> read:org

Manually release

For the first time, you must:

gh auth login

Do this:

? What account do you want to log into? GitHub.com
? What is your preferred protocol for Git operations on this host? SSH
? Upload your SSH public key to your GitHub account? Skip
? How would you like to authenticate GitHub CLI? Paste an authentication token
Tip: you can generate a Personal Access Token here https://github.com/settings/tokens
The minimum required scopes are 'repo', 'read:org'.
? Paste your authentication token: ****************************************

If successful you should see:

- gh config set -h github.com git_protocol ssh
✓ Configured git protocol
✓ Logged in as <YOUR_GH_USERNAME>

Find script here

./scripts/ios/release.sh

CD

See .github/workflows/release.yml

Android

Two modules are published in Github's maven.

  • sargon-android

    (See .github/workflows/release-android.yml)

    Contains the generated UniFFi Kotlin code and the runtime sargon binaries, in different architectures. It also contains the JNA dependency.

    Import with:

    implementation("com.radixdlt.sargon:sargon-android:<version>")
    
  • sargon-desktop-bins

    (See .github/workflows/release-desktop-bins.yml)

    Contains only the runtime sargon binaries, built for desktop. Used when running Unit tests.

    Import with:

    testRuntimeOnly("com.radixdlt.sargon:sargon-desktop-bins:<version>")
    

Important

Currently only supporting aarch64-apple-darwin (apple silicon). So when running Unit tests for your client app, make sure to run them on an apple silicon machine. In the future we will try to add more target architectures.

Example apps

iOS

See iOS example app in examples/iOS

Android

Import the /jvm directory in Android Studio and run the app configuration.