Skip to content

chore: replace android cross-rs cross compilation setup with a nix based one#434

Open
Dzejkop wants to merge 34 commits into
mainfrom
nix/android-devshell
Open

chore: replace android cross-rs cross compilation setup with a nix based one#434
Dzejkop wants to merge 34 commits into
mainfrom
nix/android-devshell

Conversation

@Dzejkop

@Dzejkop Dzejkop commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Rationale

The Android build requires nargo as a build-time host tool. cross-rs uses target-specific Docker images and may execute target binaries under emulation—for example, its i686-linux-android image uses an i386 QEMU runner. Noir does not publish nargo binaries for these emulated target environments, so we cannot reliably provision it inside the cross-rs build flow.

This PR replaces cross-rs with Nix-based cross-compilation. Cargo and nargo now run on the host architecture, where an official nargo binary is available, while the pinned Android NDK cross-compiles the native library for each Android target.

Changes

  • Adds pinned Nix development shells for Android, wasm, and general Rust development.
  • Packages the official nargo binaries for supported host platforms.
  • Replaces the Android release workflow's cross-rs builds with Nix/NDK builds for:
    • aarch64-linux-android
    • armv7-linux-androideabi
    • x86_64-linux-android
    • i686-linux-android
  • Consolidates local and CI Kotlin assembly through kotlin/build_kotlin.sh.
  • Adds a Docker-based Nix CLI proxy for contributors without Nix. It uses linux/amd64 because the Android NDK does not provide an aarch64-linux host toolchain.
  • Leaves the Swift release flow on its existing macOS/Xcode host toolchain.

Validation

  • All four Android native targets built successfully in the temporary branch workflow: https://github.com/worldcoin/walletkit/actions/runs/29082146903
  • Verified the Android devshell provides the pinned Rust toolchain, NDK/linkers, nargo, and JDK 17.
  • Verified the release workflow retains publishing behavior while using the Nix Android build path.

Note

Medium Risk
This changes how release Android .so artifacts are produced; Swift is untouched, but a toolchain regression would affect published Kotlin packages until caught in CI.

Overview
Replaces cross-rs Android builds with Nix devshells so cargo and nargo run on the host while a pinned NDK r27 cross-compiles all four Android targets—addressing missing nargo binaries inside cross’s emulated target images.

Adds a flake (default, android, wasm shells), repackaged nargo, helpers (nix/build-android.sh, nix/docker.sh), and docs in nix/README.md. Cross.toml is removed; Android link flags stay in .cargo/config.toml.

Release workflow (prepare-kotlin / publish-kotlin) now installs Nix, caches Cargo artifacts, builds via ./nix/build-android.sh, and assembles JNI + UniFFI through kotlin/build_kotlin.sh --artifacts-dir. Swift release steps stay on macOS/Xcode; GitHub Actions are pinned to commit SHAs.

kotlin/build_kotlin.sh is unified for local and CI (plain cargo build, optional prebuilt .so layout). README and local_kotlin.sh drop Docker/cross prerequisites in favor of nix develop .#android.

Reviewed by Cursor Bugbot for commit f5bfdb4. Bugbot is set up for automated code reviews on this repo. Configure here.

@Dzejkop Dzejkop self-assigned this Jun 24, 2026
Comment thread .github/workflows/build-kotlin-nix.yml Outdated
Comment thread .github/workflows/build-kotlin-nix.yml Outdated
Comment thread .github/workflows/build-kotlin-nix.yml Outdated
Comment thread .github/workflows/build-kotlin-nix.yml Outdated
@semgrep-code-worldcoin

Copy link
Copy Markdown

Semgrep found 10 github-actions-mutable-action-tag findings:

GitHub Actions step uses a mutable tag or branch reference. Tags and branch names can be silently repointed by the action owner, enabling supply-chain attacks — as seen in the trivy-action and kics-github-action compromises. Pin the reference to a full 40-character commit SHA instead, e.g. uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608.

Comment thread .github/workflows/build-kotlin-nix.yml Outdated
Comment thread .github/workflows/build-kotlin-nix.yml Outdated
Comment thread .github/workflows/build-kotlin-nix.yml Outdated
Comment thread .github/workflows/build-kotlin-nix.yml Outdated
Comment thread .github/workflows/build-kotlin-nix.yml Outdated
Comment thread .github/workflows/build-swift-nix.yml Outdated
Comment thread .github/workflows/build-swift-nix.yml Outdated
Comment thread .github/workflows/build-swift-nix.yml Outdated
Comment thread .github/workflows/build-swift-nix.yml Outdated
Comment thread .github/workflows/build-swift-nix.yml Outdated
Comment thread .github/workflows/build-swift-nix.yml Outdated
Comment thread .github/workflows/build-swift-nix.yml Outdated
Comment thread .github/workflows/build-kotlin-nix.yml Outdated
Comment thread .github/workflows/release-swift-kotlin.yml Outdated
@Dzejkop Dzejkop marked this pull request as ready for review July 10, 2026 09:54
@Dzejkop Dzejkop changed the title WIP: Nix/android devshell chore: replace android cross-rs cross compilation setup with a nix based one Jul 10, 2026
@Dzejkop Dzejkop force-pushed the nix/android-devshell branch from 412fce6 to 08ecd8d Compare July 10, 2026 14:45
Dzejkop and others added 27 commits July 13, 2026 15:24
… brittle NDK paths

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…r swift build

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…evshells

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…cit unsupported-platform error

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
nix's apple-sdk hook overwrites DEVELOPER_DIR inside the shell, so the
pin moves to WALLETKIT_DEVELOPER_DIR; an invalid pin now aborts the
shell, and CI asserts the xcodebuild version.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…oid shell to NDK-supported systems

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
nix/build-android.sh handles per-target matrix builds and
kotlin/build_kotlin.sh (new --artifacts-dir flag) assembles jniLibs and
generates bindings, instead of inlining both in each workflow.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-authored-by: Jakub Trąd <jakubtrad@gmail.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant