From 1a6454a92c4f315fe1b6f6c362706a3603fb65f5 Mon Sep 17 00:00:00 2001 From: archbirdplus <53286705+archbirdplus@users.noreply.github.com> Date: Sun, 28 Apr 2024 02:20:20 -0700 Subject: [PATCH] Mac Dev PR 1 (#336) * Add libraries for macos + deps_local * Tab characters * build.zig.zon: MacOS comment, use relative path * build.zig.zon: Add dot to url field * build.zig: lazily load deps_local * build.zig: revert bad debug edit --- build.zig | 24 ++++++++++++++++++++++-- build.zig.zon | 8 ++++++-- src/main.zig | 2 +- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/build.zig b/build.zig index ddc7462c..0e39cbeb 100644 --- a/build.zig +++ b/build.zig @@ -21,10 +21,17 @@ pub fn build(b: *std.Build) !void { exe.linkLibC(); exe.linkLibCpp(); - const deps = b.dependency("deps", .{ + // For the time being, MacOS cubyz_deps will not have released binaries. + const depsName = if (t.os.tag == .macos) "deps_local" else "deps"; + const deps = b.lazyDependency(depsName, .{ .target = target, .optimize = optimize, - }); + }) orelse { + // Lazy dependencies with a `url` field will fail here the first time. + // build.zig will restart and try again. + std.log.info("Downloading dependency {s}.", .{depsName}); + return; + }; exe.addLibraryPath(deps.path("lib")); exe.addIncludePath(deps.path("include")); @@ -42,6 +49,19 @@ pub fn build(b: *std.Build) !void { exe.linkSystemLibrary("asound"); exe.linkSystemLibrary("x11"); exe.linkSystemLibrary("GL"); + } else if(t.os.tag == .macos) { + exe.linkFramework("AudioUnit"); + exe.linkFramework("AudioToolbox"); + exe.linkFramework("CoreAudio"); + exe.linkFramework("CoreServices"); + exe.linkFramework("Foundation"); + exe.linkFramework("IOKit"); + exe.linkFramework("Cocoa"); + exe.linkFramework("QuartzCore"); + exe.linkSystemLibrary("GL"); + exe.linkSystemLibrary("X11"); + exe.addLibraryPath(.{.path="/usr/local/GL/lib"}); + exe.addLibraryPath(.{.path="/opt/X11/lib"}); } else { std.log.err("Unsupported target: {}\n", .{t.os.tag}); } diff --git a/build.zig.zon b/build.zig.zon index 241f7d9b..b0435de1 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -3,10 +3,14 @@ .version = "0.0.0", .paths = .{""}, .dependencies = .{ + .deps_local = .{ + .path = "../Cubyz-libs/zig-out", // macos has no official deps release + .lazy = true, + }, .deps = .{ - //.url = "file:///home/mint/Cubyz-libs/zig-out.tar.gz", // fetching the lib from the local folder + //.url = "file:../Cubyz-libs/zig-out.tar.gz", // fetching the lib from the local folder .url = "https://github.com/PixelGuys/Cubyz-libs/releases/download/2/zig-out.tar.gz", .hash = "12201446153e8822c020a10199880fae5fac7eb3f1e3f7c7a9b653e58914fa3e2223", }, }, -} \ No newline at end of file +} diff --git a/src/main.zig b/src/main.zig index 4227dd7a..2319ca7d 100644 --- a/src/main.zig +++ b/src/main.zig @@ -451,4 +451,4 @@ pub fn main() void { test "abc" { _ = @import("json.zig"); -} \ No newline at end of file +}