joltc-sys: native Android cross-compile + host-vs-target /EHsc fix#12
Merged
LPGhatguy merged 2 commits intoMay 11, 2026
Conversation
Two coupled bugs surfaced when cross-compiling joltc-sys to
Android (aarch64-linux-android via NDK r26d clang from a Windows
host):
1. `cfg!(windows)` is a HOST-OS check inside build.rs. When
targeting Android from Windows, the conditional always fires
and adds the MSVC-only `/EHsc` flag to the cmake config — NDK
clang then receives `/EHsc` as a path argument and errors out
("error: no such file or directory: '/EHsc'").
Fix: read `CARGO_CFG_TARGET_OS` and only add `/EHsc` when the
actual target is windows.
2. Building for Android requires three CMake-side hints that
joltc-sys does not currently set: `CMAKE_TOOLCHAIN_FILE`
(NDK's `android.toolchain.cmake`), `ANDROID_ABI` (string the
toolchain reads — env var alone is ignored), and the
generator (Ninja, since cmake-rs defaults to MSBuild on
Windows hosts).
Fix: when `target_os == "android"`, derive ANDROID_ABI from
`CARGO_CFG_TARGET_ARCH` (aarch64 → arm64-v8a, arm →
armeabi-v7a, etc.), look up the NDK at
`ANDROID_NDK_HOME` / `ANDROID_NDK_ROOT` / `ANDROID_NDK`,
and force Ninja.
End-user contract after this change: set ANDROID_NDK_HOME,
run `cargo ndk --target aarch64-linux-android check -p joltc-sys`.
The standard cargo-ndk + nttld/setup-ndk@v1 flow Just Works.
Validated locally on Windows-host → aarch64-linux-android with
NDK r26d (full JoltPhysics + JoltC compiles in ~20s). 32-bit ARM
(armv7-linux-androideabi) hits an unrelated upstream JoltC
LAYOUT_COMPATIBLE static_assert (`JPC_*Settings` 16-byte
alignment vs `JPH::*Settings` 8-byte alignment on 32-bit ARM)
that this PR does not address.
Solidor777
added a commit
to Solidor777/Titan
that referenced
this pull request
May 8, 2026
Upstream PR for the joltc-sys/build.rs Android cross-compile + host-vs-target /EHsc fix now has a URL: SecondHalfGames/jolt-rust#12. Cross-referenced from docs/VENDORING.md "Local patches" and docs/TODO.md so future syncs find the trigger. Pairs with SecondHalfGames/JoltC#23 (the SetGravity export PR opened earlier today). Both are independent; either can merge first. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Contributor
Author
|
Status update: the armv7 / 32-bit-ARM follow-up I mentioned ( With both PRs applied, No code change needed on this PR — just a heads-up that the "track separately" item has a fix. |
Solidor777
added a commit
to Solidor777/Titan
that referenced
this pull request
May 17, 2026
Upstream PR for the joltc-sys/build.rs Android cross-compile + host-vs-target /EHsc fix now has a URL: SecondHalfGames/jolt-rust#12. Cross-referenced from docs/VENDORING.md "Local patches" and docs/TODO.md so future syncs find the trigger. Pairs with SecondHalfGames/JoltC#23 (the SetGravity export PR opened earlier today). Both are independent; either can merge first. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Solidor777
added a commit
to Solidor777/Titan
that referenced
this pull request
Jun 4, 2026
Upstream PR for the joltc-sys/build.rs Android cross-compile + host-vs-target /EHsc fix now has a URL: SecondHalfGames/jolt-rust#12. Cross-referenced from docs/VENDORING.md "Local patches" and docs/TODO.md so future syncs find the trigger. Pairs with SecondHalfGames/JoltC#23 (the SetGravity export PR opened earlier today). Both are independent; either can merge first. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.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.
Summary
Two coupled bugs surfaced while cross-compiling
joltc-systo Android (aarch64-linux-android via NDK r26d clang from a Windows host).1.
cfg!(windows)is a HOST-OS check, not a target-OS checkbuild.rsruns on the host. When the host is Windows and the target is Android, the existingif cfg!(windows) { config.cxxflag("/EHsc"); }unconditionally appends the MSVC-only/EHscflag. NDK clang then receives/EHscas a path argument and errors withno such file or directory: '/EHsc'.Fix: read
CARGO_CFG_TARGET_OSand gate/EHscon the actual target.2. Native Android cross-compile setup is missing
Building for Android via the standard
cargo ndk --target <android-triple> check -p joltc-sysflow currently fails becausejoltc-sysdoes not set:CMAKE_TOOLCHAIN_FILE(NDK'sbuild/cmake/android.toolchain.cmake).ANDROID_ABI(the toolchain reads it as a CMake-Dvariable; env var is ignored).Fix: when
target_os == "android", deriveANDROID_ABIfromCARGO_CFG_TARGET_ARCH(aarch64→arm64-v8a,arm→armeabi-v7a,x86/x86_641:1), resolve the NDK fromANDROID_NDK_HOME/ANDROID_NDK_ROOT/ANDROID_NDK, forceNinja, and pinANDROID_PLATFORM=android-21.End-user contract after this change
The standard cargo-ndk +
nttld/setup-ndk@v1GitHub Action workflow Just Works.Validation
JoltPhysics + JoltC + joltc-sys + roltcross-compile completes in ~20s. Downstream Rust crate (Titan engine'stitan-jolt-3d) builds against the cross-compiled libs.armv7-linux-androideabiis not addressed by this PR — it hits an unrelatedJoltCLAYOUT_COMPATIBLEstatic_assert (JPC_*Settings16-byte alignment vsJPH::*Settings8-byte alignment on 32-bit ARM). That looks like a JoltC-side ABI bug for 32-bit targets; happy to track separately.target_os == "android", and the/EHscchange only narrows the existing condition (Windows targets still get it).Test plan
cargo check -p joltc-syson Windows host (default target, x86_64-pc-windows-msvc) —/EHscstill applied; existing behavior unchanged.cargo ndk --target aarch64-linux-android check -p joltc-syson Windows host — succeeds with onlyANDROID_NDK_HOMEset.cargo ndk --target aarch64-linux-android check -p joltc-syson Linux + macOS hosts — reviewer to validate; should be the simpler case (no/EHschot path).cargo check -p joltc-syson Linux/macOS — unaffected; existing CI covers.Opened from the same Titan-engine fork that submitted SecondHalfGames/JoltC#23 (the
JPC_PhysicsSystem_SetGravityexport). Both PRs are independent — happy to address review feedback on either.