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 |
|
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 |
f38c0fd to
01bf6d4
Compare
|
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 ? |
|
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. |
alexanderwiederin
left a comment
There was a problem hiding this comment.
Thanks @Davidson-Souza. I've opened a PR (still in draft) for the nit in build.rs.
This looks ready to merge from my side.
@jaoleal @Davidson-Souza, given your context on the Android integration, I'll make sure to loop you in on any future issues or PRs touching this build path.
…eate a maven package 0777069 fix: add NDK_HOME and Boost sysroot symlink for Android cross-compilation (Davidson Souza) 4c24d16 ci: add boost installation for bitcoinkernel, restructure workflows (Davidson Souza) 06570c3 ci: add Android and Rust CI workflows (Davidson Souza) 8c4b661 feat: add Android library project with cross-compilation and maven publishing (Davidson Souza) Pull request description: ~~Depends on #10~~ Based on sedited/rust-bitcoinkernel#158 This PR adapts [bdk-ffi](https://github.com/bitcoindevkit/bdk-ffi)'s android builds for `floresta`. It builds both the `.so` and glue code for `Floresta` with gradle, so android applications can just use `floresta-android` as a maven dependency like any other. Top commit has no ACKs. Tree-SHA512: a8ba14022cec58520b8bf04af310dc286620c8afee4a81563a5e4d6c298f420619dbc8bb6e471879cfd326c9b6c5c77005e3ea2e75bd9b8cd8f148bcbbed82e5
|
Hey folks, ill address the suggestions. Just a thing about the last change, in order to make armv7 floresta target to work i had to patch it with // The pre-compiled libcompiler_builtins for armv7-linux-androideabi
// ships ARM EABI helper symbols tagged with @@LIBC_N (e.g.
// __aeabi_memcpy@@LIBC_N). When lld links a shared library or
// executable it errors because the LIBC_N version node is not
// defined in any version script. --exclude-libs,ALL marks every
// symbol pulled from static archives as local, which suppresses
// the version-node error.
if ndk_triple == "arm-linux-androideabi" {
println!("cargo:rustc-link-arg=-Wl,--exclude-libs,ALL");
} |
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.
|
Rebased |
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.
…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.
|
Okay, CHANGELOG:
|
|
Consuming the nix outputs look like this https://github.com/getfloresta/floresta-nix/pull/29/changes#diff-c765aab0783c96c0d736cf34b8b34bf38166bbfa04478db4391ce45e16d6b030R40-R42 |
alexanderwiederin
left a comment
There was a problem hiding this comment.
Nice - thanks for doing all this!
I had two smaller comments that build on my previous ones - they are mostly nits so feel free to ignore.
Regarding the manual setup and prebuilt LIBBITCOINKERNEL_LIB_DIR: Can we focus this PR only on supporting nix? The next PR could be focused on the manual setup instructions and include a CI job so we can continuously make sure it works manually. The third PR could focus on the the LIBBITCOINKERNEL_LIB_DIR proposal.
I appreciate your patience here, I know this has taken a while. I think breaking these three pieces down has a lot of value!
| nix build .#libbitcoinkernel-android-x86_64 # build only; tests skipped (see flake.nix) | ||
| ``` | ||
|
|
||
| The resulting libraries and headers are placed in `result/lib/` and `result/include. |
There was a problem hiding this comment.
Missing the closing "`" for result/include
| - name: Install Nix | ||
| uses: cachix/install-nix-action@v31 | ||
|
|
||
| - name: Build and Test |
There was a problem hiding this comment.
- name: Build${{ matrix.package != 'libbitcoinkernel-android-x86_64' && ' and Test' || '' }}
I agree with you, do you mind if i just cherry pick them out and open a pr so we can work on them later ? |
This pr contain 3 commits: