pkg/apple-sdk: detect apple sdk based on target

This commit is contained in:
Mitchell Hashimoto
2024-01-09 22:24:34 -08:00
parent 829776bebd
commit 22648d60e7
4 changed files with 39 additions and 21 deletions

View File

@ -9,7 +9,7 @@ pub fn build(b: *std.Build) !void {
pub fn addPaths(b: *std.Build, m: *std.Build.Module) !void {
// The active SDK we want to use
const sdk = "MacOSX14.sdk";
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.
@ -19,22 +19,30 @@ pub fn addPaths(b: *std.Build, m: *std.Build.Module) !void {
" \r\n",
);
m.addSystemFrameworkPath(.{
.cwd_relative = b.pathJoin(&.{
path,
"Platforms/MacOSX.platform/Developer/SDKs/" ++ sdk ++ "/System/Library/Frameworks",
}),
});
m.addSystemIncludePath(.{
.cwd_relative = b.pathJoin(&.{
path,
"Platforms/MacOSX.platform/Developer/SDKs/" ++ sdk ++ "/usr/include",
}),
});
m.addLibraryPath(.{
.cwd_relative = b.pathJoin(&.{
path,
"Platforms/MacOSX.platform/Developer/SDKs/" ++ sdk ++ "/usr/lib",
}),
// 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" }) });
}
const SDK = struct {
platform: []const u8,
version: []const u8,
pub fn fromTarget(target: std.Target) !SDK {
return switch (target.os.tag) {
.macos => .{ .platform = "MacOSX", .version = "14.2" },
else => {
std.log.err("unsupported os={}", .{target.os.tag});
return error.UnsupportedOS;
},
};
}
};

View File

@ -5,7 +5,11 @@ pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
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 freetype = b.dependency("freetype", .{

View File

@ -18,6 +18,8 @@ pub fn build(b: *std.Build) !void {
const module = b.addModule("harfbuzz", .{
.root_source_file = .{ .path = "main.zig" },
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "freetype", .module = freetype.module("freetype") },
.{ .name = "macos", .module = macos.module("macos") },
@ -59,7 +61,7 @@ pub fn build(b: *std.Build) !void {
"-DHAVE_FT_DONE_MM_VAR=1",
"-DHAVE_FT_GET_TRANSFORM=1",
});
if (coretext_enabled) {
if (coretext_enabled and target.result.isDarwin()) {
try flags.appendSlice(&.{"-DHAVE_CORETEXT=1"});
try apple_sdk.addPaths(b, &lib.root_module);
try apple_sdk.addPaths(b, module);

View File

@ -6,7 +6,11 @@ pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
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(.{
.name = "macos",