diff --git a/pkg/macos/animation/c.zig b/pkg/macos/animation/c.zig index cfe6aacfc..1a7d1627e 100644 --- a/pkg/macos/animation/c.zig +++ b/pkg/macos/animation/c.zig @@ -1,3 +1 @@ -pub const c = @cImport({ - @cInclude("QuartzCore/CALayer.h"); -}); +pub const c = @import("../main.zig").c; diff --git a/pkg/macos/build.zig b/pkg/macos/build.zig index fcc1a2226..911664a2f 100644 --- a/pkg/macos/build.zig +++ b/pkg/macos/build.zig @@ -45,10 +45,8 @@ pub fn build(b: *std.Build) !void { module.linkFramework("CoreVideo", .{}); module.linkFramework("QuartzCore", .{}); - if (!target.query.isNative()) { - try apple_sdk.addPaths(b, lib.root_module); - try apple_sdk.addPaths(b, module); - } + try apple_sdk.addPaths(b, lib.root_module); + try apple_sdk.addPaths(b, module); } b.installArtifact(lib); @@ -59,9 +57,20 @@ pub fn build(b: *std.Build) !void { .target = target, .optimize = optimize, }); + if (target.result.os.tag.isDarwin()) { + try apple_sdk.addPaths(b, test_exe.root_module); + } test_exe.linkLibrary(lib); + var it = module.import_table.iterator(); - while (it.next()) |entry| test_exe.root_module.addImport(entry.key_ptr.*, entry.value_ptr.*); + while (it.next()) |entry| { + test_exe.root_module.addImport( + entry.key_ptr.*, + entry.value_ptr.*, + ); + } + + b.installArtifact(test_exe); const tests_run = b.addRunArtifact(test_exe); const test_step = b.step("test", "Run tests"); diff --git a/pkg/macos/build.zig.zon b/pkg/macos/build.zig.zon index 49defbed9..4c22ad7c1 100644 --- a/pkg/macos/build.zig.zon +++ b/pkg/macos/build.zig.zon @@ -1,6 +1,7 @@ .{ - .name = "macos", + .name = .macos, .version = "0.1.0", + .fingerprint = 0x45e2f6107d5b2b2c, .paths = .{""}, .dependencies = .{ .apple_sdk = .{ .path = "../apple-sdk" }, diff --git a/pkg/macos/carbon/c.zig b/pkg/macos/carbon/c.zig index 248af3c90..1a7d1627e 100644 --- a/pkg/macos/carbon/c.zig +++ b/pkg/macos/carbon/c.zig @@ -1,3 +1 @@ -pub const c = @cImport({ - @cInclude("Carbon/Carbon.h"); -}); +pub const c = @import("../main.zig").c; diff --git a/pkg/macos/dispatch/c.zig b/pkg/macos/dispatch/c.zig index 703bb4de6..1a7d1627e 100644 --- a/pkg/macos/dispatch/c.zig +++ b/pkg/macos/dispatch/c.zig @@ -1,3 +1 @@ -pub const c = @cImport({ - @cInclude("dispatch/dispatch.h"); -}); +pub const c = @import("../main.zig").c; diff --git a/pkg/macos/foundation/attributed_string.zig b/pkg/macos/foundation/attributed_string.zig index 2801a506d..de509b2c0 100644 --- a/pkg/macos/foundation/attributed_string.zig +++ b/pkg/macos/foundation/attributed_string.zig @@ -67,7 +67,7 @@ pub const MutableAttributedString = opaque { ) void { const T = @TypeOf(key); const info = @typeInfo(T); - const Key = if (info != .Pointer) T else info.Pointer.child; + const Key = if (info != .pointer) T else info.pointer.child; const key_arg = if (@hasDecl(Key, "key")) key.key() else diff --git a/pkg/macos/foundation/c.zig b/pkg/macos/foundation/c.zig index 22fe8c6e5..1a7d1627e 100644 --- a/pkg/macos/foundation/c.zig +++ b/pkg/macos/foundation/c.zig @@ -1,3 +1 @@ -pub const c = @cImport({ - @cInclude("CoreFoundation/CoreFoundation.h"); -}); +pub const c = @import("../main.zig").c; diff --git a/pkg/macos/graphics/bitmap_context.zig b/pkg/macos/graphics/bitmap_context.zig index 70d28b83a..7db5577f6 100644 --- a/pkg/macos/graphics/bitmap_context.zig +++ b/pkg/macos/graphics/bitmap_context.zig @@ -38,13 +38,13 @@ test { const cs = try graphics.ColorSpace.createDeviceGray(); defer cs.release(); const ctx = try BitmapContext.create(null, 80, 80, 8, 80, cs, 0); - defer ctx.release(); - - ctx.setShouldAntialias(true); - ctx.setShouldSmoothFonts(false); - ctx.setGrayFillColor(1, 1); - ctx.setGrayStrokeColor(1, 1); - ctx.setTextDrawingMode(.fill); - ctx.setTextMatrix(graphics.AffineTransform.identity()); - ctx.setTextPosition(0, 0); + const context = BitmapContext.context; + defer context.release(ctx); + context.setShouldAntialias(ctx, true); + context.setShouldSmoothFonts(ctx, false); + context.setGrayFillColor(ctx, 1, 1); + context.setGrayStrokeColor(ctx, 1, 1); + context.setTextDrawingMode(ctx, .fill); + context.setTextMatrix(ctx, graphics.AffineTransform.identity()); + context.setTextPosition(ctx, 0, 0); } diff --git a/pkg/macos/graphics/c.zig b/pkg/macos/graphics/c.zig index c47b271a2..1a7d1627e 100644 --- a/pkg/macos/graphics/c.zig +++ b/pkg/macos/graphics/c.zig @@ -1,3 +1 @@ -pub const c = @cImport({ - @cInclude("CoreGraphics/CoreGraphics.h"); -}); +pub const c = @import("../main.zig").c; diff --git a/pkg/macos/graphics/path.zig b/pkg/macos/graphics/path.zig index 1dea355ea..7f549709d 100644 --- a/pkg/macos/graphics/path.zig +++ b/pkg/macos/graphics/path.zig @@ -3,7 +3,7 @@ const assert = std.debug.assert; const Allocator = std.mem.Allocator; const foundation = @import("../foundation.zig"); const graphics = @import("../graphics.zig"); -const c = @import("c.zig"); +const c = @import("c.zig").c; pub const Path = opaque { pub fn createWithRect( diff --git a/pkg/macos/main.zig b/pkg/macos/main.zig index ef244fc78..d094b987e 100644 --- a/pkg/macos/main.zig +++ b/pkg/macos/main.zig @@ -1,3 +1,5 @@ +const builtin = @import("builtin"); + pub const carbon = @import("carbon.zig"); pub const foundation = @import("foundation.zig"); pub const animation = @import("animation.zig"); @@ -7,6 +9,23 @@ pub const os = @import("os.zig"); pub const text = @import("text.zig"); pub const video = @import("video.zig"); +// All of our C imports consolidated into one place. We used to +// import them one by one in each package but Zig 0.14 has some +// kind of issue with that I wasn't able to minimize. +pub const c = @cImport({ + @cInclude("CoreFoundation/CoreFoundation.h"); + @cInclude("CoreGraphics/CoreGraphics.h"); + @cInclude("CoreText/CoreText.h"); + @cInclude("CoreVideo/CoreVideo.h"); + @cInclude("QuartzCore/CALayer.h"); + @cInclude("dispatch/dispatch.h"); + @cInclude("os/log.h"); + + if (builtin.os.tag == .macos) { + @cInclude("Carbon/Carbon.h"); + } +}); + test { @import("std").testing.refAllDecls(@This()); } diff --git a/pkg/macos/os/c.zig b/pkg/macos/os/c.zig index c0d88e866..1a7d1627e 100644 --- a/pkg/macos/os/c.zig +++ b/pkg/macos/os/c.zig @@ -1,3 +1 @@ -pub const c = @cImport({ - @cInclude("os/log.h"); -}); +pub const c = @import("../main.zig").c; diff --git a/pkg/macos/text/c.zig b/pkg/macos/text/c.zig index e8608d6d0..1a7d1627e 100644 --- a/pkg/macos/text/c.zig +++ b/pkg/macos/text/c.zig @@ -1,3 +1 @@ -pub const c = @cImport({ - @cInclude("CoreText/CoreText.h"); -}); +pub const c = @import("../main.zig").c; diff --git a/pkg/macos/text/font.zig b/pkg/macos/text/font.zig index 6423d82ea..383861d62 100644 --- a/pkg/macos/text/font.zig +++ b/pkg/macos/text/font.zig @@ -280,7 +280,8 @@ test { const cs = try graphics.ColorSpace.createDeviceGray(); defer cs.release(); const ctx = try graphics.BitmapContext.create(null, 80, 80, 8, 80, cs, 0); - defer ctx.release(); + const context = graphics.BitmapContext.context; + defer context.release(ctx); var pos = [_]graphics.Point{.{ .x = 0, .y = 0 }}; font.drawGlyphs( diff --git a/pkg/macos/text/font_descriptor.zig b/pkg/macos/text/font_descriptor.zig index 3b4928a6e..563165bc7 100644 --- a/pkg/macos/text/font_descriptor.zig +++ b/pkg/macos/text/font_descriptor.zig @@ -276,7 +276,7 @@ test "descriptor" { const v = try FontDescriptor.createWithNameAndSize(name, 12); defer v.release(); - const copy_name = v.copyAttribute(.name); + const copy_name = v.copyAttribute(.name).?; defer copy_name.release(); { diff --git a/pkg/macos/video/c.zig b/pkg/macos/video/c.zig index d99b1aeb6..1a7d1627e 100644 --- a/pkg/macos/video/c.zig +++ b/pkg/macos/video/c.zig @@ -1,3 +1 @@ -pub const c = @cImport({ - @cInclude("CoreVideo/CoreVideo.h"); -}); +pub const c = @import("../main.zig").c;