Android Support
Mandacaru is a Bitcoin validator node powered by Floresta, a Bitcoin node implementation that exports its components and uses rust-bitcoinkernel for script validation.
Recently, jvsena42 (the maintainer of Mandacaru) opened an issue in Floresta reporting that cross-compilation for Android is blocked because the build script libbitcoinkernel-sys/build.rs offers no mechanism for building against Android targets.
My excitement about finally running Floresta (or at least its components) on my phone made me spend some time to see what I could do to address this.
The current state:
The build script has three gaps when targeting Android:
- No Android target detection. There's no conditional path for Android, so CMake never receives the NDK toolchain.
- Bindgen misconfiguration. Without the NDK sysroot and correct target triple, bindgen parses host headers and produces the incorect bindings.
- Wrong C++ standard library. The script links to the host's
libstdc++, but Android have its own, libc++_static and libc++abi which is shipped by the NDK.
Why should rust-bitcoinkernel care about Android?
The bindings and conformance with Bitcoin Core's validation engine that this library exports are fundamental to the Rust Bitcoin ecosystem. Serious projects like Floresta depend on it.
Lacking Android support here is a real problem for us in Floresta. Our components are designed with constrained devices in mind, and apps like Mandacaru that build on top of them are left with two bad options:
- Work around it by vendoring or patching out-of-tree code — potentially exposing the app to unreviewed code and forcing trade-offs that degrade its purpose.
- Disable the validation engine entirely — which is worse.
That said, i guess the most elegant and secure solution for that is about writing Android support for this project.
Proposed solution
Instruct build.rs to detect Android targets and handle the issues stated above: configure CMake with the NDK toolchain, point bindgen at the right sysroot and headers, and link it to the NDK's C++ runtime.
Ill push a draft PR addressing this, not with the intention for it to be imediatly merged but for us to have a more tangible discussion over this. The patch will also include a patch to the Nix flake that I used to set up the build environment and verify compilation across android-aarch64, android-armv7, and android-x86_64 — not required for the feature itself, just how I validated it. (I use nixos btw)
edit: #158
Android Support
Mandacaru is a Bitcoin validator node powered by Floresta, a Bitcoin node implementation that exports its components and uses rust-bitcoinkernel for script validation.
Recently, jvsena42 (the maintainer of Mandacaru) opened an issue in Floresta reporting that cross-compilation for Android is blocked because the build script
libbitcoinkernel-sys/build.rsoffers no mechanism for building against Android targets.My excitement about finally running Floresta (or at least its components) on my phone made me spend some time to see what I could do to address this.
The current state:
The build script has three gaps when targeting Android:
libstdc++, but Android have its own,libc++_staticandlibc++abiwhich is shipped by the NDK.Why should rust-bitcoinkernel care about Android?
The bindings and conformance with Bitcoin Core's validation engine that this library exports are fundamental to the Rust Bitcoin ecosystem. Serious projects like Floresta depend on it.
Lacking Android support here is a real problem for us in Floresta. Our components are designed with constrained devices in mind, and apps like Mandacaru that build on top of them are left with two bad options:
That said, i guess the most elegant and secure solution for that is about writing Android support for this project.
Proposed solution
Instruct
build.rsto detect Android targets and handle the issues stated above: configure CMake with the NDK toolchain, point bindgen at the right sysroot and headers, and link it to the NDK's C++ runtime.Ill push a draft PR addressing this, not with the intention for it to be imediatly merged but for us to have a more tangible discussion over this. The patch will also include a patch to the Nix flake that I used to set up the build environment and verify compilation across
android-aarch64,android-armv7, andandroid-x86_64— not required for the feature itself, just how I validated it. (I use nixos btw)edit: #158