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:
@@ -550,6 +550,14 @@ pub fn link(allocator: std.mem.Allocator, io: std.Io, output_obj: []const u8, ex
|
||||
// owns `ANativeActivity_onCreate` and forwards into android_main on
|
||||
// a dedicated thread. `-u ANativeActivity_onCreate` keeps the glue's
|
||||
// symbol from being stripped (nothing in our .o references it).
|
||||
//
|
||||
// The `libraries` parameter (collected from `#library` directives)
|
||||
// and `frameworks` parameter (Apple-only by definition) are
|
||||
// intentionally ignored here. On Android, users opt into specific
|
||||
// libs via `opts.add_link_flag("-l<name>")` in their build.sx —
|
||||
// the platform-specific link surface should be expressed in build
|
||||
// options rather than auto-inherited from every imported module
|
||||
// (most of which assume Apple targets).
|
||||
const ndk_root = if (target_config.sysroot) |sr|
|
||||
try allocator.dupe(u8, sr)
|
||||
else
|
||||
@@ -587,11 +595,11 @@ pub fn link(allocator: std.mem.Allocator, io: std.Io, output_obj: []const u8, ex
|
||||
for (target_config.lib_paths) |lp| {
|
||||
try argv.append(allocator, try std.fmt.allocPrint(allocator, "-L{s}", .{lp}));
|
||||
}
|
||||
for (libraries) |lib| {
|
||||
try argv.append(allocator, try std.fmt.allocPrint(allocator, "-l{s}", .{lib}));
|
||||
}
|
||||
// Default libs available on every Android runtime; linker drops
|
||||
// unreferenced ones automatically.
|
||||
// unreferenced ones automatically. `#library` directives are
|
||||
// intentionally NOT auto-emitted here (most assume Apple targets);
|
||||
// users opt in per-target via `opts.add_link_flag("-l...")` in
|
||||
// their build.sx.
|
||||
try argv.appendSlice(allocator, &.{ "-llog", "-landroid", "-lEGL", "-lGLESv3", "-lm", "-ldl" });
|
||||
for (target_config.extra_link_flags) |flag| {
|
||||
var it = std.mem.tokenizeScalar(u8, flag, ' ');
|
||||
|
||||
Reference in New Issue
Block a user