From 581af823355180a5ff0b0f822174b1c993dd551e Mon Sep 17 00:00:00 2001 From: jiacai2050 Date: Sat, 21 Oct 2023 00:16:55 +0800 Subject: [PATCH] fix build --- build.zig | 30 +++++++++++++++---- .../{pretty_table.zig => pretty-table.zig} | 0 2 files changed, 25 insertions(+), 5 deletions(-) rename src/mod/{pretty_table.zig => pretty-table.zig} (100%) diff --git a/build.zig b/build.zig index 04ea1a4..c676b4a 100644 --- a/build.zig +++ b/build.zig @@ -23,7 +23,7 @@ pub fn build(b: *Build) void { b.modules.put("build_info", opt.createModule()) catch @panic("OOM"); b.modules.put("simargs", simargs_dep.module("simargs")) catch @panic("OOM"); _ = b.addModule("pretty-table", .{ - .source_file = .{ .path = "src/mod/pretty_table.zig" }, + .source_file = .{ .path = "src/mod/pretty-table.zig" }, }); const is_ci = b.option(bool, "is_ci", "Build in CI") orelse false; @@ -41,6 +41,13 @@ const Source = union(enum) { .mod => |v| v, }; } + + fn path(self: Self) []const u8 { + return switch (self) { + .bin => |_| "bin", + .mod => |_| "mod", + }; + } }; fn buildBinariesAndModules( @@ -62,7 +69,14 @@ fn buildBinariesAndModules( } const test_all_step = b.step("test", "Run all tests"); - test_all_step.dependOn(buildTestStep(b, "util", target)); + // TODO: move util out of `bin` + test_all_step.dependOn(buildTestStep(b, .{ .bin = "util" }, target)); + + inline for (.{ + "pretty-table", + }) |name| { + test_all_step.dependOn(buildTestStep(b, .{ .mod = name }, target)); + } for (all_tests.items) |step| { test_all_step.dependOn(step); } @@ -91,13 +105,19 @@ fn buildBinaries( b.step("run-" ++ prog_name, "Run " ++ prog_name) .dependOn(&run_cmd.step); - all_tests.append(buildTestStep(b, prog_name, target)) catch @panic("OOM"); + all_tests.append(buildTestStep(b, source, target)) catch @panic("OOM"); } } -fn buildTestStep(b: *std.Build, comptime name: []const u8, target: std.zig.CrossTarget) *Build.Step { +fn buildTestStep( + b: *std.Build, + comptime source: Source, + target: std.zig.CrossTarget, +) *Build.Step { + const name = comptime source.name(); + const path = comptime source.path(); const exe_tests = b.addTest(.{ - .root_source_file = .{ .path = "src/bin/" ++ name ++ ".zig" }, + .root_source_file = .{ .path = "src/" ++ path ++ "/" ++ name ++ ".zig" }, .target = target, }); const test_step = b.step("test-" ++ name, "Run " ++ name ++ " tests"); diff --git a/src/mod/pretty_table.zig b/src/mod/pretty-table.zig similarity index 100% rename from src/mod/pretty_table.zig rename to src/mod/pretty-table.zig