Skip to content

Commit

Permalink
update to latest xcode-frameworks API
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
  • Loading branch information
slimsag committed Oct 8, 2024
1 parent 1893ad9 commit 81c8808
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 39 deletions.
62 changes: 29 additions & 33 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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");
Expand All @@ -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", .{});
Expand Down Expand Up @@ -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,
Expand All @@ -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,
});
Expand All @@ -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);
}
}
Expand All @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand All @@ -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(.{
Expand All @@ -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| {
Expand Down
11 changes: 5 additions & 6 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 81c8808

Please sign in to comment.