update to latest xcode-frameworks API

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2024-10-08 09:30:48 -07:00 committed by Stephen Gutekanst
parent c1dacf4df9
commit 26b385eb8e
2 changed files with 34 additions and 39 deletions

View file

@ -129,6 +129,15 @@ pub fn build(b: *std.Build) !void {
} }
} }
if (target.result.isDarwin()) { if (target.result.isDarwin()) {
// TODO(build): determine if we need this after https://github.com/ziglang/zig/issues/21598 is fixed
if (b.lazyDependency("xcode_frameworks", .{
.target = target,
.optimize = optimize,
})) |dep| {
module.addSystemFrameworkPath(dep.path("Frameworks"));
module.addSystemIncludePath(dep.path("include"));
module.addLibraryPath(dep.path("lib"));
}
if (b.lazyDependency("mach_objc", .{ if (b.lazyDependency("mach_objc", .{
.target = target, .target = target,
.optimize = optimize, .optimize = optimize,
@ -150,7 +159,6 @@ pub fn build(b: *std.Build) !void {
.optimize = optimize, .optimize = optimize,
}); });
example_exe.root_module.addImport("mach", module); example_exe.root_module.addImport("mach", module);
addPaths(&example_exe.root_module);
// b.installArtifact(example_exe); // b.installArtifact(example_exe);
const example_compile_step = b.step("sysaudio-" ++ example, "Compile 'sysaudio-" ++ example ++ "' example"); const example_compile_step = b.step("sysaudio-" ++ example, "Compile 'sysaudio-" ++ example ++ "' example");
@ -164,22 +172,9 @@ pub fn build(b: *std.Build) !void {
example_run_step.dependOn(&example_run_cmd.step); example_run_step.dependOn(&example_run_cmd.step);
} }
} }
if (target.result.isDarwin()) {
if (b.lazyDependency("mach_objc", .{
.target = target,
.optimize = optimize,
})) |dep| module.addImport("objc", dep.module("mach-objc"));
}
} }
if (target.result.isDarwin()) { if (target.result.isDarwin()) {
// Transitive dependencies, explicit linkage of these works around
// ziglang/zig#17130
module.linkSystemLibrary("objc", .{});
module.linkFramework("CoreImage", .{});
module.linkFramework("CoreVideo", .{});
// Direct dependencies
module.linkFramework("AudioToolbox", .{}); module.linkFramework("AudioToolbox", .{});
module.linkFramework("CoreFoundation", .{}); module.linkFramework("CoreFoundation", .{});
module.linkFramework("CoreAudio", .{}); module.linkFramework("CoreAudio", .{});
@ -222,6 +217,15 @@ pub fn build(b: *std.Build) !void {
if (want_sysgpu) { if (want_sysgpu) {
if (b.lazyDependency("vulkan_zig_generated", .{})) |dep| module.addImport("vulkan", dep.module("vulkan-zig-generated")); if (b.lazyDependency("vulkan_zig_generated", .{})) |dep| module.addImport("vulkan", dep.module("vulkan-zig-generated"));
if (target.result.isDarwin()) { if (target.result.isDarwin()) {
// TODO(build): determine if we need this after https://github.com/ziglang/zig/issues/21598 is fixed
if (b.lazyDependency("xcode_frameworks", .{
.target = target,
.optimize = optimize,
})) |dep| {
module.addSystemFrameworkPath(dep.path("Frameworks"));
module.addSystemIncludePath(dep.path("include"));
module.addLibraryPath(dep.path("lib"));
}
if (b.lazyDependency("mach_objc", .{ if (b.lazyDependency("mach_objc", .{
.target = target, .target = target,
.optimize = optimize, .optimize = optimize,
@ -233,7 +237,6 @@ pub fn build(b: *std.Build) !void {
if (want_libs) { if (want_libs) {
const lib = b.addStaticLibrary(.{ const lib = b.addStaticLibrary(.{
.name = "mach-sysgpu", .name = "mach-sysgpu",
.root_source_file = b.addWriteFiles().add("empty.c", ""),
.target = target, .target = target,
.optimize = optimize, .optimize = optimize,
}); });
@ -242,7 +245,6 @@ pub fn build(b: *std.Build) !void {
lib.root_module.addImport(e.key_ptr.*, e.value_ptr.*); lib.root_module.addImport(e.key_ptr.*, e.value_ptr.*);
} }
linkSysgpu(b, &lib.root_module); linkSysgpu(b, &lib.root_module);
addPaths(&lib.root_module);
b.installArtifact(lib); b.installArtifact(lib);
} }
} }
@ -259,7 +261,6 @@ pub fn build(b: *std.Build) !void {
while (iter.next()) |e| { while (iter.next()) |e| {
unit_tests.root_module.addImport(e.key_ptr.*, e.value_ptr.*); unit_tests.root_module.addImport(e.key_ptr.*, e.value_ptr.*);
} }
addPaths(&unit_tests.root_module);
// Linux gamemode requires libc. // Linux gamemode requires libc.
if (target.result.os.tag == .linux) unit_tests.root_module.link_libc = true; if (target.result.os.tag == .linux) unit_tests.root_module.link_libc = true;
@ -312,7 +313,15 @@ fn linkSysgpu(b: *std.Build, module: *std.Build.Module) void {
const target = resolved_target.result; const target = resolved_target.result;
if (target.cpu.arch != .wasm32) module.link_libc = true; if (target.cpu.arch != .wasm32) module.link_libc = true;
if (target.isDarwin()) { if (target.isDarwin()) {
module.linkSystemLibrary("objc", .{}); // TODO(build): determine if we need this after https://github.com/ziglang/zig/issues/21598 is fixed
if (b.lazyDependency("xcode_frameworks", .{
.target = resolved_target,
.optimize = module.optimize.?,
})) |dep| {
module.addSystemFrameworkPath(dep.path("Frameworks"));
module.addSystemIncludePath(dep.path("include"));
module.addLibraryPath(dep.path("lib"));
}
if (target.os.tag == .macos) { if (target.os.tag == .macos) {
module.linkFramework("AppKit", .{}); module.linkFramework("AppKit", .{});
} else { } else {
@ -352,18 +361,6 @@ fn linkSysgpu(b: *std.Build, module: *std.Build.Module) void {
} }
} }
pub fn addPaths(mod: *std.Build.Module) void {
if (mod.resolved_target.?.result.isDarwin()) @import("xcode_frameworks").addPaths(mod);
}
fn sdkPath(comptime suffix: []const u8) []const u8 {
if (suffix[0] != '/') @compileError("suffix must be an absolute path");
return comptime blk: {
const root_dir = std.fs.path.dirname(@src().file) orelse ".";
break :blk root_dir ++ suffix;
};
}
fn buildExamples( fn buildExamples(
b: *std.Build, b: *std.Build,
optimize: std.builtin.OptimizeMode, optimize: std.builtin.OptimizeMode,
@ -387,12 +384,12 @@ fn buildExamples(
.{ .core = true, .name = "triangle", .deps = &.{} }, .{ .core = true, .name = "triangle", .deps = &.{} },
// Mach engine examples // Mach engine examples
.{ .name = "hardware-check", .deps = &.{ .assets, .zigimg } }, // .{ .name = "hardware-check", .deps = &.{ .assets, .zigimg } },
.{ .name = "custom-renderer", .deps = &.{} }, .{ .name = "custom-renderer", .deps = &.{} },
.{ .name = "glyphs", .deps = &.{ .freetype, .assets } }, .{ .name = "glyphs", .deps = &.{ .freetype, .assets } },
.{ .name = "piano", .deps = &.{} }, .{ .name = "piano", .deps = &.{} },
.{ .name = "play-opus", .deps = &.{.assets} }, .{ .name = "play-opus", .deps = &.{.assets} },
.{ .name = "sprite", .deps = &.{ .zigimg, .assets } }, // .{ .name = "sprite", .deps = &.{ .zigimg, .assets } },
.{ .name = "text", .deps = &.{.assets} }, .{ .name = "text", .deps = &.{.assets} },
}) |example| { }) |example| {
const exe = b.addExecutable(.{ const exe = b.addExecutable(.{
@ -405,7 +402,6 @@ fn buildExamples(
.optimize = optimize, .optimize = optimize,
}); });
exe.root_module.addImport("mach", mach_mod); exe.root_module.addImport("mach", mach_mod);
addPaths(&exe.root_module);
b.installArtifact(exe); b.installArtifact(exe);
for (example.deps) |d| { for (example.deps) |d| {

View file

@ -22,15 +22,14 @@
.lazy = true, .lazy = true,
}, },
.mach_objc = .{ .mach_objc = .{
.url = "https://pkg.machengine.org/mach-objc/8c04f317104d5a0b24806c6da7ddea2cf67ece94.tar.gz", .url = "https://pkg.machengine.org/mach-objc/a66178db2ec3d20d928b8f90491cb30d3da23816.tar.gz",
.hash = "1220396d9181fde88d809dbe7cb7f337f4217b4e242106e417053ce5877c9330d15e", .hash = "122077746182b7015b4df73c0ba38378c3499ac9353fcd8701c51cd598ea93f06582",
.lazy = true, .lazy = true,
}, },
.xcode_frameworks = .{ .xcode_frameworks = .{
.url = "https://pkg.machengine.org/xcode-frameworks/a6bf82e032d4d9923ad5c222d466710fcc05f249.tar.gz", .url = "https://pkg.machengine.org/xcode-frameworks/9a45f3ac977fd25dff77e58c6de1870b6808c4a7.tar.gz",
.hash = "12208da4dfcd9b53fb367375fb612ec73f38e53015f1ce6ae6d6e8437a637078e170", .hash = "122098b9174895f9708bc824b0f9e550c401892c40a900006459acf2cbf78acd99bb",
// TODO(build): be able to mark this dependency as lazy .lazy = true,
// .lazy = true,
}, },
.direct3d_headers = .{ .direct3d_headers = .{
.url = "https://pkg.machengine.org/direct3d-headers/edfc992810c9f19b4003f398ed30e08a0dd3d356.tar.gz", .url = "https://pkg.machengine.org/direct3d-headers/edfc992810c9f19b4003f398ed30e08a0dd3d356.tar.gz",