From ba818509e0dafe0c9b6827afcff829ed1b20a6ce Mon Sep 17 00:00:00 2001 From: Charlie Windolf Date: Sun, 2 Aug 2026 09:44:50 -0400 Subject: [PATCH 1/5] mac: build complaining about extra defines --- src/macos.zig | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/macos.zig b/src/macos.zig index 5b0f11f4a..8cd103467 100644 --- a/src/macos.zig +++ b/src/macos.zig @@ -73,9 +73,9 @@ pub fn build( // C library functions .HAVE_DLOPEN = 1, .HAVE_MALLOC = 1, - .HAVE_CALLOC = 1, - .HAVE_REALLOC = 1, - .HAVE_FREE = 1, + // .HAVE_CALLOC = 1, + // .HAVE_REALLOC = 1, + // .HAVE_FREE = 1, .HAVE_GETENV = 1, .HAVE_SETENV = 1, .HAVE_PUTENV = 1, @@ -169,10 +169,10 @@ pub fn build( .HAVE_SYSCONF = 1, .HAVE_CLOCK_GETTIME = 1, .HAVE_GETPAGESIZE = 1, - .HAVE_MPROTECT = 1, + // .HAVE_MPROTECT = 1, .HAVE_PTHREAD_SETNAME_NP = 1, .HAVE_SEM_TIMEDWAIT = 1, - .HAVE_SYSCTL = 1, + // .HAVE_SYSCTL = 1, .HAVE_SYSCTLBYNAME = 1, .HAVE_O_CLOEXEC = 1, .USE_POSIX_SPAWN = 1, From 1cd7a14e759a0ce40565330ad0662ba87de4aac7 Mon Sep 17 00:00:00 2001 From: Charlie Windolf Date: Sun, 2 Aug 2026 09:45:00 -0400 Subject: [PATCH 2/5] include SDL_main --- src/sdl.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/sdl.h b/src/sdl.h index a897cf086..895b265f0 100644 --- a/src/sdl.h +++ b/src/sdl.h @@ -51,3 +51,6 @@ #include #include #include + +// I want to use callbacks +#include From 781ef70d63296eb31456da61392b36105e061c49 Mon Sep 17 00:00:00 2001 From: Charlie Windolf Date: Mon, 3 Aug 2026 14:57:49 -0400 Subject: [PATCH 3/5] sdl: callbacks working on mac and at least compiling for ios simulator --- build.zig | 56 +++++++++- src/ios.zig | 271 +++++++++++++++++++++++++++++++++++++++++++++++++ src/macos.zig | 4 +- src/sdl.h | 3 - src/sdl.zon | 30 ++++++ src/sdl_main.c | 3 + 6 files changed, 360 insertions(+), 7 deletions(-) create mode 100644 src/ios.zig create mode 100644 src/sdl_main.c diff --git a/build.zig b/build.zig index 7c4c5541f..7792fef2d 100644 --- a/build.zig +++ b/build.zig @@ -2,6 +2,7 @@ const std = @import("std"); const linux = @import("src/linux.zig"); const windows = @import("src/windows.zig"); const macos = @import("src/macos.zig"); +const ios = @import("src/ios.zig"); const build_zon = @import("build.zig.zon"); const Translator = @import("translate_c").Translator; @@ -36,6 +37,11 @@ pub fn build(b: *std.Build) !void { , ) orelse .static; + const main_callbacks = b.option(bool, "main_callbacks", + \\build SDL3_main to enter the app through SDL_AppInit/Iterate/Event/Quit rather + \\than a classic SDL_main, defaults to false + ) orelse false; + // Create the library const lib = b.addLibrary(.{ .name = "SDL3", @@ -45,8 +51,7 @@ pub fn build(b: *std.Build) !void { .link_libc = true, }), .linkage = linkage, - .version = comptime std.SemanticVersion.parse(build_zon.dependencies.sdl.so_version) - catch unreachable, + .version = comptime std.SemanticVersion.parse(build_zon.dependencies.sdl.so_version) catch unreachable, }); switch (linkage) { .dynamic => { @@ -75,6 +80,23 @@ pub fn build(b: *std.Build) !void { .flags = flags, }); + const main_lib = b.addLibrary(.{ + .name = "SDL3_main", + .root_module = b.createModule(.{ + .target = target, + .optimize = optimize, + .link_libc = true, + }), + .linkage = .static, + }); + main_lib.root_module.addIncludePath(upstream.path("include")); + if (main_callbacks) { + main_lib.root_module.addCMacro("SDL_MAIN_USE_CALLBACKS", "1"); + } + main_lib.root_module.addCSourceFile(.{ .file = b.path("src/sdl_main.c") }); + addAppleSdkPathsToModule(b, target.result, main_lib.root_module); + b.installArtifact(main_lib); + if (default_target_config) { const build_config_h = b.addConfigHeader(.{ .style = .{ .cmake = upstream.path("include/build_config/SDL_build_config.h.cmake") }, @@ -104,6 +126,7 @@ pub fn build(b: *std.Build) !void { .linux => linux.build(b, target.result, lib, build_config_h), .windows => windows.build(b, target.result, lib, build_config_h), .macos => macos.build(b, target.result, lib, build_config_h), + .ios => ios.build(b, target.result, lib, build_config_h), else => @panic("target has no default config"), } } @@ -125,11 +148,16 @@ pub fn build(b: *std.Build) !void { else => optimize, }, }); + translator.defineCMacro("USING_GENERATED_CONFIG_H", "1"); translator.addIncludePath(upstream.path("include")); translator.addIncludePath(upstream.path("src/video/khronos")); translator.mod.linkLibrary(lib); try b.modules.putNoClobber(b.graph.arena, "sdl3", translator.mod); + addAppleSdkPathsToTranslator(b, target.result, translator); + if (target.result.os.tag == .ios) { + translator.defineCMacro("TARGET_OS_IPHONE", "1"); + } // Add the example const example = b.addExecutable(.{ @@ -149,3 +177,27 @@ pub fn build(b: *std.Build) !void { const run_step = b.step("run-example", "Run the example app"); run_step.dependOn(&run_example.step); } + +pub fn addAppleSdkPathsToTranslator(b: *std.Build, target: std.Target, translator: Translator) void { + if (!target.os.tag.isDarwin()) return; + + const sdk = std.zig.system.darwin.getSdk(b.allocator, b.graph.io, &target) orelse + @panic("Couldn't detect Apple SDK"); + + translator.addIncludePath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "usr/include" }) }); + translator.addSystemFrameworkPath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "System/Library/Frameworks" }) }); + translator.addSystemFrameworkPath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "System/Library/SubFrameworks" }) }); + translator.addIncludePath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "usr/lib" }) }); +} + +pub fn addAppleSdkPathsToModule(b: *std.Build, target: std.Target, module: *std.Build.Module) void { + if (!target.os.tag.isDarwin()) return; + + const sdk = std.zig.system.darwin.getSdk(b.allocator, b.graph.io, &target) orelse + @panic("Couldn't detect Apple SDK"); + + module.addSystemIncludePath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "usr/include" }) }); + module.addSystemFrameworkPath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "System/Library/Frameworks" }) }); + module.addSystemFrameworkPath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "System/Library/SubFrameworks" }) }); + module.addLibraryPath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "usr/lib" }) }); +} diff --git a/src/ios.zig b/src/ios.zig new file mode 100644 index 000000000..228ce629e --- /dev/null +++ b/src/ios.zig @@ -0,0 +1,271 @@ +const std = @import("std"); +const build_zon = @import("../build.zig.zon"); +const sources = @import("sdl.zon"); +const root = @import("../build.zig"); +const Subsystems = root.Subsystems; +const AllDrivers = root.Drivers; + +pub fn build( + b: *std.Build, + target: std.Target, + lib: *std.Build.Step.Compile, + build_config_h: *std.Build.Step.ConfigHeader, +) void { + const upstream = b.dependency("sdl", .{}); + // _ = target; + lib.root_module.addIncludePath(b.dependency("egl", .{}).path("api")); + lib.root_module.addIncludePath(b.dependency("opengl", .{}).path("api")); + + root.addAppleSdkPathsToModule(b, target, lib.root_module); + + // Link with the platform specific system frameworks + lib.root_module.linkFramework("UIKit", .{}); + lib.root_module.linkFramework("UIUtilities", .{}); + lib.root_module.linkFramework("CoreMotion", .{}); + lib.root_module.linkFramework("CoreVideo", .{}); + lib.root_module.linkFramework("CoreAudio", .{}); + lib.root_module.linkFramework("CoreHaptics", .{}); + lib.root_module.linkFramework("CoreFoundation", .{}); + lib.root_module.linkFramework("CoreMedia", .{}); + lib.root_module.linkFramework("CoreGraphics", .{}); + lib.root_module.linkFramework("Metal", .{}); + lib.root_module.linkFramework("QuartzCore", .{}); + lib.root_module.linkFramework("AudioToolbox", .{}); + lib.root_module.linkFramework("AVFoundation", .{}); + lib.root_module.linkFramework("Foundation", .{}); + lib.root_module.linkFramework("GameController", .{}); + lib.root_module.linkFramework("CoreBluetooth", .{}); + lib.root_module.linkFramework("UniformTypeIdentifiers", .{}); + lib.root_module.linkFramework("OpenGLES", .{}); + // lib.root_module.linkSystemLibrary("iconv", .{}); + + // Add the platform specific sources + const objc_flags = root.flags.* ++ [_][]const u8{"-fobjc-arc"}; + lib.root_module.addCSourceFiles(.{ + .files = &(sources.uikit ++ sources.darwin ++ sources.ios ++ sources.unix ++ sources.pthread), + .root = upstream.path("src"), + .flags = &objc_flags, + }); + + // Set the platform specific build config + build_config_h.addValues(.{ + .HAVE_GCC_ATOMICS = 1, + + .HAVE_ALLOCA_H = 1, + .HAVE_FLOAT_H = 1, + .HAVE_INTTYPES_H = 1, + .HAVE_LIMITS_H = 1, + .HAVE_MATH_H = 1, + .HAVE_SIGNAL_H = 1, + .HAVE_STDARG_H = 1, + .HAVE_STDDEF_H = 1, + .HAVE_STDINT_H = 1, + .HAVE_STDIO_H = 1, + .HAVE_STDLIB_H = 1, + .HAVE_STRING_H = 1, + .HAVE_SYS_TYPES_H = 1, + .HAVE_WCHAR_H = 1, + + // C library functions + .HAVE_LIBC = 1, + .HAVE_DLOPEN = 1, + .HAVE_MALLOC = 1, + .HAVE_GETENV = 1, + .HAVE_GETHOSTNAME = 1, + .HAVE_PUTENV = 1, + .HAVE_SETENV = 1, + .HAVE_UNSETENV = 1, + .HAVE_ABS = 1, + .HAVE_BCOPY = 1, + .HAVE_MEMSET = 1, + .HAVE_MEMCPY = 1, + .HAVE_MEMMOVE = 1, + .HAVE_MEMCMP = 1, + .HAVE_STRLEN = 1, + .HAVE_STRLCPY = 1, + .HAVE_STRLCAT = 1, + .HAVE_STRCHR = 1, + .HAVE_STRRCHR = 1, + .HAVE_STRSTR = 1, + .HAVE_STRTOK_R = 1, + .HAVE_STRTOL = 1, + .HAVE_STRTOUL = 1, + .HAVE_STRTOLL = 1, + .HAVE_STRTOULL = 1, + .HAVE_STRTOD = 1, + .HAVE_ATOI = 1, + .HAVE_ATOF = 1, + .HAVE_STRCMP = 1, + .HAVE_STRNCMP = 1, + .HAVE_STRPBRK = 1, + .HAVE_VSSCANF = 1, + .HAVE_VSNPRINTF = 1, + .HAVE_ACOS = 1, + .HAVE_ACOSF = 1, + .HAVE_ASIN = 1, + .HAVE_ASINF = 1, + .HAVE_ATAN = 1, + .HAVE_ATANF = 1, + .HAVE_ATAN2 = 1, + .HAVE_ATAN2F = 1, + .HAVE_CEIL = 1, + .HAVE_CEILF = 1, + .HAVE_COPYSIGN = 1, + .HAVE_COPYSIGNF = 1, + .HAVE_COS = 1, + .HAVE_COSF = 1, + .HAVE_EXP = 1, + .HAVE_EXPF = 1, + .HAVE_FABS = 1, + .HAVE_FABSF = 1, + .HAVE_FLOOR = 1, + .HAVE_FLOORF = 1, + .HAVE_FMOD = 1, + .HAVE_FMODF = 1, + .HAVE_ISINF = 1, + .HAVE_ISINF_FLOAT_MACRO = 1, + .HAVE_ISNAN = 1, + .HAVE_ISNAN_FLOAT_MACRO = 1, + .HAVE_LOG = 1, + .HAVE_LOGF = 1, + .HAVE_LOG10 = 1, + .HAVE_LOG10F = 1, + .HAVE_LROUND = 1, + .HAVE_LROUNDF = 1, + .HAVE_MODF = 1, + .HAVE_MODFF = 1, + .HAVE_POW = 1, + .HAVE_POWF = 1, + .HAVE_ROUND = 1, + .HAVE_ROUNDF = 1, + .HAVE_SCALBN = 1, + .HAVE_SCALBNF = 1, + .HAVE_SIN = 1, + .HAVE_SINF = 1, + .HAVE_SQRT = 1, + .HAVE_SQRTF = 1, + .HAVE_TAN = 1, + .HAVE_TANF = 1, + .HAVE_TRUNC = 1, + .HAVE_TRUNCF = 1, + .HAVE_SIGACTION = 1, + .HAVE_SETJMP = 1, + .HAVE_NANOSLEEP = 1, + .HAVE_GMTIME_R = 1, + .HAVE_LOCALTIME_R = 1, + .HAVE_NL_LANGINFO = 1, + .HAVE_SYSCONF = 1, + .HAVE_SYSCTLBYNAME = 1, + .HAVE_O_CLOEXEC = 1, + + // enable iPhone version of Core Audio driver + .SDL_AUDIO_DRIVER_COREAUDIO = 1, + // Enable the dummy audio driver (src/audio/dummy/\*.c) + .SDL_AUDIO_DRIVER_DUMMY = 1, + + // Enable the stub haptic driver (src/haptic/dummy/\*.c) + .SDL_HAPTIC_DUMMY = 1, + + // Enable joystick support + // Only enable HIDAPI support if you want to support Steam Controllers on iOS and tvOS + .SDL_JOYSTICK_MFI = 1, + .SDL_JOYSTICK_VIRTUAL = 1, + + // Enable various process implementations + .SDL_PROCESS_DUMMY = 1, + + // Enable the CoreMotion sensor driver + .SDL_SENSOR_COREMOTION = 1, + + // Enable Unix style SO loading + .SDL_LOADSO_DLOPEN = 1, + + // Enable various threading systems + .SDL_THREAD_PTHREAD = 1, + .SDL_THREAD_PTHREAD_RECURSIVE_MUTEX = 1, + + // Enable various RTC system + .SDL_TIME_UNIX = 1, + + // Enable various timer systems + .SDL_TIMER_UNIX = 1, + + // Supported video drivers + .SDL_VIDEO_DRIVER_UIKIT = 1, + .SDL_VIDEO_DRIVER_DUMMY = 1, + + // .SDL_PLATFORM_SUPPORTS_METAL = 1, + .SDL_VIDEO_OPENGL_ES2 = 1, + .SDL_VIDEO_OPENGL_ES = 1, + .SDL_VIDEO_RENDER_OGL_ES2 = 1, + + .SDL_VIDEO_METAL = 1, + .SDL_VIDEO_VULKAN = 1, + .SDL_GPU_METAL = 1, + .SDL_GPU_VULKAN = 1, + .SDL_VIDEO_RENDER_METAL = 1, + .SDL_VIDEO_RENDER_GPU = 1, + + // Enable system power support + .SDL_POWER_UIKIT = 1, + + // enable iPhone keyboard support + .SDL_IPHONE_KEYBOARD = 1, + + // enable iOS extended launch screen + .SDL_IPHONE_LAUNCHSCREEN = 1, + + // enable filesystem support + .SDL_FILESYSTEM_COCOA = 1, + .SDL_FSOPS_POSIX = 1, + + .SDL_CAMERA_DRIVER_DUMMY = 1, + + // Enable dialog subsystem + .SDL_DIALOG_DUMMY = 1, + + // Enable tray subsystem + .SDL_TRAY_DUMMY = 1, + + // Disable ARM SVE2 intrinsics until we confirm they're available on all Apple mobile and TV hardware + // .SDL_DISABLE_SVE2 = 1, + + // Enable steam storage + .SDL_STORAGE_STEAM = 1, + + // Unused + .SDL_AUDIO_DRIVER_ALSA_DYNAMIC = "", + .SDL_AUDIO_DRIVER_JACK_DYNAMIC = "", + .SDL_AUDIO_DRIVER_PIPEWIRE_DYNAMIC = "", + .SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC = "", + .SDL_AUDIO_DRIVER_SNDIO_DYNAMIC = "", + .SDL_LIBUSB_DYNAMIC = "", + .SDL_UDEV_DYNAMIC = "", + .SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC = "", + .SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC_GBM = "", + .SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC = "", + .SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_CURSOR = "", + .SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_EGL = "", + .SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_LIBDECOR = "", + .SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_XKBCOMMON = "", + .SDL_VIDEO_DRIVER_X11_DYNAMIC = "", + .SDL_VIDEO_DRIVER_X11_DYNAMIC_XCURSOR = "", + .SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT = "", + .SDL_VIDEO_DRIVER_X11_DYNAMIC_XFIXES = "", + .SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2 = "", + .SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR = "", + .SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS = "", + .SDL_CAMERA_DRIVER_PIPEWIRE_DYNAMIC = "", + .SDL_LIBDECOR_VERSION_MAJOR = "", + .SDL_LIBDECOR_VERSION_MINOR = "", + .SDL_LIBDECOR_VERSION_PATCH = "", + .SDL_FRIBIDI_DYNAMIC = "", + .SDL_LIBTHAI_DYNAMIC = "", + .SDL_VIDEO_DRIVER_X11_DYNAMIC_XTEST = "", + .SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_GESTURE = "", + .SDL_XKBCOMMON_VERSION_MAJOR = "", + .SDL_XKBCOMMON_VERSION_MINOR = "", + .SDL_XKBCOMMON_VERSION_PATCH = "", + .SDL_EMSCRIPTEN_PERSISTENT_PATH_STRING = "", + }); +} diff --git a/src/macos.zig b/src/macos.zig index 8cd103467..217a47923 100644 --- a/src/macos.zig +++ b/src/macos.zig @@ -11,14 +11,14 @@ pub fn build( lib: *std.Build.Step.Compile, build_config_h: *std.Build.Step.ConfigHeader, ) void { - _ = target; - const upstream = b.dependency("sdl", .{}); // Add the platform specific dependency include paths lib.root_module.addIncludePath(b.dependency("egl", .{}).path("api")); lib.root_module.addIncludePath(b.dependency("opengl", .{}).path("api")); + root.addAppleSdkPathsToModule(b, target, lib.root_module); + // Link with the platform specific system frameworks lib.root_module.linkFramework("Cocoa", .{}); lib.root_module.linkFramework("IOKit", .{}); diff --git a/src/sdl.h b/src/sdl.h index 895b265f0..a897cf086 100644 --- a/src/sdl.h +++ b/src/sdl.h @@ -51,6 +51,3 @@ #include #include #include - -// I want to use callbacks -#include diff --git a/src/sdl.zon b/src/sdl.zon index 390507fd3..e61fdbb38 100644 --- a/src/sdl.zon +++ b/src/sdl.zon @@ -476,6 +476,33 @@ "joystick/darwin/SDL_iokitjoystick.c", "joystick/apple/SDL_mfijoystick.m", }, + .uikit = .{ + "audio/coreaudio/SDL_coreaudio.m", + "camera/coremedia/SDL_camera_coremedia.m", + "render/metal/SDL_render_metal.m", + "gpu/metal/SDL_gpu_metal.m", + "joystick/apple/SDL_mfijoystick.m", + "filesystem/cocoa/SDL_sysfilesystem.m", + "locale/macos/SDL_syslocale.m", + "misc/ios/SDL_sysurl.m", + "video/uikit/SDL_uikitappdelegate.m", + "video/uikit/SDL_uikitclipboard.m", + "video/uikit/SDL_uikitevents.m", + "video/uikit/SDL_uikitmessagebox.m", + "video/uikit/SDL_uikitmetalview.m", + "video/uikit/SDL_uikitmodes.m", + "video/uikit/SDL_uikitopengles.m", + "video/uikit/SDL_uikitopenglview.m", + "video/uikit/SDL_uikitpen.m", + "video/uikit/SDL_uikitview.m", + "video/uikit/SDL_uikitviewcontroller.m", + "video/uikit/SDL_uikitvideo.m", + "video/uikit/SDL_uikitvulkan.m", + "video/uikit/SDL_uikitwindow.m", + "power/uikit/SDL_syspower.m", + "sensor/coremotion/SDL_coremotionsensor.m", + "main/ios/SDL_sysmain_callbacks.m", + }, .emscripten = .{ "filesystem/emscripten/SDL_sysfilesystem.c", "joystick/emscripten/SDL_sysjoystick.c", @@ -501,6 +528,9 @@ .mac = .{ "hidapi/mac/hid.c", }, + .ios = .{ + "hidapi/ios/hid.m", + }, .n3ds = .{ "io/n3ds/SDL_iostreamromfs.c", "joystick/n3ds/SDL_sysjoystick.c", diff --git a/src/sdl_main.c b/src/sdl_main.c new file mode 100644 index 000000000..35e5e659d --- /dev/null +++ b/src/sdl_main.c @@ -0,0 +1,3 @@ +#ifdef SDL_MAIN_USE_CALLBACKS +#include +#endif From d7bbda82a2b55f5d7b117d2a10df706edcca42e9 Mon Sep 17 00:00:00 2001 From: Charlie Windolf Date: Mon, 3 Aug 2026 15:55:09 -0400 Subject: [PATCH 4/5] get ios simulator running --- build.zig | 4 ++++ src/ios.zig | 1 - 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/build.zig b/build.zig index 7792fef2d..258792906 100644 --- a/build.zig +++ b/build.zig @@ -42,6 +42,8 @@ pub fn build(b: *std.Build) !void { \\than a classic SDL_main, defaults to false ) orelse false; + const can_san = target.result.os.tag != .ios; + // Create the library const lib = b.addLibrary(.{ .name = "SDL3", @@ -49,6 +51,7 @@ pub fn build(b: *std.Build) !void { .target = target, .optimize = optimize, .link_libc = true, + .sanitize_c = if (can_san) null else .off, }), .linkage = linkage, .version = comptime std.SemanticVersion.parse(build_zon.dependencies.sdl.so_version) catch unreachable, @@ -86,6 +89,7 @@ pub fn build(b: *std.Build) !void { .target = target, .optimize = optimize, .link_libc = true, + .sanitize_c = if (can_san) null else .off, }), .linkage = .static, }); diff --git a/src/ios.zig b/src/ios.zig index 228ce629e..272d0a1a2 100644 --- a/src/ios.zig +++ b/src/ios.zig @@ -20,7 +20,6 @@ pub fn build( // Link with the platform specific system frameworks lib.root_module.linkFramework("UIKit", .{}); - lib.root_module.linkFramework("UIUtilities", .{}); lib.root_module.linkFramework("CoreMotion", .{}); lib.root_module.linkFramework("CoreVideo", .{}); lib.root_module.linkFramework("CoreAudio", .{}); From d9969ab222118edee9beeef8f84bec89d7bd8236 Mon Sep 17 00:00:00 2001 From: Charlie Windolf Date: Sun, 25 Oct 2026 11:10:37 -0400 Subject: [PATCH 5/5] refactor to better support -Dinclude_path etc rather than calling xcrun always, and also unify SDK logic in one place --- build.zig | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/build.zig b/build.zig index 1426000ee..f76d21d7a 100644 --- a/build.zig +++ b/build.zig @@ -127,7 +127,7 @@ pub fn build(b: *std.Build) !void { main_lib.root_module.addCMacro("SDL_MAIN_USE_CALLBACKS", "1"); } main_lib.root_module.addCSourceFile(.{ .file = b.path("src/sdl_main.c") }); - addAppleSdkPathsToModule(b, target.result, main_lib.root_module); + addSystemPathsToModule(b, main_lib.root_module, system_paths); b.installArtifact(main_lib); if (default_target_config) { @@ -179,7 +179,7 @@ pub fn build(b: *std.Build) !void { translate_c.defineCMacro("USING_GENERATED_CONFIG_H", "1"); translate_c.addIncludePath(upstream.path("include")); translate_c.addIncludePath(upstream.path("src/video/khronos")); - addAppleSdkPathsToTranslateC(b, target.result, translate_c); + addSystemPathsToTranslateC(b, translate_c, system_paths); const module = translate_c.addModule("sdl3"); module.linkLibrary(lib); @@ -249,15 +249,21 @@ pub fn withAppleSdkFallback(b: *std.Build, target: std.Target, paths: SystemPath }; } -pub fn addAppleSdkPathsToTranslateC(b: *std.Build, target: std.Target, translate_c: *std.Build.Step.TranslateC) void { - if (!target.os.tag.isDarwin()) return; - - const sdk = std.zig.system.darwin.getSdk(b.allocator, b.graph.io, &target) orelse - @panic("Couldn't detect Apple SDK"); +fn addSystemPathsToModule(b: *std.Build, module: *std.Build.Module, paths: SystemPaths) void { + if (paths.include) |p| module.addSystemIncludePath(p); + if (paths.framework) |p| { + module.addSystemFrameworkPath(p); + module.addSystemFrameworkPath(p.dirname().path(b, "SubFrameworks")); + } + if (paths.library) |p| module.addLibraryPath(p); +} - translate_c.addIncludePath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "usr/include" }) }); - translate_c.addSystemFrameworkPath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "System/Library/Frameworks" }) }); - translate_c.addSystemFrameworkPath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "System/Library/SubFrameworks" }) }); +fn addSystemPathsToTranslateC(b: *std.Build, translate_c: *std.Build.Step.TranslateC, paths: SystemPaths) void { + if (paths.include) |p| translate_c.addSystemIncludePath(p); + if (paths.framework) |p| { + translate_c.addSystemFrameworkPath(p); + translate_c.addSystemFrameworkPath(p.dirname().path(b, "SubFrameworks")); + } } pub fn addAppleSdkPathsToModule(b: *std.Build, target: std.Target, module: *std.Build.Module) void {