Skip to content

native_build: fail fast (with the real cause) when Android needs zig but it's missing#20

Merged
GenericJam merged 1 commit into
masterfrom
fail-fast-zig-missing
Jun 19, 2026
Merged

native_build: fail fast (with the real cause) when Android needs zig but it's missing#20
GenericJam merged 1 commit into
masterfrom
fail-fast-zig-missing

Conversation

@GenericJam

Copy link
Copy Markdown
Owner

The failure this fixes

A real mix mob.deploy --native --android failure (gist) ended in:

CMake Error at CMakeLists.txt:78 (add_library):
  Cannot find source file:
    /Users/ben/code/bravautwo_mobile/deps/mob/android/jni/mob_nif.c

That error points at the wrong thing. The real cause is printed ~150 lines earlier and then ignored:

zig not on PATH — skipping build.zig step (CMake will compile sources directly)

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's mob_nif.zig now). So once build.zig exists but zig is missing, the build cannot succeed — but zig_build_android_objects/4 warned 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/3 and add a fourth outcome:

build.zig zig legacy mob_nif.c plan behaviour
no :skip_no_build_zig nothing to do
yes yes :run_zig real build.zig path
yes no yes :legacy_cmake warn + continue (old mob still has the C sources)
yes no no :zig_required abort before Gradle with an actionable message

The :zig_required path returns {:error, zig_required_message()}, so the build stops immediately and the last thing printed is the cause and the fix:

✗ Android native build failed: zig is not on your PATH, and this project's
Android native build needs it.

mob 0.7+ compiles the Android JNI layer with build.zig. The legacy CMake
fallback would reference C sources (deps/mob/android/jni/mob_nif.c) that no
longer ship with mob, so the build cannot succeed without zig.

Install zig 0.15.x, then re-run `mix mob.deploy --native --android`:
  asdf:    asdf plugin add zig && asdf install zig 0.15.2 && asdf global zig 0.15.2
  manual:  https://ziglang.org/download/  (then put `zig` on your PATH)

Verify your toolchain any time with `mix mob.doctor`.

The version (0.15.x / 0.15.2) matches what mix mob.doctor already recommends. Projects on an older mob that still ships the C sources are unaffected: they keep the :legacy_cmake warn-and-continue path.

Tests

zig_build_plan/3 is tested across the full 2×2×... matrix, and zig_required_message/0 is pinned to name both the cause (mob_nif.c, "zig is not on your PATH") and the fix (zig 0.15, mix mob.doctor). Full native_build_test.exs green (148). format / credo --strict / compile --warnings-as-errors clean (pre-push hook passed).

🤖 Generated with Claude Code

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>
@GenericJam GenericJam merged commit 05657c4 into master Jun 19, 2026
3 checks passed
GenericJam added a commit that referenced this pull request Jun 20, 2026
…missing zig (#23, #20)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.

1 participant