╭ 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 install_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.global_base = 6560; 24 exe.entry = .disabled; 25 exe.rdynamic = true; 26 exe.import_memory = false; 27 exe.export_memory = true; 28 exe.stack_size = std.wasm.page_size; 29 30 // start small and let the allocator grow on demand up to wasm32's 31 // architectural ceiling (65536 pages = 4 GiB) 32 const initial_pages = 16; 33 const max_pages = 65536; 34 exe.initial_memory = std.wasm.page_size * initial_pages; 35 exe.max_memory = std.wasm.page_size * max_pages; 36 37 const install_exe = b.addInstallArtifact(exe, .{}); 38 b.getInstallStep().dependOn(&install_exe.step); 39 40 const wasm_step = b.step("wasm", "Generate the wasm"); 41 wasm_step.dependOn(&install_exe.step); 42 43 // windows can't follow symlinks, so copy the wasm file to the embed dir 44 if (.windows == @import("builtin").os.tag) { 45 const copy_wasm = b.addUpdateSourceFiles(); 46 copy_wasm.addCopyFileToSource(exe.getEmittedBin(), "src/embed/haxy.wasm"); 47 b.getInstallStep().dependOn(&copy_wasm.step); 48 break :blk copy_wasm; 49 } 50 51 break :blk install_exe; 52 }; 53 54 const target = b.standardTargetOptions(.{}); 55 const optimize = b.standardOptimizeOption(.{}); 56 57 // main 58 const install_main_exe = blk: { 59 const exe = b.addExecutable(.{ 60 .name = "haxy", 61 .root_module = b.createModule(.{ 62 .root_source_file = b.path("src/main.zig"), 63 .target = target, 64 .optimize = optimize, 65 }), 66 .use_llvm = true, 67 }); 68 exe.root_module.addImport("xit", xit_dep.module("xit")); 69 exe.step.dependOn(&install_wasm_exe.step); 70 71 const install_exe = b.addInstallArtifact(exe, .{}); 72 b.getInstallStep().dependOn(&install_exe.step); 73 74 break :blk install_exe; 75 }; 76 77 // test 78 { 79 const unit_tests = b.addTest(.{ 80 .root_module = b.createModule(.{ 81 .root_source_file = b.path("src/test.zig"), 82 .target = target, 83 .optimize = optimize, 84 }), 85 }); 86 unit_tests.root_module.addImport("xit", xit_dep.module("xit")); 87 88 const run_unit_tests = b.addRunArtifact(unit_tests); 89 run_unit_tests.has_side_effects = true; 90 const test_step = b.step("test", "Run unit tests"); 91 test_step.dependOn(&run_unit_tests.step); 92 } 93 94 // module for using haxy as a library 95 // (the commands below consume haxy this way) 96 const haxy = b.addModule("haxy", .{ 97 .root_source_file = b.path("src/lib.zig"), 98 }); 99 haxy.addImport("xit", xit_dep.module("xit")); 100 101 // try 102 { 103 const exe = b.addExecutable(.{ 104 .name = "try", 105 .root_module = b.createModule(.{ 106 .root_source_file = b.path("src/try.zig"), 107 .target = target, 108 .optimize = optimize, 109 }), 110 }); 111 exe.root_module.addImport("haxy", haxy); 112 exe.step.dependOn(&install_wasm_exe.step); 113 b.installArtifact(exe); 114 115 const run_cmd = b.addRunArtifact(exe); 116 run_cmd.step.dependOn(b.getInstallStep()); 117 if (b.args) |args| { 118 run_cmd.addArgs(args); 119 } 120 121 const run_step = b.step("try", "Try the app"); 122 run_step.dependOn(&run_cmd.step); 123 } 124 125 // testnet 126 { 127 const unit_tests = b.addTest(.{ 128 .root_module = b.createModule(.{ 129 .root_source_file = b.path("src/testnet.zig"), 130 .target = target, 131 .optimize = optimize, 132 }), 133 }); 134 unit_tests.root_module.addImport("haxy", haxy); 135 136 const run_unit_tests = b.addRunArtifact(unit_tests); 137 run_unit_tests.has_side_effects = true; 138 const test_step = b.step("testnet", "Run network unit tests"); 139 test_step.dependOn(&install_main_exe.step); 140 test_step.dependOn(&run_unit_tests.step); 141 } 142 } 143