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