╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ build.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯
115 run_cmd.step.dependOn(&try_install.step); 116 run_cmd.addPassthruArgs(); 117 118 const run_step = b.step("try", "Try the app"); 119 run_step.dependOn(&run_cmd.step); 120 } 121 122 // testnet 123 { 124 const server_exe = b.addExecutable(.{ 125 .name = "haxy", 126 .root_module = b.createModule(.{ 127 .root_source_file = b.path("src/main.zig"), 128 .target = target, 129 .optimize = .debug, 130 }), 131 .use_llvm = true, 132 }); 133 server_exe.root_module.addImport("xit", xit_dep.module("xit")); 134 server_exe.root_module.addImport("ansi_art", ansi_art); 135 server_exe.root_module.addAnonymousImport("haxy.wasm", .{ 136 .root_source_file = wasm_exe.getEmittedBin(), 137 }); 138 const install_server_exe = b.addInstallArtifact(server_exe, .{}); 139 140 const unit_tests = b.addTest(.{ 141 .root_module = b.createModule(.{ 142 .root_source_file = b.path("src/testnet.zig"), 143 .target = target, 144 .optimize = optimize, 145 }), 146 .filters = test_filters, 147 }); 148 unit_tests.root_module.addImport("haxy", haxy); 149 150 const run_unit_tests = b.addRunArtifact(unit_tests); 151 run_unit_tests.has_side_effects = true; 152 run_unit_tests.step.dependOn(&install_server_exe.step); 153 const test_step = b.step("testnet", "Run network unit tests"); 154 test_step.dependOn(&run_unit_tests.step); 155 } 156 } 157 158 // reads every ANSI-art text file while configuring the build. sorting keeps 159 // the generated module stable when directory iteration order changes. 160 fn ansiArtModule(b: *std.Build) *std.Build.Module { 161 const io = b.graph.io; 162 b.dependOnDirectoryContents(b.path("src/embed/ansi")); 163 b.dependOnFileContents(b.path("src/embed/not-found.txt")); 164 var dir = b.root.openDir(io, "src/embed/ansi", .{ .iterate = true }) catch |err| { 165 std.debug.panic("unable to open src/embed/ansi: {t}", .{err}); 166 }; 167 defer dir.close(io); 168 169 var names: std.ArrayList([]const u8) = .empty; 170 var iter = dir.iterate(); 171 while (iter.next(io) catch |err| std.debug.panic("unable to read src/embed/ansi: {t}", .{err})) |entry| { 172 if (entry.kind != .file or !std.mem.endsWith(u8, entry.name, ".txt")) continue; 173 names.append(b.allocator, b.graph.dupeString(entry.name)) catch @panic("OOM"); 174 } 175 std.mem.sort([]const u8, names.items, {}, struct { 176 fn lessThan(_: void, lhs: []const u8, rhs: []const u8) bool { 177 return std.mem.order(u8, lhs, rhs) == .lt; 178 } 179 }.lessThan); 180 if (names.items.len == 0) @panic("src/embed/ansi must contain at least one .txt file"); 181 182 const contents = b.allocator.alloc([]const u8, names.items.len) catch @panic("OOM"); 183 for (names.items, contents) |name, *content| { 184 b.dependOnFileContents(b.path(b.fmt("src/embed/ansi/{s}", .{name}))); 185 content.* = dir.readFileAlloc(io, name, b.allocator, .limited(16 * 1024 * 1024)) catch |err| { 186 std.debug.panic("unable to read src/embed/ansi/{s}: {t}", .{ name, err }); 187 }; 188 } 189 190 var embed_dir = b.root.openDir(io, "src/embed", .{}) catch unreachable; 191 defer embed_dir.close(io); 192 const not_found = embed_dir.readFileAlloc(io, "not-found.txt", b.allocator, .limited(16 * 1024 * 1024)) catch unreachable; 193 194 const options = b.addOptions(); 195 options.addOption([]const []const u8, "art", contents); 196 options.addOption([]const u8, "not_found", not_found); 197 return options.createModule(); 198 } 199