this repo has no description
13
fork

Configure Feed

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

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