a modern tui library written in zig
at v0.5.1 4.6 kB view raw
1const std = @import("std"); 2 3pub fn build(b: *std.Build) void { 4 const include_libxev = b.option(bool, "libxev", "Enable support for libxev library (default: true)") orelse true; 5 const include_images = b.option(bool, "images", "Enable support for images (default: true)") orelse true; 6 const include_aio = b.option(bool, "aio", "Enable support for zig-aio library (default: false)") orelse false; 7 8 const options = b.addOptions(); 9 options.addOption(bool, "libxev", include_libxev); 10 options.addOption(bool, "images", include_images); 11 options.addOption(bool, "aio", include_aio); 12 13 const options_mod = options.createModule(); 14 15 const target = b.standardTargetOptions(.{}); 16 const optimize = b.standardOptimizeOption(.{}); 17 const root_source_file = b.path("src/main.zig"); 18 19 // Dependencies 20 const zg_dep = b.dependency("zg", .{ 21 .optimize = optimize, 22 .target = target, 23 }); 24 const zigimg_dep = if (include_images) b.lazyDependency("zigimg", .{ 25 .optimize = optimize, 26 .target = target, 27 }) else null; 28 const xev_dep = if (include_libxev) b.lazyDependency("libxev", .{ 29 .optimize = optimize, 30 .target = target, 31 }) else null; 32 const aio_dep = if (include_aio) b.lazyDependency("aio", .{ 33 .optimize = optimize, 34 .target = target, 35 }) else null; 36 37 // Module 38 const vaxis_mod = b.addModule("vaxis", .{ 39 .root_source_file = root_source_file, 40 .target = target, 41 .optimize = optimize, 42 }); 43 vaxis_mod.addImport("code_point", zg_dep.module("code_point")); 44 vaxis_mod.addImport("grapheme", zg_dep.module("grapheme")); 45 vaxis_mod.addImport("DisplayWidth", zg_dep.module("DisplayWidth")); 46 if (zigimg_dep) |dep| vaxis_mod.addImport("zigimg", dep.module("zigimg")); 47 if (xev_dep) |dep| vaxis_mod.addImport("xev", dep.module("xev")); 48 if (aio_dep) |dep| vaxis_mod.addImport("aio", dep.module("aio")); 49 if (aio_dep) |dep| vaxis_mod.addImport("coro", dep.module("coro")); 50 vaxis_mod.addImport("build_options", options_mod); 51 52 // Examples 53 const Example = enum { 54 aio, 55 cli, 56 image, 57 main, 58 nvim, 59 table, 60 text_input, 61 vaxis, 62 view, 63 vt, 64 xev, 65 }; 66 const example_option = b.option(Example, "example", "Example to run (default: text_input)") orelse .text_input; 67 const example_step = b.step("example", "Run example"); 68 const example = b.addExecutable(.{ 69 .name = "example", 70 // future versions should use b.path, see zig PR #19597 71 .root_source_file = b.path( 72 b.fmt("examples/{s}.zig", .{@tagName(example_option)}), 73 ), 74 .target = target, 75 .optimize = optimize, 76 }); 77 example.root_module.addImport("vaxis", vaxis_mod); 78 if (xev_dep) |dep| example.root_module.addImport("xev", dep.module("xev")); 79 if (aio_dep) |dep| example.root_module.addImport("aio", dep.module("aio")); 80 if (aio_dep) |dep| example.root_module.addImport("coro", dep.module("coro")); 81 82 const example_run = b.addRunArtifact(example); 83 example_step.dependOn(&example_run.step); 84 85 // Tests 86 const tests_step = b.step("test", "Run tests"); 87 88 const tests = b.addTest(.{ 89 .root_source_file = b.path("src/main.zig"), 90 .target = target, 91 .optimize = optimize, 92 }); 93 tests.root_module.addImport("code_point", zg_dep.module("code_point")); 94 tests.root_module.addImport("grapheme", zg_dep.module("grapheme")); 95 tests.root_module.addImport("DisplayWidth", zg_dep.module("DisplayWidth")); 96 if (zigimg_dep) |dep| tests.root_module.addImport("zigimg", dep.module("zigimg")); 97 tests.root_module.addImport("build_options", options_mod); 98 99 const tests_run = b.addRunArtifact(tests); 100 b.installArtifact(tests); 101 tests_step.dependOn(&tests_run.step); 102 103 // Lints 104 const lints_step = b.step("lint", "Run lints"); 105 106 const lints = b.addFmt(.{ 107 .paths = &.{ "src", "build.zig" }, 108 .check = true, 109 }); 110 111 lints_step.dependOn(&lints.step); 112 b.default_step.dependOn(lints_step); 113 114 // Docs 115 const docs_step = b.step("docs", "Build the vaxis library docs"); 116 const docs_obj = b.addObject(.{ 117 .name = "vaxis", 118 .root_source_file = root_source_file, 119 .target = target, 120 .optimize = optimize, 121 }); 122 const docs = docs_obj.getEmittedDocs(); 123 docs_step.dependOn(&b.addInstallDirectory(.{ 124 .source_dir = docs, 125 .install_dir = .prefix, 126 .install_subdir = "docs", 127 }).step); 128}