╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ build.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
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 39 const wasm_step = b.step("wasm", "Generate the wasm"); 40 wasm_step.dependOn(&install_exe.step); 41 42 break :blk exe; 43 }; 44 45 const target = b.standardTargetOptions(.{}); 46 const optimize = b.standardOptimizeOption(.{}); 47 48 // main 49 const install_main_exe = blk: { 50 const exe = b.addExecutable(.{ 51 .name = "haxy", 52 .root_module = b.createModule(.{ 53 .root_source_file = b.path("src/main.zig"), 54 .target = target, 55 // default to ReleaseSafe unless an explicit -Doptimize is passed 56 .optimize = if (b.user_input_options.contains("optimize")) optimize else .ReleaseSafe, 57 }), 58 .use_llvm = true, 59 }); 60 exe.root_module.addImport("xit", xit_dep.module("xit")); 61 exe.root_module.addAnonymousImport("haxy.wasm", .{ 62 .root_source_file = wasm_exe.getEmittedBin(), 63 }); 64 65 const install_exe = b.addInstallArtifact(exe, .{}); 66 b.getInstallStep().dependOn(&install_exe.step); 67 68 break :blk install_exe; 69 }; 70 71 // test 72 { 73 const unit_tests = b.addTest(.{ 74 .root_module = b.createModule(.{ 75 .root_source_file = b.path("src/test.zig"), 76 .target = target, 77 .optimize = optimize, 78 }), 79 }); 80 unit_tests.root_module.addImport("xit", xit_dep.module("xit")); 81 82 const run_unit_tests = b.addRunArtifact(unit_tests); 83 run_unit_tests.has_side_effects = true; 84 const test_step = b.step("test", "Run unit tests"); 85 test_step.dependOn(&run_unit_tests.step); 86 } 87 88 // module for using haxy as a library 89 // (the commands below consume haxy this way) 90 const haxy = b.addModule("haxy", .{ 91 .root_source_file = b.path("src/lib.zig"), 92 }); 93 haxy.addImport("xit", xit_dep.module("xit")); 94 haxy.addAnonymousImport("haxy.wasm", .{ 95 .root_source_file = wasm_exe.getEmittedBin(), 96 }); 97 98 // try 99 { 100 const exe = b.addExecutable(.{ 101 .name = "try", 102 .root_module = b.createModule(.{ 103 .root_source_file = b.path("src/try.zig"), 104 .target = target, 105 .optimize = optimize, 106 }), 107 }); 108 exe.root_module.addImport("haxy", haxy); 109 const try_install = b.addInstallArtifact(exe, .{}); 110 111 const run_cmd = b.addRunArtifact(exe); 112 run_cmd.step.dependOn(&try_install.step); 113 if (b.args) |args| { 114 run_cmd.addArgs(args); 115 } 116 117 const run_step = b.step("try", "Try the app"); 118 run_step.dependOn(&run_cmd.step); 119 } 120 121 // testnet 122 { 123 const unit_tests = b.addTest(.{ 124 .root_module = b.createModule(.{ 125 .root_source_file = b.path("src/testnet.zig"), 126 .target = target, 127 .optimize = optimize, 128 }), 129 }); 130 unit_tests.root_module.addImport("haxy", haxy); 131 132 const run_unit_tests = b.addRunArtifact(unit_tests); 133 run_unit_tests.has_side_effects = true; 134 const test_step = b.step("testnet", "Run network unit tests"); 135 test_step.dependOn(&install_main_exe.step); 136 test_step.dependOn(&run_unit_tests.step); 137 } 138 } 139