Skip to content

fix(android): cross-compile works on Windows hosts (#1508) - #1523

Merged
proggeramlug merged 1 commit into
mainfrom
fix/1508-android-windows-host
May 23, 2026
Merged

fix(android): cross-compile works on Windows hosts (#1508)#1523
proggeramlug merged 1 commit into
mainfrom
fix/1508-android-windows-host

Conversation

@proggeramlug

Copy link
Copy Markdown
Contributor

Summary

Two independent bugs blocked perry compile --target android on Windows hosts.

Bug 1 — wrong NDK host tag

link/platform_cmd.rs:430 and link/mod.rs:701 both have a two-branch cfg! that fell through to linux-x86_64 on Windows. The NDK ships per-host prebuilt toolchains under toolchains/llvm/prebuilt/<host>/, so the path didn't exist and the linker failed with Android NDK clang not found at: …/prebuilt/linux-x86_64/…. JNI stub compilation silently fell back via unwrap_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_env

Unlike HarmonyOS (which calls harmonyos_cross_env at 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" on Windows.

Add android_cross_env(ndk_home, target) in library_search.rs mirroring harmonyos_cross_env. 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 uses .cmd wrapper scripts — append .cmd to 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 perry clean
  • cargo test --release -p perry --bin perry (348 passed)
  • cargo fmt --all -- --check
  • manual Windows / Linux / macOS cross-compile validation requires a Windows host — not covered in this PR (deferring to user-side verification)

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.
@proggeramlug
proggeramlug merged commit df53c0f into main May 23, 2026
9 checks passed
@proggeramlug
proggeramlug deleted the fix/1508-android-windows-host branch May 23, 2026 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: Android cross-compilation fails on Windows host due to hardcoded linux-x86_64 NDK path

1 participant