|
| 1 | +// File: build.zig |
| 2 | +// Created Time: 2023-01-07 |
| 3 | +// Author: sjinzh (sjinzh@gmail.com) |
| 4 | + |
| 5 | +const std = @import("std"); |
| 6 | + |
| 7 | +// Zig Version: 0.11.0-dev.3944+2e424e019 |
| 8 | +// Zig Build Command: zig build -Doptimize=ReleaseFast |
| 9 | +// Zig Run Command: zig build run_* -Doptimize=ReleaseFast |
| 10 | +pub fn build(b: *std.Build) void { |
| 11 | + const target = b.standardTargetOptions(.{}); |
| 12 | + const optimize = b.standardOptimizeOption(.{}); |
| 13 | + |
| 14 | + const group_name_path = .{ |
| 15 | + // Source File: "chapter_computational_complexity/time_complexity.zig" |
| 16 | + // Run Command: zig build run_time_complexity -Doptimize=ReleaseFast |
| 17 | + .{ .name = "time_complexity", .path = "chapter_computational_complexity/time_complexity.zig" }, |
| 18 | + |
| 19 | + // Source File: "chapter_computational_complexity/worst_best_time_complexity.zig" |
| 20 | + // Run Command: zig build run_worst_best_time_complexity -Doptimize=ReleaseFast |
| 21 | + .{ .name = "worst_best_time_complexity", .path = "chapter_computational_complexity/worst_best_time_complexity.zig" }, |
| 22 | + |
| 23 | + // Source File: "chapter_computational_complexity/space_complexity.zig" |
| 24 | + // Run Command: zig build run_space_complexity -Doptimize=ReleaseFast |
| 25 | + .{ .name = "space_complexity", .path = "chapter_computational_complexity/space_complexity.zig" }, |
| 26 | + |
| 27 | + // Source File: "chapter_array_and_linkedlist/array.zig" |
| 28 | + // Run Command: zig build run_array -Doptimize=ReleaseFast |
| 29 | + .{ .name = "array", .path = "chapter_array_and_linkedlist/array.zig" }, |
| 30 | + |
| 31 | + // Source File: "chapter_array_and_linkedlist/linked_list.zig" |
| 32 | + // Run Command: zig build run_linked_list -Doptimize=ReleaseFast |
| 33 | + .{ .name = "linked_list", .path = "chapter_array_and_linkedlist/linked_list.zig" }, |
| 34 | + |
| 35 | + // Source File: "chapter_array_and_linkedlist/list.zig" |
| 36 | + // Run Command: zig build run_list -Doptimize=ReleaseFast |
| 37 | + .{ .name = "list", .path = "chapter_array_and_linkedlist/list.zig" }, |
| 38 | + |
| 39 | + // Source File: "chapter_array_and_linkedlist/my_list.zig" |
| 40 | + // Run Command: zig build run_my_list -Doptimize=ReleaseFast |
| 41 | + .{ .name = "my_list", .path = "chapter_array_and_linkedlist/my_list.zig" }, |
| 42 | + |
| 43 | + // Source File: "chapter_stack_and_queue/stack.zig" |
| 44 | + // Run Command: zig build run_stack -Doptimize=ReleaseFast |
| 45 | + .{ .name = "stack", .path = "chapter_stack_and_queue/stack.zig" }, |
| 46 | + |
| 47 | + // Source File: "chapter_stack_and_queue/linkedlist_stack.zig" |
| 48 | + // Run Command: zig build run_linkedlist_stack -Doptimize=ReleaseFast |
| 49 | + .{ .name = "linkedlist_stack", .path = "chapter_stack_and_queue/linkedlist_stack.zig" }, |
| 50 | + |
| 51 | + // Source File: "chapter_stack_and_queue/array_stack.zig" |
| 52 | + // Run Command: zig build run_array_stack -Doptimize=ReleaseFast |
| 53 | + .{ .name = "array_stack", .path = "chapter_stack_and_queue/array_stack.zig" }, |
| 54 | + |
| 55 | + // Source File: "chapter_stack_and_queue/queue.zig" |
| 56 | + // Run Command: zig build run_queue -Doptimize=ReleaseFast |
| 57 | + .{ .name = "queue", .path = "chapter_stack_and_queue/queue.zig" }, |
| 58 | + |
| 59 | + // Source File: "chapter_stack_and_queue/array_queue.zig" |
| 60 | + // Run Command: zig build run_array_queue -Doptimize=ReleaseFast |
| 61 | + .{ .name = "array_queue", .path = "chapter_stack_and_queue/array_queue.zig" }, |
| 62 | + |
| 63 | + // Source File: "chapter_stack_and_queue/linkedlist_queue.zig" |
| 64 | + // Run Command: zig build run_linkedlist_queue -Doptimize=ReleaseFast |
| 65 | + .{ .name = "linkedlist_queue", .path = "chapter_stack_and_queue/linkedlist_queue.zig" }, |
| 66 | + |
| 67 | + // Source File: "chapter_stack_and_queue/deque.zig" |
| 68 | + // Run Command: zig build run_deque -Doptimize=ReleaseFast |
| 69 | + .{ .name = "deque", .path = "chapter_stack_and_queue/deque.zig" }, |
| 70 | + |
| 71 | + // Source File: "chapter_stack_and_queue/linkedlist_deque.zig" |
| 72 | + // Run Command: zig build run_linkedlist_deque -Doptimize=ReleaseFast |
| 73 | + .{ .name = "linkedlist_deque", .path = "chapter_stack_and_queue/linkedlist_deque.zig" }, |
| 74 | + |
| 75 | + // Source File: "chapter_hashing/hash_map.zig" |
| 76 | + // Run Command: zig build run_hash_map -Doptimize=ReleaseFast |
| 77 | + .{ .name = "hash_map", .path = "chapter_hashing/hash_map.zig" }, |
| 78 | + |
| 79 | + // Source File: "chapter_hashing/array_hash_map.zig" |
| 80 | + // Run Command: zig build run_array_hash_map -Doptimize=ReleaseFast |
| 81 | + .{ .name = "array_hash_map", .path = "chapter_hashing/array_hash_map.zig" }, |
| 82 | + |
| 83 | + // Source File: "chapter_tree/binary_tree.zig" |
| 84 | + // Run Command: zig build run_binary_tree -Doptimize=ReleaseFast |
| 85 | + .{ .name = "binary_tree", .path = "chapter_tree/binary_tree.zig" }, |
| 86 | + |
| 87 | + // Source File: "chapter_tree/binary_tree_bfs.zig" |
| 88 | + // Run Command: zig build run_binary_tree_bfs -Doptimize=ReleaseFast |
| 89 | + .{ .name = "binary_tree_bfs", .path = "chapter_tree/binary_tree_bfs.zig" }, |
| 90 | + |
| 91 | + // Source File: "chapter_tree/binary_tree_dfs.zig" |
| 92 | + // Run Command: zig build run_binary_tree_dfs -Doptimize=ReleaseFast |
| 93 | + .{ .name = "binary_tree_dfs", .path = "chapter_tree/binary_tree_dfs.zig" }, |
| 94 | + |
| 95 | + // Source File: "chapter_tree/binary_search_tree.zig" |
| 96 | + // Run Command: zig build run_binary_search_tree -Doptimize=ReleaseFast |
| 97 | + .{ .name = "binary_search_tree", .path = "chapter_tree/binary_search_tree.zig" }, |
| 98 | + |
| 99 | + // Source File: "chapter_tree/avl_tree.zig" |
| 100 | + // Run Command: zig build run_avl_tree -Doptimize=ReleaseFast |
| 101 | + .{ .name = "avl_tree", .path = "chapter_tree/avl_tree.zig" }, |
| 102 | + |
| 103 | + // Source File: "chapter_heap/heap.zig" |
| 104 | + // Run Command: zig build run_heap -Doptimize=ReleaseFast |
| 105 | + .{ .name = "heap", .path = "chapter_heap/heap.zig" }, |
| 106 | + |
| 107 | + // Source File: "chapter_heap/my_heap.zig" |
| 108 | + // Run Command: zig build run_my_heap -Doptimize=ReleaseFast |
| 109 | + .{ .name = "my_heap", .path = "chapter_heap/my_heap.zig" }, |
| 110 | + |
| 111 | + // Source File: "chapter_searching/linear_search.zig" |
| 112 | + // Run Command: zig build run_linear_search -Doptimize=ReleaseFast |
| 113 | + .{ .name = "linear_search", .path = "chapter_searching/linear_search.zig" }, |
| 114 | + |
| 115 | + // Source File: "chapter_searching/binary_search.zig" |
| 116 | + // Run Command: zig build run_binary_search -Doptimize=ReleaseFast |
| 117 | + .{ .name = "binary_search", .path = "chapter_searching/binary_search.zig" }, |
| 118 | + |
| 119 | + // Source File: "chapter_searching/hashing_search.zig" |
| 120 | + // Run Command: zig build run_hashing_search -Doptimize=ReleaseFast |
| 121 | + .{ .name = "hashing_search", .path = "chapter_searching/hashing_search.zig" }, |
| 122 | + |
| 123 | + // Source File: "chapter_searching/two_sum.zig" |
| 124 | + // Run Command: zig build run_two_sum -Doptimize=ReleaseFast |
| 125 | + .{ .name = "two_sum", .path = "chapter_searching/two_sum.zig" }, |
| 126 | + |
| 127 | + // Source File: "chapter_sorting/bubble_sort.zig" |
| 128 | + // Run Command: zig build run_bubble_sort -Doptimize=ReleaseFast |
| 129 | + .{ .name = "bubble_sort", .path = "chapter_sorting/bubble_sort.zig" }, |
| 130 | + |
| 131 | + // Source File: "chapter_sorting/insertion_sort.zig" |
| 132 | + // Run Command: zig build run_insertion_sort -Doptimize=ReleaseFast |
| 133 | + .{ .name = "insertion_sort", .path = "chapter_sorting/insertion_sort.zig" }, |
| 134 | + |
| 135 | + // Source File: "chapter_sorting/quick_sort.zig" |
| 136 | + // Run Command: zig build run_quick_sort -Doptimize=ReleaseFast |
| 137 | + .{ .name = "quick_sort", .path = "chapter_sorting/quick_sort.zig" }, |
| 138 | + |
| 139 | + // Source File: "chapter_sorting/merge_sort.zig" |
| 140 | + // Run Command: zig build run_merge_sort -Doptimize=ReleaseFast |
| 141 | + .{ .name = "merge_sort", .path = "chapter_sorting/merge_sort.zig" }, |
| 142 | + |
| 143 | + // Source File: "chapter_sorting/radix_sort.zig" |
| 144 | + // Run Command: zig build run_radix_sort -Doptimize=ReleaseFast |
| 145 | + .{ .name = "radix_sort", .path = "chapter_sorting/radix_sort.zig" }, |
| 146 | + }; |
| 147 | + |
| 148 | + inline for (group_name_path) |name_path| { |
| 149 | + const exe = b.addExecutable(.{ |
| 150 | + .name = name_path.name, |
| 151 | + .root_source_file = .{ .path = name_path.path }, |
| 152 | + .target = target, |
| 153 | + .optimize = optimize, |
| 154 | + }); |
| 155 | + exe.addModule("include", b.addModule("", .{ |
| 156 | + .source_file = .{ .path = "include/include.zig" }, |
| 157 | + })); |
| 158 | + b.installArtifact(exe); |
| 159 | + const run_cmd = b.addRunArtifact(exe); |
| 160 | + run_cmd.step.dependOn(b.getInstallStep()); |
| 161 | + if (b.args) |args| run_cmd.addArgs(args); |
| 162 | + const run_step = b.step("run_" ++ name_path.name, "Run the app"); |
| 163 | + run_step.dependOn(&run_cmd.step); |
| 164 | + } |
| 165 | +} |
0 commit comments