feat(bgfx-android): route std.log to logcat (Phase-4 observability) - #401
Conversation
The generated main.zig had no std_options.logFn, so zig std.log went to stderr — invisible in adb logcat. Engine/backend diagnostics (the surface_lost/ surface_restored markers, 'first surface (cold init)', etc.) never reached the device log; only bgfx's own C logging showed. Add std_options.logFn on the bgfx-android generated root that routes std.log -> __android_log_write (tag 'labelle', level->ANDROID_LOG_* mapping). Makes the Phase-4 surface-loss hooks observable on-device. Signature compile-checked for aarch64-linux-android. Bump 0.57.0 -> 0.58.0.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds Android logcat routing to the bgfx Android template with a custom ChangesAndroid Log Integration
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Code Review
This pull request adds routing for Zig's std.log to Android logcat within the BGFX backend template, and bumps the project version to 0.58.0. Feedback is provided regarding two compilation errors in the new logging function: the use of the invalid @EnumLiteral type for the scope parameter, and passing text.ptr instead of text directly to __android_log_write which loses the sentinel-terminated type information.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
|
|
||
| fn androidLogFn( | ||
| comptime level: std.log.Level, | ||
| comptime scope: @EnumLiteral(), |
| .warn => 5, | ||
| .err => 6, | ||
| }; | ||
| _ = __android_log_write(prio, "labelle", text.ptr); |
There was a problem hiding this comment.
Passing text.ptr to __android_log_write will cause a compilation error. text is a sentinel-terminated slice of type [:0]u8, so text.ptr has the type [*]u8 which loses the sentinel in the type system and cannot be implicitly coerced to [*:0]const u8. You should pass text directly, as a sentinel-terminated slice implicitly coerces to a sentinel-terminated pointer.
_ = __android_log_write(prio, "labelle", text);
The generated main.zig already imports std via {{module_vars}} (used by the gpa
allocator), so my added 'const std' was a duplicate struct member -> compile
break in the cross-build. Dropped it; the logFn references the template's std
(file-scope, order-independent). Also pass the [:0]u8 slice directly to
__android_log_write instead of .ptr (clean sentinel coercion). @EnumLiteral() is
correct for Zig 0.16 (CI compiled past it; std lib + standalone confirm) — the
Gemini @type(.enum_literal) suggestion is the old form.
Makes the bgfx-Android surface-loss hooks observable on-device. The generated
main.zighad nostd_options.logFn, so zigstd.logwent to stderr — invisible inadb logcat. So the engine/backend markers (surface_lost: invalidated N,re-init against new surface (restore),first surface (cold init)) never showed; only bgfx's own C logging did (surfaced during the #558 emulator validation).Change
backends/bgfx/templates/android.txt(the generated root):pub const std_options: std.Options = .{ .logFn = androidLogFn }routingstd.log→__android_log_write(taglabelle, level→ANDROID_LOG_*). Covers ALL std.log across engine + backend + game on Android. Self-contained in the template (no engine change).Verified
logFn signature compile-checked standalone for
aarch64-linux-android(@EnumLiteral()scope param, Zig 0.16). The bgfx-Android CI cross-build exercises the full template → generated-game compile. Bump 0.57.0 → 0.58.0; pairs with FP #558 (repin to consume it).Summary by CodeRabbit
New Features
std.logoutput to Logcat, so logs appear inadb logcatunder a consistent tag.Chores
labelle_assemblerpackage version to0.58.0.