Add Android packaging: xtask build-android-* emit the C FFI as an NDK cdylib - #17
Add Android packaging: xtask build-android-* emit the C FFI as an NDK cdylib#17meinharrd wants to merge 3 commits into
Conversation
… cdylib freedom-browser-android consumes the same C ABI as iOS (ffi/include/freedom_ipfs.h) but as a shared library loaded via a JNI shim in the app, so packaging is a per-ABI libfreedom_ipfs_mobile.so instead of the xcframework. - xtask build-android-arm64 / build-android-x86_64 / build-android-all cross-compile freedom-ipfs-mobile with cargo-ndk (API 26). The crate-type is overridden to cdylib per-build via cargo rustc, so Cargo.toml keeps rlib+staticlib for the iOS and desktop slices, and the .so is linked with max-page-size=16384 for 16 KB-page Android 15+ devices regardless of cargo-ndk/NDK defaults. - Matching make build-android-* targets and a README packaging section. No library-code changes were needed: all production name-resolution paths already avoid /etc/resolv.conf (absent on Android) — DNSLink/ IPNS use Cloudflare DoH, the libp2p DNS transports pin ResolverConfig::cloudflare() instead of system config, and plain HTTP resolves via getaddrinfo. Closes #16
|
Review notes — no correctness bugs found (the cargo-ndk invocation shape, the
Minor, non-blocking: the artifact check hardcodes |
…lap attr - build_android and build_xcframework's rustup/cargo invocations now go through the existing run() helper instead of hand-rolling spawn/status/bail. - The 16 KB max-page-size link flag moves from a per-invocation rustc arg to target-scoped rustflags in .cargo/config.toml, so build paths that bypass xtask (direct cargo-ndk, CI) also emit Android 15+ compliant artifacts. cargo-ndk sets the linker via CARGO_TARGET_<T>_LINKER, so the two compose. - Drop the redundant #[command(name)] on BuildAndroidArm64 — clap's kebab-case default already produces build-android-arm64; only the x86_64 variant needs the explicit name. Re-verified after the rustflags move: both ABIs rebuild with all 45 freedom_ipfs_* symbols and 0x4000 LOAD alignment.
|
All three items addressed in 34df282:
Since moving rustflags invalidates the build cache, both ABIs were rebuilt from scratch to re-verify: 45 |
ReviewOverviewAdds Correctness
Main risk: the page-size flag can be silently droppedTarget-scoped Suggestion: have Test coverage / CI
Minor points
Security
VerdictSolid, well-scoped PR that follows the repo's xtask/Makefile/README conventions, with unusually thorough verification notes. The one change I'd request before merge is the post-build 16 KB-alignment check (or at minimum documenting the |
RUSTFLAGS / CARGO_ENCODED_RUSTFLAGS in the environment silently replace the target rustflags in .cargo/config.toml, which would drop the max-page-size link-arg and produce a .so that only fails at app runtime on 16 KB-page Android 15+ hardware. build_android now parses the ELF program headers of the built artifact (no external tool needed) and fails the build when any LOAD segment aligns below 0x4000; unit tests cover the parser and both verdicts on synthetic ELFs. The config.toml comment and README now state the env-override caveat instead of claiming clean composition, plus the review's cosmetic nits: stderr/stdout separator in the cargo-ndk error and 'NDK release r26 or newer' wording to disambiguate from API level 26.
|
Requested change addressed in 3dd26f8 — Also in the same commit: the For the CI follow-up I'll note it on #16 so it isn't lost. |
flotob
left a comment
There was a problem hiding this comment.
One correctness issue remains in the Android packaging path. Otherwise the latest head looks sound, including the 16 KB ELF alignment verification.
Validation performed:
cargo test --workspace: passedcargo test -p xtask: 8 passedcargo fmt --all -- --check: passedcargo clippy -p xtask --all-targets -- -D warnings: passed- GitHub iOS XCFramework workflow: passed
I could not independently rerun the Android cross-build because cargo-ndk/NDK is not installed locally.
| &format!("cargo ndk -t {target}"), | ||
| )?; | ||
|
|
||
| let lib = PathBuf::from("target") |
There was a problem hiding this comment.
[P2] Respect Cargo's configured target directory
This hardcodes target/<triple>/release/..., although Cargo may write the artifact beneath CARGO_TARGET_DIR or [build] target-dir. It also fails when xtask is launched from a workspace subdirectory: Cargo finds the workspace and builds successfully, but this relative lookup checks the caller's directory and then incorrectly reports the .so missing. Please resolve Cargo's target_directory (for example through cargo metadata) or pass an explicit absolute --target-dir to cargo-ndk.
Implements #16 — the Android export freedom-browser-android needs to swap its embedded Kubo node for freedom-ipfs (solardev-xyz/freedom-browser-android#3).
What
cargo xtask build-android-arm64/build-android-x86_64/build-android-allcross-compilefreedom-ipfs-mobilewith cargo-ndk at API 26, producingtarget/<triple>/release/libfreedom_ipfs_mobile.soper ABI. Matchingmake build-android-*targets and a README packaging section.cargo rustc --crate-type cdylib(ant's pattern), soCargo.tomlkeepsrlib + staticlibfor the iOS/desktop slices and only the.sois emitted for Android.-Wl,-z,max-page-size=16384so the artifact loads on 16 KB-page Android 15+ devices regardless of cargo-ndk/NDK defaults.DNS audit (Android has no /etc/resolv.conf)
No library changes needed — every production resolution path already avoids system DNS config:
ResolverConfig::cloudflare()pinned explicitly, neverfrom_system_confgetaddrinfo, which bionic backsThe
resolv-confcrate remains in the lockfile only as an unexercised transitive dep of hickory-resolver.Verification
Built on Linux x86_64 with NDK r27 + cargo-ndk 4.1.2, both ABIs:
.soper ABIfreedom_ipfs_*symbols fromffi/include/freedom_ipfs.hexported (llvm-nm -D --defined-only)llvm-readelf -l)The JNI shim intentionally stays in the consumer (freedom-browser-android), mirroring the ant split: this repo owns the C ABI + header, the app owns
*_jni.c.