╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ build.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
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 const test_step = b.step("testnet", "Run network unit tests"); 134 test_step.dependOn(&install_main_exe.step); 135 test_step.dependOn(&run_unit_tests.step); 136 } 137 } 138