Skip to content
Merged
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
30 changes: 8 additions & 22 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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" }),

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".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, you're right! Thank you! I cleaned up the code, works for me and I agree it is backward compatible.

" \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