From cc0c9deba9449f36d2d92d7399d88bd333cb3cd0 Mon Sep 17 00:00:00 2001 From: Iuri de Silvio Date: Thu, 20 Aug 2026 09:14:07 +0200 Subject: [PATCH] Find the macOS SDK when only the Command Line Tools are installed The SDK path was built as `xcode-select --print-path` plus `Platforms/MacOSX.platform/Developer/SDKs/`, which only exists inside a full Xcode. With the Command Line Tools selected the SDKs sit directly under `SDKs/`, so the link step failed with warning: unable to open library directory '/Library/Developer/CommandLineTools/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.sdk/usr/lib' after compiling everything. Ask xcrun for the SDK instead, which answers for either layout. The pinned MacOSX15.sdk was not holding the build to that SDK to begin with: zig resolves the SDK for the link itself and the paths added here only supplement it, so a native build recorded `sdk 26.5` with or without the pin. What a binary runs on comes from the target -- `-Dtarget=aarch64-macos`, which is what publish.yaml passes, gives `minos 13.0` -- and not from here. Co-Authored-By: Claude Opus 5 --- build.zig | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/build.zig b/build.zig index 565695a7d..0674e4a05 100644 --- a/build.zig +++ b/build.zig @@ -188,37 +188,23 @@ pub fn build(b: *std.Build) void { } if (target.result.os.tag == .macos) { - // Stole this method from - // https://github.com/ghostty-org/ghostty/commit/c0722b3652e5e207f34d220f64a03d9d53e93ad0 - - // The active SDK we want to use - const sdk = "MacOSX15.sdk"; - - // Get the path to our active Xcode installation. If this fails then - // the zig build will fail. - const path = std.mem.trim( + // The SDK the toolchain is pointed at, whether that is a full Xcode + // or just the Command Line Tools. The macOS version a binary runs on + // comes from the target, not from this. + const sdk_path = std.mem.trim( u8, - b.run(&.{ "xcode-select", "--print-path" }), + b.run(&.{ "xcrun", "--show-sdk-path" }), " \r\n", ); canvas.root_module.addSystemFrameworkPath(.{ - .cwd_relative = b.pathJoin(&.{ - path, - "Platforms/MacOSX.platform/Developer/SDKs/" ++ sdk ++ "/System/Library/Frameworks", - }), + .cwd_relative = b.pathJoin(&.{ sdk_path, "System/Library/Frameworks" }), }); canvas.root_module.addSystemIncludePath(.{ - .cwd_relative = b.pathJoin(&.{ - path, - "Platforms/MacOSX.platform/Developer/SDKs/" ++ sdk ++ "/usr/include", - }), + .cwd_relative = b.pathJoin(&.{ sdk_path, "usr/include" }), }); canvas.root_module.addLibraryPath(.{ - .cwd_relative = b.pathJoin(&.{ - path, - "Platforms/MacOSX.platform/Developer/SDKs/" ++ sdk ++ "/usr/lib", - }), + .cwd_relative = b.pathJoin(&.{ sdk_path, "usr/lib" }), }); }