From 81c88089fdd643e331fceb66194233482ef7241d Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Tue, 8 Oct 2024 09:30:48 -0700 Subject: [PATCH] update to latest xcode-frameworks API Signed-off-by: Stephen Gutekanst --- build.zig | 62 ++++++++++++++++++++++++--------------------------- build.zig.zon | 11 +++++---- 2 files changed, 34 insertions(+), 39 deletions(-) diff --git a/build.zig b/build.zig index e5c1becc9f..360a185be4 100644 --- a/build.zig +++ b/build.zig @@ -129,6 +129,15 @@ pub fn build(b: *std.Build) !void { } } 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", .{ .target = target, .optimize = optimize, @@ -150,7 +159,6 @@ pub fn build(b: *std.Build) !void { .optimize = optimize, }); example_exe.root_module.addImport("mach", module); - addPaths(&example_exe.root_module); // b.installArtifact(example_exe); 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); } } - 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()) { - // 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("CoreFoundation", .{}); module.linkFramework("CoreAudio", .{}); @@ -222,6 +217,15 @@ pub fn build(b: *std.Build) !void { if (want_sysgpu) { if (b.lazyDependency("vulkan_zig_generated", .{})) |dep| module.addImport("vulkan", dep.module("vulkan-zig-generated")); 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", .{ .target = target, .optimize = optimize, @@ -233,7 +237,6 @@ pub fn build(b: *std.Build) !void { if (want_libs) { const lib = b.addStaticLibrary(.{ .name = "mach-sysgpu", - .root_source_file = b.addWriteFiles().add("empty.c", ""), .target = target, .optimize = optimize, }); @@ -242,7 +245,6 @@ pub fn build(b: *std.Build) !void { lib.root_module.addImport(e.key_ptr.*, e.value_ptr.*); } linkSysgpu(b, &lib.root_module); - addPaths(&lib.root_module); b.installArtifact(lib); } } @@ -259,7 +261,6 @@ pub fn build(b: *std.Build) !void { while (iter.next()) |e| { unit_tests.root_module.addImport(e.key_ptr.*, e.value_ptr.*); } - addPaths(&unit_tests.root_module); // Linux gamemode requires libc. 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; if (target.cpu.arch != .wasm32) module.link_libc = true; 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) { module.linkFramework("AppKit", .{}); } 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( b: *std.Build, optimize: std.builtin.OptimizeMode, @@ -387,12 +384,12 @@ fn buildExamples( .{ .core = true, .name = "triangle", .deps = &.{} }, // Mach engine examples - .{ .name = "hardware-check", .deps = &.{ .assets, .zigimg } }, + // .{ .name = "hardware-check", .deps = &.{ .assets, .zigimg } }, .{ .name = "custom-renderer", .deps = &.{} }, .{ .name = "glyphs", .deps = &.{ .freetype, .assets } }, .{ .name = "piano", .deps = &.{} }, .{ .name = "play-opus", .deps = &.{.assets} }, - .{ .name = "sprite", .deps = &.{ .zigimg, .assets } }, + // .{ .name = "sprite", .deps = &.{ .zigimg, .assets } }, .{ .name = "text", .deps = &.{.assets} }, }) |example| { const exe = b.addExecutable(.{ @@ -405,7 +402,6 @@ fn buildExamples( .optimize = optimize, }); exe.root_module.addImport("mach", mach_mod); - addPaths(&exe.root_module); b.installArtifact(exe); for (example.deps) |d| { diff --git a/build.zig.zon b/build.zig.zon index 7e3686be28..8f479ab756 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -22,15 +22,14 @@ .lazy = true, }, .mach_objc = .{ - .url = "https://pkg.machengine.org/mach-objc/8c04f317104d5a0b24806c6da7ddea2cf67ece94.tar.gz", - .hash = "1220396d9181fde88d809dbe7cb7f337f4217b4e242106e417053ce5877c9330d15e", + .url = "https://pkg.machengine.org/mach-objc/1b2196531754f4073977288570f13419ddd004a1.tar.gz", + .hash = "12205887aa6740d0134e64078be9cef9e96e63284a65d1562cbcfb5215593fc8f3c0", .lazy = true, }, .xcode_frameworks = .{ - .url = "https://pkg.machengine.org/xcode-frameworks/a6bf82e032d4d9923ad5c222d466710fcc05f249.tar.gz", - .hash = "12208da4dfcd9b53fb367375fb612ec73f38e53015f1ce6ae6d6e8437a637078e170", - // TODO(build): be able to mark this dependency as lazy - // .lazy = true, + .url = "https://pkg.machengine.org/xcode-frameworks/9a45f3ac977fd25dff77e58c6de1870b6808c4a7.tar.gz", + .hash = "122098b9174895f9708bc824b0f9e550c401892c40a900006459acf2cbf78acd99bb", + .lazy = true, }, .direct3d_headers = .{ .url = "https://pkg.machengine.org/direct3d-headers/edfc992810c9f19b4003f398ed30e08a0dd3d356.tar.gz",