╭ build.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1 const std = @import("std"); 2 3 pub fn build(b: *std.Build) void { 4 const xit_dep = b.dependency("xit", .{}); 5 6 // wasm 7 const wasm_exe = blk: { 8 const wasm_target = b.resolveTargetQuery(.{ 9 .cpu_arch = .wasm32, 10 .os_tag = .freestanding, 11 }); 12 13 const exe = b.addExecutable(.{ 14 .name = "haxy", 15 .root_module = b.createModule(.{ 16 .root_source_file = b.path("src/main_wasm.zig"), 17 .target = wasm_target, 18 .optimize = .ReleaseSmall, 19 }), 20 }); 21 exe.root_module.addImport("xit", xit_dep.module("xit")); 22 23 exe.entry = .disabled; 24 exe.rdynamic = true; 25 exe.import_memory = false; 26 exe.export_memory = true; 27 exe.stack_size = std.wasm.page_size * 8; 28 29 // start small and let the allocator grow on demand up to wasm32's 30 // architectural ceiling (65536 pages = 4 GiB) 31 const initial_pages = 16; 32 const max_pages = 65536; 33 exe.initial_memory = std.wasm.page_size * initial_pages; 34 exe.max_memory = std.wasm.page_size * max_pages; 35 36 const install_exe = b.addInstallArtifact(exe, .{}); 37 38 const wasm_step = b.step("wasm", "Generate the wasm"); 39 wasm_step.dependOn(&install_exe.step); 40 41 break :blk exe; 42 }; 43 44 const target = b.standardTargetOptions(.{}); 45 const optimize = b.standardOptimizeOption(.{}); 46 47 // main 48 { 49 const exe = b.addExecutable(.{ 50 .name = "haxy", 51 .root_module = b.createModule(.{ 52 .root_source_file = b.path("src/main.zig"), 53 .target = target, 54 // default to ReleaseSafe unless an explicit -Doptimize is passed 55 .optimize = if (b.user_input_options.contains("optimize")) optimize else .ReleaseSafe, 56 }), 57 .use_llvm = true, 58 }); 59 exe.root_module.addImport("xit", xit_dep.module("xit")); 60 exe.root_module.addAnonymousImport("haxy.wasm", .{ 61 .root_source_file = wasm_exe.getEmittedBin(), 62 }); 63 64 const install_exe = b.addInstallArtifact(exe, .{}); 65 b.getInstallStep().dependOn(&install_exe.step); 66 } 67 68 // test 69 { 70 const unit_tests = b.addTest(.{ 71 .root_module = b.createModule(.{ 72 .root_source_file = b.path("src/test.zig"), 73 .target = target, 74 .optimize = optimize, 75 }), 76 }); 77 unit_tests.root_module.addImport("xit", xit_dep.module("xit")); 78 79 const run_unit_tests = b.addRunArtifact(unit_tests); 80 run_unit_tests.has_side_effects = true; 81 const test_step = b.step("test", "Run unit tests"); 82 test_step.dependOn(&run_unit_tests.step); 83 } 84 85 // module for using haxy as a library 86 // (the commands below consume haxy this way) 87 const haxy = b.addModule("haxy", .{ 88 .root_source_file = b.path("src/lib.zig"), 89 }); 90 haxy.addImport("xit", xit_dep.module("xit")); 91 haxy.addAnonymousImport("haxy.wasm", .{ 92 .root_source_file = wasm_exe.getEmittedBin(), 93 }); 94 95 // try 96 { 97 const exe = b.addExecutable(.{ 98 .name = "try", 99 .root_module = b.createModule(.{ 100 .root_source_file = b.path("src/try.zig"), 101 .target = target, 102 .optimize = optimize, 103 }), 104 }); 105 exe.root_module.addImport("haxy", haxy); 106 const try_install = b.addInstallArtifact(exe, .{}); 107 108 const run_cmd = b.addRunArtifact(exe); 109 run_cmd.step.dependOn(&try_install.step); 110 if (b.args) |args| { 111 run_cmd.addArgs(args); 112 } 113 114 const run_step = b.step("try", "Try the app"); 115 run_step.dependOn(&run_cmd.step); 116 } 117 118 // testnet 119 { 120 const server_exe = b.addExecutable(.{ 121 .name = "haxy", 122 .root_module = b.createModule(.{ 123 .root_source_file = b.path("src/main.zig"), 124 .target = target, 125 .optimize = .Debug, 126 }), 127 .use_llvm = true, 128 }); 129 server_exe.root_module.addImport("xit", xit_dep.module("xit")); 130 server_exe.root_module.addAnonymousImport("haxy.wasm", .{ 131 .root_source_file = wasm_exe.getEmittedBin(), 132 }); 133 const install_server_exe = b.addInstallArtifact(server_exe, .{}); 134 135 const unit_tests = b.addTest(.{ 136 .root_module = b.createModule(.{ 137 .root_source_file = b.path("src/testnet.zig"), 138 .target = target, 139 .optimize = optimize, 140 }), 141 }); 142 unit_tests.root_module.addImport("haxy", haxy); 143 144 const run_unit_tests = b.addRunArtifact(unit_tests); 145 run_unit_tests.has_side_effects = true; 146 run_unit_tests.step.dependOn(&install_server_exe.step); 147 const test_step = b.step("testnet", "Run network unit tests"); 148 test_step.dependOn(&run_unit_tests.step); 149 } 150 } 151