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