feat: support cross-compiling to aarch64-linux-android#5196
Draft
eval-exec wants to merge 1 commit intonervosnetwork:developfrom
Draft
feat: support cross-compiling to aarch64-linux-android#5196eval-exec wants to merge 1 commit intonervosnetwork:developfrom
eval-exec wants to merge 1 commit intonervosnetwork:developfrom
Conversation
Add a Nix flake providing a devShell that cross-compiles ckb for
aarch64-linux-android using the Android NDK 27 toolchain together with
rust-overlay (rustc 1.92.0 + aarch64-linux-android target).
Source changes:
- Extend the existing 'cfg(not(target_os = "windows"))' gates around
daemonization (daemonize-me, daemon subcommand, RunArgs.daemon field)
to also exclude target_os = "android" since daemonize-me does not
support Android.
Build/tooling:
- flake.nix: rust-overlay toolchain + pkgsCross.aarch64-android-prebuilt
NDK; HOST_* point at host gcc while CC/CXX point at the NDK so
rocksdb's build_detect_platform probes the *target* compiler and
skips x86 SSE flags; LIBCLANG_PATH and BINDGEN_EXTRA_CLANG_ARGS use
the NDK's bundled clang and the unwrapped sysroot so bindgen finds
Android headers; TARGET_OS/TARGET_ARCHITECTURE hint rocksdb's detect
script; a stub libgcc.a (INPUT(-lunwind)) is placed on the linker
search path because NDK 23+ removed libgcc but rustc still passes
-lgcc when targeting *-linux-android.
- .cargo/config.toml: add empty [target.aarch64-linux-android] stanza;
the linker is supplied by the shell environment.
- .gitignore: ignore .android-libgcc-stub/.
Build:
nix develop --command cargo build --release \
--target aarch64-linux-android --bin ckb
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What problem does this PR solve?
CKB has not been buildable for
aarch64-linux-android. Cross-compiling out of the box fails on:daemonize-me(referenced byckb-bin) does not supporttarget_os = "android"— itsFFIPasswdstruct is gated to linux/macos/freebsd/openbsd/netbsd only.ckb-librocksdb-sys'sbuild_detect_platformscript unconditionally adds x86 SSE/AVX/BMI/PCLMUL flags when the probing compiler accepts them, which breaks the NDK aarch64 clang during the C++ build.libgcc, butrustcstill passes-lgccto the linker when targeting*-linux-android.Problem Summary: provide a reproducible cross-compilation environment (Nix flake, NixOS-friendly) and the small source patches needed to actually build
ckbforaarch64-linux-android.What is changed and how it works?
What's Changed:
flake.nix(new): devShell wiring rust-overlay (rustc 1.92.0 +aarch64-linux-androidtarget) andpkgsCross.aarch64-android-prebuilt(Android NDK 27).HOST_CC/CXX/AR/LD/RANLIBpoint at host gcc/g++/ar/ld/ranlib so cargo build scripts that compile and link on the host work correctly.CC/CXX/AR/RANLIB/STRIPandCARGO_TARGET_AARCH64_LINUX_ANDROID_*point at the NDK toolchain so the target compiler is used for cross-compilation (and sobuild_detect_platform's SSE probes correctly fail on aarch64, skipping the x86 flags).LIBCLANG_PATHandBINDGEN_EXTRA_CLANG_ARGSuse the NDK's bundled clang-18 with the unwrapped sysroot so bindgen finds Android headers (uint32_t, etc.).TARGET_OS=OS_ANDROID_CROSSCOMPILEandTARGET_ARCHITECTURE=aarch64hint rocksdb's detect script.libgcc.acontainingINPUT(-lunwind)is generated and added to the Android linker search path viaCARGO_TARGET_AARCH64_LINUX_ANDROID_RUSTFLAGSto satisfy rustc's hardcoded-lgcc..cargo/config.toml: add empty[target.aarch64-linux-android]stanza; linker comes from the env vars set by the devShell..gitignore: ignore.android-libgcc-stub/.cfgchanges: extendcfg(not(target_os = "windows"))to also excludetarget_os = "android"for daemonization-related code, in:ckb-bin/Cargo.toml,ckb-bin/src/{lib.rs,setup.rs,cli.rs,subcommand/mod.rs}util/app-config/src/args.rs(thedaemonfield ofRunArgs)Build command:
Produces
target/aarch64-linux-android/release/ckb:Related changes
Check List
Tests
--release --bin ckbforaarch64-linux-androidfrom a NixOS x86_64 host usingnix develop; verified the resulting ELF isARM aarch64and dynamically linked against Android's/system/bin/linker64.Side effects
cfgexclusions fortarget_os = "android"(which was previously unbuildable) and a newflake.nix/.cargo/config.tomlstanza that only affects the new target.