Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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" }),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like it would be super simple to only rely on this command rather than checking predefined directories. Does that work for you?

I did a little reading and it doesn't seem like using the latest SDK breaks compatibility with old macOS. Backward compatibility for macOS binaries is specified by a zig target like "x86_64-macos.10.15-none", which is the equivalent of the clang arg "-mmacos-version-min".

" \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" }),
});
}

Expand Down
Loading