Skip to content

Feat: Android support#158

Open
jaoleal wants to merge 4 commits into
sedited:masterfrom
jaoleal:android_support
Open

Feat: Android support#158
jaoleal wants to merge 4 commits into
sedited:masterfrom
jaoleal:android_support

Conversation

@jaoleal
Copy link
Copy Markdown
Contributor

@jaoleal jaoleal commented Apr 10, 2026

This pr contain 3 commits:

  1. an old version of Add MSRV Cargo-minimal.lock and Cargo-recent.lock files #150 to make CI work again flawlessly.
  2. A patch to the projects flake adding a nix-shell that give us the necessary setup for the android build, which includes the android toolchain and some environment variables. The second commit also introduces a new job on the CI that executes the building for android.
  3. Android building instructions for build.rs

This is just a PoC, the main commit is the third one and the CI job containing the android building at that point should run fine.
For more context read #156

@jaoleal jaoleal mentioned this pull request Apr 10, 2026
@sedited
Copy link
Copy Markdown
Owner

sedited commented Apr 23, 2026

This looks nice, can you rebase this?

@jaoleal
Copy link
Copy Markdown
Contributor Author

jaoleal commented Apr 30, 2026

Changelog:

@jaoleal jaoleal force-pushed the android_support branch 6 times, most recently from a2c959f to 0f3252f Compare May 6, 2026 20:07
@jaoleal jaoleal changed the title POC: Android support Feat: Android support May 6, 2026
@jaoleal jaoleal marked this pull request as ready for review May 6, 2026 20:08
@jaoleal
Copy link
Copy Markdown
Contributor Author

jaoleal commented May 6, 2026

I reduced a lot the code and i think this is the concise version to support android

@alexanderwiederin
Copy link
Copy Markdown
Collaborator

alexanderwiederin commented May 7, 2026

I don't think android is a supported target for libbitcoinkernel. Doesn't this require upstream work on bitcoin core first?

Copy link
Copy Markdown
Collaborator

@alexanderwiederin alexanderwiederin left a comment

Choose a reason for hiding this comment

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

From what I understand the ubuntu boost packages don't ship with the cmake config that core needs when cross-compiling.

Am I right that you got it working on nix locally? If so, can we stick with with only supporting the nix build for android?

Comment thread flake.nix Outdated
Comment thread flake.nix Outdated
@jaoleal
Copy link
Copy Markdown
Contributor Author

jaoleal commented May 7, 2026

Am I right that you got it working on nix locally? If so, can we stick with with only supporting the nix build for android?

Yes, i worked all this on nix but Im not sure about leaving android building exclusively for nix, this would make it a direct dependency of the project and its not something really special that only nix can do. Besides the dependency problem, nix can drift versions because of nixpkgs releases and that can raise problems only by itself.

Therefore, i still would like for CI to keep the runner as ubuntu. Its easier for the general developer audience to replicate the build on their machine if they need

Edit: see the comment below

@jaoleal
Copy link
Copy Markdown
Contributor Author

jaoleal commented May 7, 2026

Correction, I changed my mind... The idea is that the build.rs file is already bloated because of the android support additions, adding support for ubuntu bloated it even more... It looks like leaving to nix to cross-compile to android is actually a good choice, the changes stay minimal on build.rs side and it have broader support running on linux and macos machines... Ill make sure to document that somewhere and state how to make the android build.

@jaoleal jaoleal force-pushed the android_support branch 5 times, most recently from 479401e to 30f44a8 Compare May 8, 2026 00:24
@jaoleal
Copy link
Copy Markdown
Contributor Author

jaoleal commented May 8, 2026

Okay the android build being exclusive for nix made things easier for this PR, the changes on build.rs are minimal... I included some inline doc comments so the reviewer can follow why each line were added.

I added a section on the readme explaining the android build but its not that explanatory in a level that one can learn how to build this lib to android, do you guys think thats needed ?

I can extend the docs to include instructions for one to reproduce it on a downstream build.rs, just tell me where to put it.
AFAIK is trivial for those using Kotlin, as mandacaru is using, to pull an already compiled shared object during build time. Thats what ill do on floresta-nix for mandacaru, ideally the CI would also offer the compiled objects too for those who might need it.

Copy link
Copy Markdown
Collaborator

@alexanderwiederin alexanderwiederin left a comment

Choose a reason for hiding this comment

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

Great to see this working.

