╭ 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 const install_main_exe = blk: { 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 break :blk install_exe; 68 }; 69 70 // test 71 { 72 const unit_tests = b.addTest(.{ 73 .root_module = b.createModule(.{ 74 .root_source_file = b.path("src/test.zig"), 75 .target = target, 76 .optimize = optimize, 77 }), 78 }); 79 unit_tests.root_module.addImport("xit", xit_dep.module("xit")); 80 81 const run_unit_tests = b.addRunArtifact(unit_tests); 82 run_unit_tests.has_side_effects = true; 83 const test_step = b.step("test", "Run unit tests"); 84 test_step.dependOn(&run_unit_tests.step); 85 } 86 87 // module for using haxy as a library 88 // (the commands below consume haxy this way) 89 const haxy = b.addModule("haxy", .{ 90 .root_source_file = b.path("src/lib.zig"), 91 }); 92 haxy.addImport("xit", xit_dep.module("xit")); 93 haxy.addAnonymousImport("haxy.wasm", .{ 94 .root_source_file = wasm_exe.getEmittedBin(), 95 }); 96 97 // try 98 { 99 const exe = b.addExecutable(.{ 100 .name = "try", 101 .root_module = b.createModule(.{ 102 .root_source_file = b.path("src/try.zig"), 103 .target = target, 104 .optimize = optimize, 105 }), 106 }); 107 exe.root_module.addImport("haxy", haxy); 108 const try_install = b.addInstallArtifact(exe, .{}); 109 110 const run_cmd = b.addRunArtifact(exe); 111 run_cmd.step.dependOn(&try_install.step); 112 if (b.args) |args| { 113 run_cmd.addArgs(args); 114 } 115 116 const run_step = b.step("try", "Try the app"); 117 run_step.dependOn(&run_cmd.step); 118 } 119 120 // testnet 121 { 122 const unit_tests = b.addTest(.{ 123 .root_module = b.createModule(.{ 124 .root_source_file = b.path("src/testnet.zig"), 125 .target = target, 126 .optimize = optimize, 127 }), 128 }); 129 unit_tests.root_module.addImport("haxy", haxy); 130 131 const run_unit_tests = b.addRunArtifact(unit_tests); 132 run_unit_tests.has_side_effects = true; 133 run_unit_tests.step.dependOn(&install_main_exe.step); 134 const test_step = b.step("testnet", "Run network unit tests"); 135 test_step.dependOn(&run_unit_tests.step); 136 } 137 } 138