From ec26fb7ceeca99e7bbe98698398cd34e5cbdfa92 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 1 Oct 2023 17:02:12 -0700 Subject: [PATCH] pkg/macos --- build.zig | 2 +- pkg/macos/build.zig | 52 ++++++++++++++--------------------------- pkg/macos/build.zig.zon | 7 ++++++ 3 files changed, 25 insertions(+), 36 deletions(-) create mode 100644 pkg/macos/build.zig.zon diff --git a/build.zig b/build.zig index fc5ec72b2..6a1e96aca 100644 --- a/build.zig +++ b/build.zig @@ -739,7 +739,7 @@ fn addDeps( if (step.target.isDarwin()) { step.addModule("objc", objc_dep.module("objc")); step.addModule("macos", macos_dep.module("macos")); - //_ = try macos.link(b, step, .{}); + step.linkLibrary(macos_dep.artifact("macos")); // todo: do this is in zig-objc instead. step.linkSystemLibraryName("objc"); diff --git a/pkg/macos/build.zig b/pkg/macos/build.zig index 1b8df6b68..5a8f6fe54 100644 --- a/pkg/macos/build.zig +++ b/pkg/macos/build.zig @@ -1,52 +1,34 @@ const std = @import("std"); const builtin = @import("builtin"); +const apple_sdk = @import("apple_sdk"); pub fn build(b: *std.Build) !void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); - _ = target; - _ = optimize; _ = b.addModule("macos", .{ .source_file = .{ .path = "main.zig" } }); -} - -pub fn module(b: *std.Build) *std.build.Module { - return b.createModule(.{ - .source_file = .{ .path = (comptime thisDir()) ++ "/main.zig" }, - }); -} - -fn thisDir() []const u8 { - return std.fs.path.dirname(@src().file) orelse "."; -} - -pub const Options = struct {}; - -pub fn link( - b: *std.Build, - step: *std.build.LibExeObjStep, - opt: Options, -) !*std.build.LibExeObjStep { - _ = opt; - var flags = std.ArrayList([]const u8).init(b.allocator); - defer flags.deinit(); const lib = b.addStaticLibrary(.{ .name = "macos", - .target = step.target, - .optimize = step.optimize, + .target = target, + .optimize = optimize, }); - step.addCSourceFile(.{ - .file = .{ .path = comptime thisDir() ++ "/os/log.c" }, + + var flags = std.ArrayList([]const u8).init(b.allocator); + defer flags.deinit(); + lib.addCSourceFile(.{ + .file = .{ .path = "os/log.c" }, .flags = flags.items, }); - step.addCSourceFile(.{ - .file = .{ .path = comptime thisDir() ++ "/text/ext.c" }, + lib.addCSourceFile(.{ + .file = .{ .path = "text/ext.c" }, .flags = flags.items, }); - step.linkFramework("Carbon"); - step.linkFramework("CoreFoundation"); - step.linkFramework("CoreGraphics"); - step.linkFramework("CoreText"); - return lib; + lib.linkFramework("Carbon"); + lib.linkFramework("CoreFoundation"); + lib.linkFramework("CoreGraphics"); + lib.linkFramework("CoreText"); + try apple_sdk.addPaths(b, lib); + + b.installArtifact(lib); } diff --git a/pkg/macos/build.zig.zon b/pkg/macos/build.zig.zon new file mode 100644 index 000000000..45ab2fa2b --- /dev/null +++ b/pkg/macos/build.zig.zon @@ -0,0 +1,7 @@ +.{ + .name = "macos", + .version = "0.1.0", + .dependencies = .{ + .apple_sdk = .{ .path = "../apple-sdk" }, + }, +}