Feat: Android support#158
Conversation
|
This looks nice, can you rebase this? |
55272e4 to
378a3bc
Compare
|
Changelog:
|
a2c959f to
0f3252f
Compare
|
I reduced a lot the code and i think this is the concise version to support android |
|
|
alexanderwiederin
left a comment
There was a problem hiding this comment.
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?
Edit: see the comment below |
|
Correction, I changed my mind... The idea is that the |
479401e to
30f44a8
Compare
|
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 |
There was a problem hiding this comment.
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.
|
@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 |
|
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 :) |
d5724e1 to
32115fc
Compare
|
Ok, done. 32115fc Addressed suggestions:
cc @sedited take a look on https://github.com/sedited/rust-bitcoinkernel/actions/runs/26413972282/job/77754301637#step:4:6483 |
| let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap(); | ||
|
|
||
| if target_os == "android" { | ||
| let ndk = env::var("ANDROID_NDK_HOME") |
There was a problem hiding this comment.
We are fetching this twice. Any chance we can reuse this?
There was a problem hiding this comment.
How about we do the following in the outer scope:
let ndk = if is_android {
Some(env::var("ANDROID_NDK_HOME")
.expect("Android target detected but ANDROID_NDK_HOME is not set"))
} else {
None
};Then we can reuse it with .as_deref().unwrap() in the is_android blocks.
| ## [0.2.1] 2026-05-20 | ||
|
|
||
| ### Added | ||
| - Added Nix package outputs for Android with bundled NDK r27, Rust toolchains, Boost, and cmake. |
There was a problem hiding this comment.
This can be removed from the ## [0.2.1] 2026-05-20 section.
|
Applied @alexanderwiederin suggestions |
alexanderwiederin
left a comment
There was a problem hiding this comment.
Also reopened #158 (comment) which I think was not addressed.
|
Done, applied @alexanderwiederin suggestions |
alexanderwiederin
left a comment
There was a problem hiding this comment.
Thanks for the wait!
| let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap(); | ||
|
|
||
| if target_os == "android" { | ||
| let ndk = env::var("ANDROID_NDK_HOME") |
There was a problem hiding this comment.
How about we do the following in the outer scope:
let ndk = if is_android {
Some(env::var("ANDROID_NDK_HOME")
.expect("Android target detected but ANDROID_NDK_HOME is not set"))
} else {
None
};Then we can reuse it with .as_deref().unwrap() in the is_android blocks.
| ## [Unreleased] | ||
|
|
||
| ### Added | ||
| - Added Nix package outputs for Android with bundled NDK r24, Rust toolchains, Boost, and cmake. |
There was a problem hiding this comment.
Should this be r27? Judging by line 93 of flake.nix.
There was a problem hiding this comment.
No, i had the same doubt, If you check on flake.nix, youll see that we dont use ANDROID_API_LEVEL = "24"; directly in the build process itself but its still declared as a variable for one to alter if needed, it would reflect also altering
// API level 24+ is required because Bitcoin Core uses getifaddrs
// which was introduced in Android API 24 (Nougat).
//
// This can be overridden to a higher level by setting ANDROID_API_LEVEL.
let api_level = match env::var("ANDROID_API_LEVEL") {
Ok(level) => {
let n: u32 = level.parse().expect("ANDROID_API_LEVEL must be a number");
assert!(n >= 24, "ANDROID_API_LEVEL must be 24+");
level
}
_ => "24".to_string(),
};It appears that the API version is not the same number as the RELEASE version, the ndkVersion = "27.2.12479018"; that we use to declare the components release.
Ill add a comment clarifying that to avoid future confusion
| ## [0.2.1] 2026-05-20 | ||
|
|
||
| ### Added | ||
| - Added Nix package outputs for Android with bundled NDK r27, Rust toolchains, Boost, and cmake. |
There was a problem hiding this comment.
This should not be here.
|
Addressed @alexanderwiederin suggestions and fixes |
alexanderwiederin
left a comment
There was a problem hiding this comment.
Getting there! Could you update the PR description? I don't think it's a POC anymore. The PR also consists of four and not three commits.
Gosh, I entered in automatic mode for this one... Sorry |
This commit introduces build instructions for building the kernel targetting android. The instructions follows a design that is minimal, counting it will be executed in the nix environment which will be implemented in the next commits. We consciously made this decision; Nix runs on most systems where specific implementations would otherwise be necessary for each one. Nix helps keep these instructions minimal and reduces the chance of introducing bugs.
This commit introduces nix outputs in flake.nix that prepares the environment gathering dependencies that the Android build instructions needs and testing instructions. Testing android outputs is restricted to x86_64-linux and automatically triggered when the build process ends. QEMU user-mode emulation is configured as the Cargo test runner for cross-compiled Android targets.
|
Changelog:
|
|
Just a thing, since the android outputs can only be built with nix, I still didnt found a way to integrate it on floresta upstream so what im planning is to offer the compiled binaries on floresta-nix with the current patches presented here. I know that this is more a floresta problem but I think other projects, those depending on rust-bitcoinkernel as floresta does, may lead into the same problem and maybe a good solution would be if this project offered its own pre-compiled Android artifacts, what you guys think about it ? |
…LIB_DIR When the LIBBITCOINKERNEL_LIB_DIR environment variable is set, build.rs skips the CMake configure/build/install steps entirely and links against the pre-built static library at the given path. This follows the same pattern as openssl-sys with OPENSSL_LIB_DIR. This allows builders to pre-compile libbitcoinkernel separately and point the sys crate at the result, rather than needing adding patches to its projects.
|
Since yesterday I'm experimenting with this PR and integrating Floresta with Maven, so Android devs can consume Floresta as any other library. We already had some scaffolding in floresta-ffi but couldn't build I've opened getfloresta/floresta-ffi#11 fixing it, I can now build and run floresta with kernel enabled. Writing the main pain points here for reviewers and future reference. All my experiments did not use Nix. I've coded this on Arch Linux and Ci runs on Ubuntu.
a minor nit I've found when debugging this is that sometimes let install_output = Command::new("cmake")
.arg("--install")
.arg(&build_dir)
.arg("--config")
.arg(build_config)
.output()
.unwrap();
if !install_output.status.success() {
let stdout = String::from_utf8_lossy(&install_output.stdout);
let stderr = String::from_utf8_lossy(&install_output.stderr);
panic!(
"cmake --install failed with status {}.\nstdout:\n{}\nstderr:\n{}",
install_output.status, stdout, stderr
);
} |
|
Thanks for the report @Davidson-Souza! I hope we can get rid of boost soonish, there is some work happening towards that on the Bitcoin Core side. |
This pr contain 3 commits: