const std = @import("std"); const Build = std.Build; const Module = Build.Module; const Import = Module.Import; const Dir = std.Io.Dir; pub fn build(b: *Build) !void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); const infrared = b.addModule("infrared", .{ .root_source_file = b.path("infrared/root.zig"), .target = target, .optimize = optimize, }); try addTest(b, "infrared", infrared); const matte = b.addModule("matte", .{ .root_source_file = b.path("matte/root.zig"), .target = target, .imports = &.{ import("infrared", infrared), }, }); try addTest(b, "matte", matte); const black_tea = b.addModule("blacktea", .{ .root_source_file = b.path("blacktea/root.zig"), .target = target, .link_libc = true, }); try addTest(b, "blacktea", black_tea); const buds = b.addModule("buds", .{ .root_source_file = b.path("buds/root.zig"), .target = target, .imports = &.{ import("blacktea", black_tea), import("matte", matte), }, }); try addTest(b, "buds", buds); const zli = b.addModule("zli", .{ .root_source_file = b.path("zli/root.zig"), .target = target, .optimize = optimize, .imports = &.{ import("matte", matte), }, }); try addTest(b, "zli", zli); const c = b.addTranslateC(.{ .root_source_file = b.path("curse/libssh.h"), .target = target, .optimize = optimize, }); c.linkSystemLibrary("libssh", .{ .use_pkg_config = .yes, .needed = true, .preferred_link_mode = .dynamic, }); const libssh = c.createModule(); const curse = b.addModule("curse", .{ .root_source_file = b.path("curse/root.zig"), .target = target, .optimize = optimize, .link_libc = true, .imports = &.{ import("blacktea", black_tea), import("zli", zli), import("libssh", libssh), import("infrared", infrared), }, }); try addTest(b, "curse", curse); const demo = b.addExecutable(.{ .name = "demo", .linkage = .dynamic, .version = .{ .major = 0, .minor = 0, .patch = 0 }, .root_module = b.createModule( .{ .root_source_file = b.path("demo/main.zig"), .target = target, .optimize = optimize, .link_libc = true, .imports = &.{ import("matte", matte), import("buds", buds), import("blacktea", black_tea), import("curse", curse), import("zli", zli), import("libssh", libssh), }, }, ), }); const demo_step = b.step("demo", "run demo"); demo_step.dependOn(&b.addInstallArtifact(demo, .{}).step); b.installArtifact(demo); const run_step = b.step("run", "Run the app"); const run_cmd = b.addRunArtifact(demo); run_step.dependOn(&run_cmd.step); run_cmd.step.dependOn(b.getInstallStep()); if (b.args) |args| { run_cmd.addArgs(args); } } fn import(name: []const u8, module: *Module) Import { return .{ .name = name, .module = module }; } fn addTest(b: *Build, name: []const u8, module: *Module) !void { const step = if (b.top_level_steps.get("test")) |tls| &tls.step else b.step("test", "Run tests"); const test_module = b.addTest(.{ .name = name, .root_module = module, .filters = try testFilters(b), }); const artifact = b.addRunArtifact(test_module); step.dependOn(&artifact.step); } fn testFilters(b: *Build) ![]const []const u8 { if (!b.available_options_map.contains("test-filter")) return b.option( []const []const u8, "test-filter", "Skip tests that do not match any filter", ) orelse &.{}; const opt = b.user_input_options.getPtr("test-filter") orelse return &.{}; opt.used = true; return switch (opt.value) { .list => |l| l.items, .scalar => |s| try b.allocator.dupe([]const u8, &.{s}), else => &.{}, }; }