╭ 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 }); 57 exe.root_module.addImport("xit", xit_dep.module("xit")); 58 exe.step.dependOn(&install_wasm_exe.step); 59 60 const install_exe = b.addInstallArtifact(exe, .{}); 61 b.getInstallStep().dependOn(&install_exe.step); 62 63 const run_cmd = b.addRunArtifact(exe); 64 65 run_cmd.step.dependOn(b.getInstallStep()); 66 67 if (b.args) |args| { 68 run_cmd.addArgs(args); 69 } 70 71 const run_step = b.step("run", "Run the app"); 72 run_step.dependOn(&run_cmd.step); 73 74 break :blk install_exe; 75 }; 76 77 // module for using haxy as a library 78 // (the commands below consume haxy this way) 79 const haxy = b.addModule("haxy", .{ 80 .root_source_file = b.path("src/lib.zig"), 81 }); 82 haxy.addImport("xit", xit_dep.module("xit")); 83 84 // test 85 { 86 const unit_tests = b.addTest(.{ 87 .root_module = b.createModule(.{ 88 .root_source_file = b.path("src/test.zig"), 89 .target = target, 90 .optimize = optimize, 91 }), 92 }); 93 unit_tests.root_module.addImport("haxy", haxy); 94 95 const run_unit_tests = b.addRunArtifact(unit_tests); 96 run_unit_tests.has_side_effects = true; 97 const test_step = b.step("test", "Run unit tests"); 98 test_step.dependOn(&install_main_exe.step); 99 test_step.dependOn(&run_unit_tests.step); 100 } 101 102 // testnet 103 { 104 const unit_tests = b.addTest(.{ 105 .root_module = b.createModule(.{ 106 .root_source_file = b.path("src/testnet.zig"), 107 .target = target, 108 .optimize = optimize, 109 }), 110 }); 111 unit_tests.root_module.addImport("haxy", haxy); 112 113 const run_unit_tests = b.addRunArtifact(unit_tests); 114 run_unit_tests.has_side_effects = true; 115 const test_step = b.step("testnet", "Run network unit tests"); 116 test_step.dependOn(&install_main_exe.step); 117 test_step.dependOn(&run_unit_tests.step); 118 } 119 } 120