From 6c18a1c3dd72f4463723ede978eabf7a1fcf93ff 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. Look for the pinned SDK in both layouts, and fall back to whichever SDK xcrun considers active if it is in neither. Co-Authored-By: Claude Opus 5 --- build.zig | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/build.zig b/build.zig index 565695a7d..b79e06de8 100644 --- a/build.zig +++ b/build.zig @@ -202,23 +202,31 @@ pub fn build(b: *std.Build) void { " \r\n", ); + // A full Xcode keeps its SDKs under Platforms/, the Command Line Tools + // keep them directly under SDKs/. Fall back to whichever SDK xcrun + // considers active if neither holds the one we asked for. + const candidates = [_][]const u8{ + b.pathJoin(&.{ path, "Platforms/MacOSX.platform/Developer/SDKs/" ++ sdk }), + b.pathJoin(&.{ path, "SDKs/" ++ sdk }), + }; + + const sdk_path = for (candidates) |candidate| { + std.Io.Dir.accessAbsolute(b.graph.io, candidate, .{}) catch continue; + break candidate; + } else std.mem.trim( + u8, + 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" }), }); }