mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-17 09:16:11 +03:00
Merge pull request #1273 from mitchellh/macos-sdk
build: use Xcode to find macOS SDK
This commit is contained in:
@ -444,8 +444,8 @@ pub fn build(b: *std.Build) !void {
|
|||||||
b.installFile("images/icons/icon_256x256@2x@2x.png", "share/icons/hicolor/256x256@2/apps/com.mitchellh.ghostty.png");
|
b.installFile("images/icons/icon_256x256@2x@2x.png", "share/icons/hicolor/256x256@2/apps/com.mitchellh.ghostty.png");
|
||||||
}
|
}
|
||||||
|
|
||||||
// On Mac we can build the embedding library.
|
// On Mac we can build the embedding library. This only handles the macOS lib.
|
||||||
if (builtin.target.isDarwin() and target.result.isDarwin()) {
|
if (builtin.target.isDarwin() and target.result.os.tag == .macos) {
|
||||||
const static_lib_aarch64 = lib: {
|
const static_lib_aarch64 = lib: {
|
||||||
const lib = b.addStaticLibrary(.{
|
const lib = b.addStaticLibrary(.{
|
||||||
.name = "ghostty",
|
.name = "ghostty",
|
||||||
@ -792,7 +792,7 @@ fn addDeps(
|
|||||||
// We always require the system SDK so that our system headers are available.
|
// We always require the system SDK so that our system headers are available.
|
||||||
// This makes things like `os/log.h` available for cross-compiling.
|
// This makes things like `os/log.h` available for cross-compiling.
|
||||||
if (step.rootModuleTarget().isDarwin()) {
|
if (step.rootModuleTarget().isDarwin()) {
|
||||||
try @import("apple_sdk").addPaths(b, step);
|
try @import("apple_sdk").addPaths(b, &step.root_module);
|
||||||
}
|
}
|
||||||
|
|
||||||
// We always need the Zig packages
|
// We always need the Zig packages
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
# This file is auto-generated! check build-support/check-zig-cache-hash.sh for
|
# This file is auto-generated! check build-support/check-zig-cache-hash.sh for
|
||||||
# more details.
|
# more details.
|
||||||
"sha256-iRXzPgzOkt+TTcqPCRQubP3dN6lS+Wvn17l+0I/pDGg="
|
"sha256-1qlnSOyr2C9DtUdf+4QRNrBr4vUM1nVnv/mVUXxE5fA="
|
||||||
|
@ -7,12 +7,49 @@ pub fn build(b: *std.Build) !void {
|
|||||||
_ = optimize;
|
_ = optimize;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn addPaths(b: *std.Build, step: *std.Build.Step.Compile) !void {
|
/// Add the SDK framework, include, and library paths to the given module.
|
||||||
_ = b;
|
/// The module target is used to determine the SDK to use so it must have
|
||||||
@import("macos_sdk").addPaths(step);
|
/// a resolved target.
|
||||||
|
pub fn addPaths(b: *std.Build, m: *std.Build.Module) !void {
|
||||||
|
// The active SDK we want to use
|
||||||
|
const sdk = try SDK.fromTarget(m.resolved_target.?.result);
|
||||||
|
|
||||||
|
// Get the path to our active Xcode installation. If this fails then
|
||||||
|
// the zig build will fail. We store this in a struct variable so its
|
||||||
|
// static and only calculated once per build.
|
||||||
|
const Path = struct {
|
||||||
|
var value: ?[]const u8 = null;
|
||||||
|
};
|
||||||
|
const path = Path.value orelse path: {
|
||||||
|
const path = std.mem.trim(u8, b.run(&.{ "xcode-select", "--print-path" }), " \r\n");
|
||||||
|
Path.value = path;
|
||||||
|
break :path path;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Base path
|
||||||
|
const base = b.fmt("{s}/Platforms/{s}.platform/Developer/SDKs/{s}{s}.sdk", .{
|
||||||
|
path,
|
||||||
|
sdk.platform,
|
||||||
|
sdk.platform,
|
||||||
|
sdk.version,
|
||||||
|
});
|
||||||
|
|
||||||
|
m.addSystemFrameworkPath(.{ .cwd_relative = b.pathJoin(&.{ base, "/System/Library/Frameworks" }) });
|
||||||
|
m.addSystemIncludePath(.{ .cwd_relative = b.pathJoin(&.{ base, "/usr/include" }) });
|
||||||
|
m.addLibraryPath(.{ .cwd_relative = b.pathJoin(&.{ base, "/usr/lib" }) });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn addPathsModule(b: *std.Build, m: *std.Build.Module) !void {
|
const SDK = struct {
|
||||||
_ = b;
|
platform: []const u8,
|
||||||
@import("macos_sdk").addPathsModule(m);
|
version: []const u8,
|
||||||
}
|
|
||||||
|
pub fn fromTarget(target: std.Target) !SDK {
|
||||||
|
return switch (target.os.tag) {
|
||||||
|
.macos => .{ .platform = "MacOSX", .version = "14" },
|
||||||
|
else => {
|
||||||
|
std.log.err("unsupported os={}", .{target.os.tag});
|
||||||
|
return error.UnsupportedOS;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
@ -1,10 +1,5 @@
|
|||||||
.{
|
.{
|
||||||
.name = "apple-sdk",
|
.name = "apple-sdk",
|
||||||
.version = "0.1.0",
|
.version = "0.1.0",
|
||||||
.dependencies = .{
|
.dependencies = .{},
|
||||||
.macos_sdk = .{
|
|
||||||
.url = "https://github.com/mitchellh/zig-build-macos-sdk/archive/ee70f27c08680307fa35ada92e6b2c36e0ff84c6.tar.gz",
|
|
||||||
.hash = "1220b415f529f1c04ed876c2b481e9f8119d353d4e3d4d7c8607ee302d2142e13eca",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,11 @@ pub fn build(b: *std.Build) !void {
|
|||||||
const target = b.standardTargetOptions(.{});
|
const target = b.standardTargetOptions(.{});
|
||||||
const optimize = b.standardOptimizeOption(.{});
|
const optimize = b.standardOptimizeOption(.{});
|
||||||
|
|
||||||
const module = b.addModule("cimgui", .{ .root_source_file = .{ .path = "main.zig" } });
|
const module = b.addModule("cimgui", .{
|
||||||
|
.root_source_file = .{ .path = "main.zig" },
|
||||||
|
.target = target,
|
||||||
|
.optimize = optimize,
|
||||||
|
});
|
||||||
|
|
||||||
const imgui = b.dependency("imgui", .{});
|
const imgui = b.dependency("imgui", .{});
|
||||||
const freetype = b.dependency("freetype", .{
|
const freetype = b.dependency("freetype", .{
|
||||||
@ -60,8 +64,8 @@ pub fn build(b: *std.Build) !void {
|
|||||||
|
|
||||||
if (target.result.isDarwin()) {
|
if (target.result.isDarwin()) {
|
||||||
if (!target.query.isNative()) {
|
if (!target.query.isNative()) {
|
||||||
try @import("apple_sdk").addPaths(b, lib);
|
try @import("apple_sdk").addPaths(b, &lib.root_module);
|
||||||
try @import("apple_sdk").addPathsModule(b, module);
|
try @import("apple_sdk").addPaths(b, module);
|
||||||
}
|
}
|
||||||
lib.addCSourceFile(.{
|
lib.addCSourceFile(.{
|
||||||
.file = imgui.path("backends/imgui_impl_metal.mm"),
|
.file = imgui.path("backends/imgui_impl_metal.mm"),
|
||||||
|
@ -18,6 +18,8 @@ pub fn build(b: *std.Build) !void {
|
|||||||
|
|
||||||
const module = b.addModule("harfbuzz", .{
|
const module = b.addModule("harfbuzz", .{
|
||||||
.root_source_file = .{ .path = "main.zig" },
|
.root_source_file = .{ .path = "main.zig" },
|
||||||
|
.target = target,
|
||||||
|
.optimize = optimize,
|
||||||
.imports = &.{
|
.imports = &.{
|
||||||
.{ .name = "freetype", .module = freetype.module("freetype") },
|
.{ .name = "freetype", .module = freetype.module("freetype") },
|
||||||
.{ .name = "macos", .module = macos.module("macos") },
|
.{ .name = "macos", .module = macos.module("macos") },
|
||||||
@ -59,10 +61,10 @@ pub fn build(b: *std.Build) !void {
|
|||||||
"-DHAVE_FT_DONE_MM_VAR=1",
|
"-DHAVE_FT_DONE_MM_VAR=1",
|
||||||
"-DHAVE_FT_GET_TRANSFORM=1",
|
"-DHAVE_FT_GET_TRANSFORM=1",
|
||||||
});
|
});
|
||||||
if (coretext_enabled) {
|
if (coretext_enabled and target.result.isDarwin()) {
|
||||||
try flags.appendSlice(&.{"-DHAVE_CORETEXT=1"});
|
try flags.appendSlice(&.{"-DHAVE_CORETEXT=1"});
|
||||||
try apple_sdk.addPaths(b, lib);
|
try apple_sdk.addPaths(b, &lib.root_module);
|
||||||
try apple_sdk.addPathsModule(b, module);
|
try apple_sdk.addPaths(b, module);
|
||||||
lib.linkFramework("ApplicationServices");
|
lib.linkFramework("ApplicationServices");
|
||||||
module.linkFramework("ApplicationServices", .{});
|
module.linkFramework("ApplicationServices", .{});
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,11 @@ pub fn build(b: *std.Build) !void {
|
|||||||
const target = b.standardTargetOptions(.{});
|
const target = b.standardTargetOptions(.{});
|
||||||
const optimize = b.standardOptimizeOption(.{});
|
const optimize = b.standardOptimizeOption(.{});
|
||||||
|
|
||||||
const module = b.addModule("macos", .{ .root_source_file = .{ .path = "main.zig" } });
|
const module = b.addModule("macos", .{
|
||||||
|
.root_source_file = .{ .path = "main.zig" },
|
||||||
|
.target = target,
|
||||||
|
.optimize = optimize,
|
||||||
|
});
|
||||||
|
|
||||||
const lib = b.addStaticLibrary(.{
|
const lib = b.addStaticLibrary(.{
|
||||||
.name = "macos",
|
.name = "macos",
|
||||||
@ -36,11 +40,11 @@ pub fn build(b: *std.Build) !void {
|
|||||||
module.linkFramework("CoreGraphics", .{});
|
module.linkFramework("CoreGraphics", .{});
|
||||||
module.linkFramework("CoreText", .{});
|
module.linkFramework("CoreText", .{});
|
||||||
module.linkFramework("CoreVideo", .{});
|
module.linkFramework("CoreVideo", .{});
|
||||||
}
|
|
||||||
|
|
||||||
if (!target.query.isNative()) {
|
if (!target.query.isNative()) {
|
||||||
try apple_sdk.addPaths(b, lib);
|
try apple_sdk.addPaths(b, &lib.root_module);
|
||||||
try apple_sdk.addPathsModule(b, module);
|
try apple_sdk.addPaths(b, module);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
b.installArtifact(lib);
|
b.installArtifact(lib);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user