native_build: fail fast (with the real cause) when Android needs zig but it's missing#20
Merged
Merged
Conversation
A `--native --android` build with `jni/build.zig` present but no `zig` on PATH used to print a yellow "skipping build.zig step" warning and continue, then fall into the CMake fallback. On mob 0.7+ that fallback references `deps/mob/android/jni/mob_nif.c`, which no longer ships with mob (it's `mob_nif.zig` now), so the build always died ~150 lines later with a cryptic `CMake Error ... Cannot find source file: .../mob_nif.c`. Extract the decision into a pure `zig_build_plan/3` and treat "build.zig present, no zig, no legacy C source" as `:zig_required`: abort before Gradle with an actionable message (install zig 0.15.x, re-run, verify with `mix mob.doctor`) instead of limping into a CMake error that points at the wrong thing. Old mobs that still ship the C sources keep the `:legacy_cmake` warn-and-continue behaviour. Pure kernel + message tested across the full matrix. Co-Authored-By: Claude Opus 4.8 <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.
The failure this fixes
A real
mix mob.deploy --native --androidfailure (gist) ended in:That error points at the wrong thing. The real cause is printed ~150 lines earlier and then ignored:
On mob 0.7+ the Android JNI layer is compiled by
build.zig; the C source the CMake fallback wants (deps/mob/android/jni/mob_nif.c) no longer ships with mob (it'smob_nif.zignow). So oncebuild.zigexists butzigis missing, the build cannot succeed — butzig_build_android_objects/4warned in yellow and returned:ok, limping into Gradle to die later with a CMake error that blames a missing file instead of the missing toolchain.Change
Extract the decision into a pure
zig_build_plan/3and add a fourth outcome:mob_nif.c:skip_no_build_zig:run_zig:legacy_cmake:zig_requiredThe
:zig_requiredpath returns{:error, zig_required_message()}, so the build stops immediately and the last thing printed is the cause and the fix:The version (0.15.x / 0.15.2) matches what
mix mob.doctoralready recommends. Projects on an older mob that still ships the C sources are unaffected: they keep the:legacy_cmakewarn-and-continue path.Tests
zig_build_plan/3is tested across the full 2×2×... matrix, andzig_required_message/0is pinned to name both the cause (mob_nif.c, "zig is not on your PATH") and the fix (zig 0.15,mix mob.doctor). Fullnative_build_test.exsgreen (148). format / credo --strict / compile --warnings-as-errors clean (pre-push hook passed).🤖 Generated with Claude Code