From 0021b290cf0961d3cd83c8dde9868fc85520a2f7 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 1 Oct 2023 18:43:25 -0700 Subject: [PATCH] pkg: add test targets --- pkg/fontconfig/build.zig | 11 +++++++++++ pkg/freetype/build.zig | 13 +++++++++++++ pkg/harfbuzz/build.zig | 21 +++++++++++++++++++-- pkg/macos/build.zig | 18 +++++++++++++++++- pkg/pixman/build.zig | 18 +++++++++++++++++- 5 files changed, 77 insertions(+), 4 deletions(-) diff --git a/pkg/fontconfig/build.zig b/pkg/fontconfig/build.zig index dec6d9c5e..bfdac3a33 100644 --- a/pkg/fontconfig/build.zig +++ b/pkg/fontconfig/build.zig @@ -170,6 +170,17 @@ pub fn build(b: *std.Build) !void { }); b.installArtifact(lib); + + const test_exe = b.addTest(.{ + .name = "test", + .root_source_file = .{ .path = "main.zig" }, + .target = target, + .optimize = optimize, + }); + test_exe.linkLibrary(lib); + const tests_run = b.addRunArtifact(test_exe); + const test_step = b.step("test", "Run tests"); + test_step.dependOn(&tests_run.step); } const headers = &.{ diff --git a/pkg/freetype/build.zig b/pkg/freetype/build.zig index fb31777bb..24006e17f 100644 --- a/pkg/freetype/build.zig +++ b/pkg/freetype/build.zig @@ -84,6 +84,19 @@ pub fn build(b: *std.Build) !void { }); b.installArtifact(lib); + + { + const test_exe = b.addTest(.{ + .name = "test", + .root_source_file = .{ .path = "main.zig" }, + .target = target, + .optimize = optimize, + }); + test_exe.linkLibrary(lib); + const tests_run = b.addRunArtifact(test_exe); + const test_step = b.step("test", "Run tests"); + test_step.dependOn(&tests_run.step); + } } const srcs: []const []const u8 = &.{ diff --git a/pkg/harfbuzz/build.zig b/pkg/harfbuzz/build.zig index 64487dfdf..2923f59ab 100644 --- a/pkg/harfbuzz/build.zig +++ b/pkg/harfbuzz/build.zig @@ -6,7 +6,7 @@ pub fn build(b: *std.Build) !void { const optimize = b.standardOptimizeOption(.{}); const coretext_enabled = b.option(bool, "enable-coretext", "Build coretext") orelse false; - const freetype_enabled = b.option(bool, "enable-freetype", "Build freetype") orelse false; + const freetype_enabled = b.option(bool, "enable-freetype", "Build freetype") orelse true; const freetype = b.dependency("freetype", .{ .target = target, @@ -15,7 +15,7 @@ pub fn build(b: *std.Build) !void { }); const macos = b.dependency("macos", .{ .target = target, .optimize = optimize }); - _ = b.addModule("harfbuzz", .{ + const module = b.addModule("harfbuzz", .{ .source_file = .{ .path = "main.zig" }, .dependencies = &.{ .{ .name = "freetype", .module = freetype.module("freetype") }, @@ -76,4 +76,21 @@ pub fn build(b: *std.Build) !void { }); b.installArtifact(lib); + + { + const test_exe = b.addTest(.{ + .name = "test", + .root_source_file = .{ .path = "main.zig" }, + .target = target, + .optimize = optimize, + }); + test_exe.linkLibrary(lib); + + var it = module.dependencies.iterator(); + while (it.next()) |entry| test_exe.addModule(entry.key_ptr.*, entry.value_ptr.*); + test_exe.linkLibrary(freetype_dep.artifact("freetype")); + const tests_run = b.addRunArtifact(test_exe); + const test_step = b.step("test", "Run tests"); + test_step.dependOn(&tests_run.step); + } } diff --git a/pkg/macos/build.zig b/pkg/macos/build.zig index 5a8f6fe54..aed7e5d28 100644 --- a/pkg/macos/build.zig +++ b/pkg/macos/build.zig @@ -6,7 +6,7 @@ pub fn build(b: *std.Build) !void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); - _ = b.addModule("macos", .{ .source_file = .{ .path = "main.zig" } }); + const module = b.addModule("macos", .{ .source_file = .{ .path = "main.zig" } }); const lib = b.addStaticLibrary(.{ .name = "macos", @@ -31,4 +31,20 @@ pub fn build(b: *std.Build) !void { try apple_sdk.addPaths(b, lib); b.installArtifact(lib); + + { + const test_exe = b.addTest(.{ + .name = "test", + .root_source_file = .{ .path = "main.zig" }, + .target = target, + .optimize = optimize, + }); + test_exe.linkLibrary(lib); + var it = module.dependencies.iterator(); + while (it.next()) |entry| test_exe.addModule(entry.key_ptr.*, entry.value_ptr.*); + + const tests_run = b.addRunArtifact(test_exe); + const test_step = b.step("test", "Run tests"); + test_step.dependOn(&tests_run.step); + } } diff --git a/pkg/pixman/build.zig b/pkg/pixman/build.zig index 3b0848aa5..ef2a91286 100644 --- a/pkg/pixman/build.zig +++ b/pkg/pixman/build.zig @@ -4,7 +4,7 @@ pub fn build(b: *std.Build) !void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); - _ = b.addModule("pixman", .{ .source_file = .{ .path = "main.zig" } }); + const module = b.addModule("pixman", .{ .source_file = .{ .path = "main.zig" } }); const upstream = b.dependency("pixman", .{}); const lib = b.addStaticLibrary(.{ @@ -66,6 +66,22 @@ pub fn build(b: *std.Build) !void { }); b.installArtifact(lib); + + { + const test_exe = b.addTest(.{ + .name = "test", + .root_source_file = .{ .path = "main.zig" }, + .target = target, + .optimize = optimize, + }); + test_exe.linkLibrary(lib); + var it = module.dependencies.iterator(); + while (it.next()) |entry| test_exe.addModule(entry.key_ptr.*, entry.value_ptr.*); + + const tests_run = b.addRunArtifact(test_exe); + const test_step = b.step("test", "Run tests"); + test_step.dependOn(&tests_run.step); + } } const srcs: []const []const u8 = &.{