android: forward NDK sysroot to embedded clang + skip auto #library/#framework
C imports (stb_image, stb_truetype) compiled via the embedded LLVM clang library now resolve bionic headers on Android. main.zig auto- fills target_config.sysroot with the NDK root (mirroring the iOS path that auto-fills the iOS SDK path); c_import.zig derives the bionic sysroot inside it and passes `--sysroot <ndk>/toolchains/llvm/prebuilt/<host>/sysroot` to the embedded clang. Android link branch in target.zig stops auto-appending entries from the collected `#library` / `#framework` lists. Most `#library` directives in the stdlib (`objc.sx`'s `objc :: #library "objc";`, frameworks set by uikit.sx, etc.) describe Apple-specific intent that's nonsensical on Android. Users opt into Android-side libs via `opts.add_link_flag(...)` in build.sx — same shape as how the iOS branch already lists frameworks in chess's configure_build. Verified end-to-end: chess game compiles for Android, packages into a debug-signed APK, installs and launches on Pixel 7 Pro. It crashes in UIRenderer.init because raw GL calls run before EGL is up — same architectural gap iOS bridges via the Metal GPU protocol. Next step is a GLES3 GPU impl or a lazy-init in UIRenderer. 86/86 regression tests + iOS-sim chess build clean.
This commit is contained in:
10
src/main.zig
10
src/main.zig
@@ -167,6 +167,15 @@ pub fn main(init: std.process.Init) !void {
|
||||
target_config.sysroot = sx.target.discoverAppleSdk(allocator, io, sdk_name) catch null;
|
||||
}
|
||||
|
||||
// Same idea for Android — the NDK root must be visible to BOTH the
|
||||
// C-import compile path (so `--sysroot ndk/.../sysroot` finds bionic
|
||||
// headers) and the link path. By convention, target_config.sysroot
|
||||
// holds the NDK root on Android (target.zig's link branch + c_import.zig
|
||||
// both read it). Honors any explicit --sysroot.
|
||||
if (target_config.isAndroid() and target_config.sysroot == null) {
|
||||
target_config.sysroot = sx.target.discoverAndroidNdk(allocator, io) catch null;
|
||||
}
|
||||
|
||||
const path = input_path orelse {
|
||||
printUsage();
|
||||
return;
|
||||
@@ -559,6 +568,7 @@ fn compileWithTimer(allocator: std.mem.Allocator, io: std.Io, input_path: []cons
|
||||
// Shadow the outer `fws` for the rest of the function by reassignment.
|
||||
fws = try merged_fws.toOwnedSlice(allocator);
|
||||
}
|
||||
|
||||
if (build_flags.len > 0) {
|
||||
var all_flags: std.ArrayList([]const u8) = .empty;
|
||||
for (target_config.extra_link_flags) |f| try all_flags.append(allocator, f);
|
||||
|
||||
Reference in New Issue
Block a user