fix(android): cross-compile works on Windows hosts (#1508) - #1523
Merged
Conversation
Two independent bugs blocked `perry compile --target android` on Windows: 1. **Wrong NDK host tag.** Both `link/platform_cmd.rs:430` and `link/mod.rs:701` constructed the NDK toolchain path with a two-branch `cfg!` that fell through to `linux-x86_64` on Windows, pointing at a path that doesn't exist on the NDK (Windows ships `prebuilt/windows-x86_64/`). Linker failed with `Android NDK clang not found at: …/prebuilt/linux-x86_64/…` and the JNI stub compilation silently fell back to a broken binary. Add an explicit `cfg!(target_os = "windows")` branch in both files. 2. **Missing `android_cross_env`.** Unlike HarmonyOS — which calls `harmonyos_cross_env` at the two cargo-invocation sites (`optimized_libs.rs:565`, `link/mod.rs:1316`) — Android had no equivalent. cc-rs had nothing to point at when compiling native C deps (libsqlite3-sys, libmimalloc-sys) and bailed with `failed to find tool "clang.exe": program not found` on Windows and architecturally-mismatched objects on Unix. Add `android_cross_env(ndk_home, target) -> Vec<(K, V)>` in `library_search.rs` (mirroring `harmonyos_cross_env`), wire it into both cargo-invocation sites. Sets `CC_*` / `CXX_*` / `CARGO_TARGET_*_LINKER` to the NDK clang for the chosen target, using the host-aware tag from fix (1). On Windows the NDK ships `.cmd` wrapper scripts — append `.cmd` to the clang/clang++ names. Error message also updated to show Windows-style path next to the existing macOS/Linux examples. Closes #1508.
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.
Summary
Two independent bugs blocked
perry compile --target androidon Windows hosts.Bug 1 — wrong NDK host tag
link/platform_cmd.rs:430andlink/mod.rs:701both have a two-branchcfg!that fell through tolinux-x86_64on Windows. The NDK ships per-host prebuilt toolchains undertoolchains/llvm/prebuilt/<host>/, so the path didn't exist and the linker failed withAndroid NDK clang not found at: …/prebuilt/linux-x86_64/…. JNI stub compilation silently fell back viaunwrap_or(false)and produced a broken binary.Add explicit
cfg!(target_os = "windows") → "windows-x86_64"branches in both files.Bug 2 — missing
android_cross_envUnlike HarmonyOS (which calls
harmonyos_cross_envatoptimized_libs.rs:565+link/mod.rs:1316), Android had no equivalent. cc-rs had nothing to point at when compiling native C deps (libsqlite3-sys / libmimalloc-sys) and bailed withfailed to find tool "clang.exe"on Windows.Add
android_cross_env(ndk_home, target)inlibrary_search.rsmirroringharmonyos_cross_env. SetsCC_*/CXX_*/CARGO_TARGET_*_LINKERto the NDK clang for the chosen target, using the host-aware tag from fix (1). On Windows the NDK uses.cmdwrapper scripts — append.cmdto the clang/clang++ names.Bonus
Error message updated to include Windows-style path next to existing macOS/Linux examples.
Closes #1508.
Test plan
cargo build --release -p perrycleancargo test --release -p perry --bin perry(348 passed)cargo fmt --all -- --check