Skip to content

feat(bgfx-android): route std.log to logcat (Phase-4 observability) - #401

Merged
apotema merged 2 commits into
mainfrom
feat/android-stdlog-routing
Jun 28, 2026
Merged

feat(bgfx-android): route std.log to logcat (Phase-4 observability)#401
apotema merged 2 commits into
mainfrom
feat/android-stdlog-routing

Conversation

@apotema

@apotema apotema commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Makes the bgfx-Android surface-loss hooks observable on-device. The generated main.zig had no std_options.logFn, so zig std.log went to stderr — invisible in adb 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 } routing std.log__android_log_write (tag labelle, 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

    • Android builds now forward std.log output to Logcat, so logs appear in adb logcat under a consistent tag.
    • Log severity is mapped to Android log levels for clearer filtering, with safe handling when message formatting fails.
  • Chores

    • Bumped the labelle_assembler package version to 0.58.0.

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.
@coderabbitai

coderabbitai Bot commented Jun 28, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f7fa2e66-5cbd-462e-b5e9-edaf7afb4d08

📥 Commits

Reviewing files that changed from the base of the PR and between 2afb408 and b814f2d.

📒 Files selected for processing (1)
  • backends/bgfx/templates/android.txt
🚧 Files skipped from review as they are similar to previous changes (1)
  • backends/bgfx/templates/android.txt

📝 Walkthrough

Walkthrough

Adds Android logcat routing to the bgfx Android template with a custom std.log handler, and bumps the package version to 0.58.0.

Changes

Android Log Integration

Layer / File(s) Summary
std.log to logcat routing
backends/bgfx/templates/android.txt, build.zig.zon
Adds std_options with androidLogFn, declares __android_log_write, maps std.log.Level to Android priorities, formats log messages with a truncation fallback, and writes to logcat under the "labelle" tag. The package version is updated to 0.58.0.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Poem

🐇 I hop through logs, so bright and neat,
"labelle" sings with every beat.
In Android’s glow, my debug lines sway,
Then 0.58.0 hops along the way!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: routing Android std.log output to logcat for bgfx observability.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/android-stdlog-routing

Comment @coderabbitai help to get the list of available commands.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

In Zig, @EnumLiteral is not a valid builtin function or type. The correct type for the scope parameter in std.log is @Type(.enum_literal). Using @EnumLiteral() will result in a compilation error.

    comptime scope: @Type(.enum_literal),

Comment thread backends/bgfx/templates/android.txt Outdated
.warn => 5,
.err => 6,
};
_ = __android_log_write(prio, "labelle", text.ptr);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.
@apotema
apotema merged commit ed50f95 into main Jun 28, 2026
6 checks passed
@apotema
apotema deleted the feat/android-stdlog-routing branch June 28, 2026 22:55
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