If we land the hand-written bindings PR (#163) first, the changes in build.rs should become simpler. I would suggest we wait for it.

Comment thread libbitcoinkernel-sys/build.rs Outdated
Comment thread libbitcoinkernel-sys/build.rs
Comment thread flake.nix Outdated
Comment thread flake.nix Outdated
Comment thread flake.nix Outdated
Comment thread flake.nix Outdated
Comment thread .github/workflows/ci.yml
Comment thread README.md Outdated
Comment thread README.md
@sedited
Copy link
Copy Markdown
Owner

sedited commented May 20, 2026

@jaoleal I'm interested in getting this change through. Can you rebase it and address Alex' comments?

@jaoleal
Copy link
Copy Markdown
Contributor Author

jaoleal commented May 20, 2026

@jaoleal I'm interested in getting this change through. Can you rebase it and address Alex' comments?

Yes, sorry for taking long... I was waiting for the bindgen pr to be merged so we had sure what that would imply here without rebasing on a pr

@alexanderwiederin alexanderwiederin linked an issue May 22, 2026 that may be closed by this pull request
@jaoleal jaoleal force-pushed the android_support branch 4 times, most recently from f1fed04 to 5387332 Compare May 23, 2026 14:40
@jaoleal
Copy link
Copy Markdown
Contributor Author

jaoleal commented May 23, 2026

Addressed suggestions @sedited @alexanderwiederin

@jaoleal jaoleal force-pushed the android_support branch from 5387332 to d898366 Compare May 23, 2026 21:24
Comment thread flake.nix Outdated
Comment thread CHANGELOG.md
## [0.2.1] 2026-05-20

### Added
- Added Nix package outputs for Android with bundled NDK r27, Rust toolchains, Boost, and cmake.
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This needs to go in a new ###Added entry in the unreleased section.

@sedited
Copy link
Copy Markdown
Owner

sedited commented May 25, 2026

@jaoleal how are you testing the build artifacts? Are you running the tests in some emulated environment, or do you just link the kernel crate into an existing project and observe that there are no failures?

@jaoleal
Copy link
Copy Markdown
Contributor Author

jaoleal commented May 25, 2026

@jaoleal how are you testing the build artifacts? Are you running the tests in some emulated environment, or do you just link the kernel crate into an existing project and observe that there are no failures?

None of these, I got satisfied by the build succeeding since testing this can be tricky... Are you looking into CI tests for this ?

But youre correct, we should be testing the outputs.

Testing it using floresta will be hard but ill look into it.

@sedited
Copy link
Copy Markdown
Owner

sedited commented May 25, 2026

Ah, I thought this was intended for eventual floresta integration. Or what was your motivation for working on it?

@jaoleal
Copy link
Copy Markdown
Contributor Author

jaoleal commented May 25, 2026

Ah, I thought this was intended for eventual floresta integration. Or what was your motivation for working on it?

Well, yes, im fixing a "floresta-issue" here but allow me to expose the whole picture.

Floresta uses bitcoin-kernel only for script validation, whitout the bitcoin-kernel feature, floresta just skips script validation.

Mandacaru, basically a port of floresta to android, needs floresta running on android, and is currently skipping script validation.

To test this using floresta i would need to: 1. Make floresta use this current android_support branch. 2. Build a binary and ship it to Mandacaru. 3. Build Mandacu, run it on android and perform full sync.

And this would not result in a satisfatory test because floresta would only exercise script validation. Too hard for basically useless results.

AFAIK the best solution to be sure that bitcoin-kernel is indeed working on android is by adding a test in CI running inside an emulated environment, ill push it and lets see how it goes

@sedited
Copy link
Copy Markdown
Owner

sedited commented May 25, 2026

I'm also fine with just leaving it be for now and handling that in a follow-up pull request. Having something link is already a good assurance :)

jaoleal added 3 commits May 25, 2026 14:08
Build instructions for targeting android expecting it to be
executed in nix

move internal changelog to unreleased
Outputs and environment setup for building android.

move nix changelog to unreleased
@jaoleal jaoleal force-pushed the android_support branch 2 times, most recently from 9eb3d5c to d5724e1 Compare May 25, 2026 17:28
This commit introduces preparation for testing in both Nix and CI.

Testing android outputs is restricted to x86_64-linux machines for
simplicity. QEMU user-mode emulation is configured as the Cargo test
runner for cross-compiled Android targets.

fix formatting
@jaoleal jaoleal force-pushed the android_support branch from d5724e1 to 32115fc Compare May 25, 2026 18:14
@jaoleal
Copy link
Copy Markdown
Contributor Author

jaoleal commented May 25, 2026

Ok, done.

32115fc Addressed suggestions:

  • Moved changelog edits to unreleased section.
  • Added tests for the android outputs.
  • fixed formatting on string literals

cc @sedited take a look on https://github.com/sedited/rust-bitcoinkernel/actions/runs/26413972282/job/77754301637#step:4:6483

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.

ci: add cross-compilation job for 32-bit/Android targets

3 participants