╭ 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 const initial_pages = 16; 31 const max_pages = 256; 32 exe.initial_memory = std.wasm.page_size * initial_pages; 33 exe.max_memory = std.wasm.page_size * max_pages; 34 35 const install_exe = b.addInstallArtifact(exe, .{}); 36 b.getInstallStep().dependOn(&install_exe.step); 37 38 const wasm_step = b.step("wasm", "Generate the wasm"); 39 wasm_step.dependOn(&install_exe.step); 40 41 break :blk install_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 .optimize = optimize, 55 }), 56 .use_llvm = true, 57 }); 58 exe.root_module.addImport("xit", xit_dep.module("xit")); 59 exe.step.dependOn(&install_wasm_exe.step); 60 61 const install_exe = b.addInstallArtifact(exe, .{}); 62 b.getInstallStep().dependOn(&install_exe.step); 63 64 break :blk install_exe; 65 }; 66 67 // test 68 { 69 const unit_tests = b.addTest(.{ 70 .root_module = b.createModule(.{ 71 .root_source_file = b.path("src/test.zig"), 72 .target = target, 73 .optimize = optimize, 74 }), 75 }); 76 unit_tests.root_module.addImport("xit", xit_dep.module("xit")); 77 78 const run_unit_tests = b.addRunArtifact(unit_tests); 79 run_unit_tests.has_side_effects = true; 80 const test_step = b.step("test", "Run unit tests"); 81 test_step.dependOn(&install_main_exe.step); 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 92 // try 93 { 94 const exe = b.addExecutable(.{ 95 .name = "try", 96 .root_module = b.createModule(.{ 97 .root_source_file = b.path("src/try.zig"), 98 .target = target, 99 .optimize = optimize, 100 }), 101 }); 102 exe.root_module.addImport("haxy", haxy); 103 b.installArtifact(exe); 104 105 const run_cmd = b.addRunArtifact(exe); 106 run_cmd.step.dependOn(b.getInstallStep()); 107 if (b.args) |args| { 108 run_cmd.addArgs(args); 109 } 110 111 const run_step = b.step("try", "Try the app"); 112 run_step.dependOn(&run_cmd.step); 113 } 114 115 // testnet 116 { 117 const unit_tests = b.addTest(.{ 118 .root_module = b.createModule(.{ 119 .root_source_file = b.path("src/testnet.zig"), 120 .target = target, 121 .optimize = optimize, 122 }), 123 }); 124 unit_tests.root_module.addImport("haxy", haxy); 125 126 const run_unit_tests = b.addRunArtifact(unit_tests); 127 run_unit_tests.has_side_effects = true; 128 const test_step = b.step("testnet", "Run network unit tests"); 129 test_step.dependOn(&install_main_exe.step); 130 test_step.dependOn(&run_unit_tests.step); 131 } 132 } 133