this repo has no description
13
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 161 lines 5.2 kB view raw
1const std = @import("std"); 2 3pub fn build(b: *std.Build) void { 4 const target = b.standardTargetOptions(.{}); 5 const optimize = b.standardOptimizeOption(.{}); 6 const use_llvm = b.option(bool, "llvm", "Use the LLVM backend for compile steps") orelse true; 7 const external_uucode = b.option(bool, "external_uucode", "Use an externally provided uucode module instead of the built-in dependency") orelse false; 8 const root_source_file = b.path("src/main.zig"); 9 10 // Dependencies 11 const zigimg_dep = b.dependency("zigimg", .{ 12 .optimize = optimize, 13 .target = target, 14 }); 15 const uucode_mod = if (!external_uucode) blk: { 16 const uucode_dep = b.lazyDependency("uucode", .{ 17 .target = target, 18 .optimize = optimize, 19 .fields = @as([]const []const u8, &.{ 20 "east_asian_width", 21 "grapheme_break", 22 "general_category", 23 "is_emoji_presentation", 24 }), 25 }) orelse break :blk null; 26 break :blk uucode_dep.module("uucode"); 27 } else null; 28 29 // Module 30 const vaxis_mod = b.addModule("vaxis", .{ 31 .root_source_file = root_source_file, 32 .target = target, 33 .optimize = optimize, 34 }); 35 vaxis_mod.addImport("zigimg", zigimg_dep.module("zigimg")); 36 if (uucode_mod) |mod| { 37 vaxis_mod.addImport("uucode", mod); 38 } else { 39 // External uucode mode: consumer wires up their own uucode module on 40 // the vaxis module. Skip examples, bench, tests, and docs steps since 41 // they all depend on uucode being available here. 42 return; 43 } 44 45 // Examples 46 const Example = enum { 47 cli, 48 counter, 49 fuzzy, 50 image, 51 main, 52 scroll, 53 split_view, 54 table, 55 text_input, 56 text_view, 57 list_view, 58 vaxis, 59 view, 60 vt, 61 }; 62 var examples: std.EnumMap(Example, *std.Build.Module) = .init(.{}); 63 inline for (std.meta.fields(Example)) |field| { 64 const example: Example = @enumFromInt(field.value); 65 examples.put( 66 example, 67 b.createModule(.{ 68 .root_source_file = b.path( 69 b.fmt("examples/{t}.zig", .{example}), 70 ), 71 .target = target, 72 .optimize = optimize, 73 .imports = &.{ 74 .{ .name = "vaxis", .module = vaxis_mod }, 75 }, 76 }), 77 ); 78 } 79 const example_option = b.option(Example, "example", "Example to run (default: text_input)") orelse .text_input; 80 const example_step = b.step("example", "Run example"); 81 const example = b.addExecutable(.{ 82 .name = b.fmt("example-{t}", .{example_option}), 83 .root_module = examples.get(example_option) orelse unreachable, 84 .use_llvm = use_llvm, 85 }); 86 87 b.getInstallStep().dependOn(&example.step); 88 89 const example_run = b.addRunArtifact(example); 90 example_step.dependOn(&example_run.step); 91 92 // Benchmarks 93 const bench_step = b.step("bench", "Run benchmarks"); 94 const bench = b.addExecutable(.{ 95 .name = "bench", 96 .use_llvm = use_llvm, 97 .root_module = b.createModule(.{ 98 .root_source_file = b.path("bench/bench.zig"), 99 .target = target, 100 .optimize = optimize, 101 .imports = &.{ 102 .{ .name = "vaxis", .module = vaxis_mod }, 103 }, 104 }), 105 }); 106 const bench_run = b.addRunArtifact(bench); 107 if (b.args) |args| { 108 bench_run.addArgs(args); 109 } 110 bench_step.dependOn(&bench_run.step); 111 112 // Tests 113 const tests_step = b.step("test", "Run tests"); 114 115 const tests = b.addTest(.{ 116 .use_llvm = use_llvm, 117 .root_module = b.createModule(.{ 118 .root_source_file = b.path("src/main.zig"), 119 .target = target, 120 .optimize = optimize, 121 .imports = &.{ 122 .{ .name = "zigimg", .module = zigimg_dep.module("zigimg") }, 123 .{ .name = "uucode", .module = uucode_mod.? }, 124 }, 125 }), 126 }); 127 128 // Let's make sure that all of the examples compile and can run any tests 129 // that they may have defined. 130 var it = examples.iterator(); 131 while (it.next()) |v| { 132 const e = b.addTest(.{ 133 .use_llvm = use_llvm, 134 .root_module = v.value.*, 135 }); 136 const r = b.addRunArtifact(e); 137 tests_step.dependOn(&r.step); 138 } 139 140 const tests_run = b.addRunArtifact(tests); 141 b.installArtifact(tests); 142 tests_step.dependOn(&tests_run.step); 143 144 // Docs 145 const docs_step = b.step("docs", "Build the vaxis library docs"); 146 const docs_obj = b.addObject(.{ 147 .name = "vaxis", 148 .use_llvm = use_llvm, 149 .root_module = b.createModule(.{ 150 .root_source_file = root_source_file, 151 .target = target, 152 .optimize = optimize, 153 }), 154 }); 155 const docs = docs_obj.getEmittedDocs(); 156 docs_step.dependOn(&b.addInstallDirectory(.{ 157 .source_dir = docs, 158 .install_dir = .prefix, 159 .install_subdir = "docs", 160 }).step); 161}