From 1df13d05097763f34f83e86e972647f69ce21657 Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Fri, 26 Nov 2021 23:25:50 -0700 Subject: [PATCH] glfw: update system_sdk to match latest Zig master macOS version targeting The latest Zig master supports specifying a specific macOS version for libc, via the target triple (ziglang/zig#10215): * x86_64-macos.10 (Catalina) * x86_64-macos.11 (Big Sur) * x86_64-macos.12 (Monterey) * aarch64-macos.11 (Big Sur) * aarch64-macos.12 (Monterey) Mach's `system_sdk.zig` can now download the relevant XCode framework stubs for Big Sur (11) and Monterey (12). Although we don't have an SDK for Catalina (10) currently, we use the Big Sur (11) SDK in that case and it generally works fine. By default, Zig targets the N-3 version (e.g. `x86_64-macos` defaults to `x86_64-macos.10`). Targeting the minimum supported version is useful for compatability, it guarantees the produced binary will run on any later macOS version. Targeting the newer version can be useful if you wish to use newer APIs not available in previous versions. Fixes hexops/mach#102 Signed-off-by: Stephen Gutekanst --- glfw/build.zig | 1 - glfw/src/Window.zig | 6 +++--- glfw/src/opengl.zig | 4 ++-- glfw/system_sdk.zig | 18 +++++++++++++----- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/glfw/build.zig b/glfw/build.zig index 5cc48721..de55d1b8 100644 --- a/glfw/build.zig +++ b/glfw/build.zig @@ -244,4 +244,3 @@ fn linkGLFWDependencies(b: *Builder, step: *std.build.LibExeObjStep, options: Op }, } } - diff --git a/glfw/src/Window.zig b/glfw/src/Window.zig index 66f4dd72..22a7205b 100644 --- a/glfw/src/Window.zig +++ b/glfw/src/Window.zig @@ -751,15 +751,15 @@ pub inline fn setSizeLimits(self: Window, min: Size, max: Size) Error!void { /// see also: window_sizelimits, glfw.Window.setSizeLimits pub inline fn setAspectRatio(self: Window, numerator: usize, denominator: usize) Error!void { internal_debug.assertInitialized(); - + std.debug.assert(numerator != 0); std.debug.assert(denominator != 0); - + if (numerator != glfw.dont_care and denominator != glfw.dont_care) { std.debug.assert(numerator > 0); std.debug.assert(denominator > 0); } - + c.glfwSetWindowAspectRatio(self.handle, @intCast(c_int, numerator), @intCast(c_int, denominator)); getError() catch |err| return switch (err) { Error.PlatformError => err, diff --git a/glfw/src/opengl.zig b/glfw/src/opengl.zig index 37fd314f..9370e363 100644 --- a/glfw/src/opengl.zig +++ b/glfw/src/opengl.zig @@ -133,10 +133,10 @@ pub inline fn swapInterval(interval: isize) Error!void { /// see also: context_glext, glfw.getProcAddress pub inline fn extensionSupported(extension: [:0]const u8) Error!bool { internal_debug.assertInitialized(); - + std.debug.assert(extension.len != 0); std.debug.assert(extension[0] != 0); - + const supported = c.glfwExtensionSupported(extension); getError() catch |err| return switch (err) { Error.NoCurrentContext => err, diff --git a/glfw/system_sdk.zig b/glfw/system_sdk.zig index 410c15ac..782ec8a5 100644 --- a/glfw/system_sdk.zig +++ b/glfw/system_sdk.zig @@ -5,9 +5,11 @@ //! //! The SDKs used by this script by default are: //! +//! * Windows: none //! * Linux: https://github.com/hexops/sdk-linux-x86_64 (~40MB, X11, Wayland, etc. development libraries) -//! * MacOS: https://github.com/hexops/sdk-macos-12.0 (~112MB, most frameworks you'd find in the XCode SDK) -//! * Windows: not needed +//! * MacOS (most frameworks you'd find in the XCode SDK): +//! * https://github.com/hexops/sdk-macos-11.3 (~160MB, default) +//! * https://github.com/hexops/sdk-macos-12.0 (~112MB, only if you specify a macOS 12 target triple.) //! //! You may supply your own SDKs via the Options struct if needed, although the Mach versions above //! will generally work for most OpenGL/Vulkan applications. @@ -34,8 +36,11 @@ pub const Options = struct { /// The github org to find repositories in. github_org: []const u8 = "hexops", - /// The MacOS SDK repository name. - macos_sdk: []const u8 = "sdk-macos-12.0", + /// The MacOS 12 SDK repository name. + macos_sdk_12: []const u8 = "sdk-macos-12.0", + + /// The MacOS 11 SDK repository name. + macos_sdk_11: []const u8 = "sdk-macos-11.3", /// The Linux x86-64 SDK repository name. linux_x86_64_sdk: []const u8 = "sdk-linux-x86_64", @@ -57,7 +62,10 @@ pub fn include(b: *Builder, step: *std.build.LibExeObjStep, options: Options) vo } fn includeSdkMacOS(b: *Builder, step: *std.build.LibExeObjStep, options: Options) void { - const sdk_root_dir = getSdkRoot(b.allocator, options.github_org, options.macos_sdk) catch unreachable; + const target = (std.zig.system.NativeTargetInfo.detect(b.allocator, step.target) catch unreachable).target; + const mac_12 = target.os.version_range.semver.isAtLeast(.{ .major = 12, .minor = 0 }) orelse false; + const sdk_name = if (mac_12) options.macos_sdk_12 else options.macos_sdk_11; + const sdk_root_dir = getSdkRoot(b.allocator, options.github_org, sdk_name) catch unreachable; if (options.set_sysroot) { step.addFrameworkDir("/System/Library/Frameworks");