Some checks failed
Zig Project Action / Lint, Spell-check and test zig project (push) Failing after 39s
This also contains some minor refactoring to improve the readability and understandability of the library (i.e. renaming of Style.Attributes to Style.Emphasis).
160 lines
4.6 KiB
Zig
160 lines
4.6 KiB
Zig
const std = @import("std");
|
|
|
|
pub fn build(b: *std.Build) void {
|
|
const target = b.standardTargetOptions(.{});
|
|
const optimize = b.standardOptimizeOption(.{});
|
|
|
|
const Examples = enum {
|
|
// elements:
|
|
button,
|
|
input,
|
|
scrollable,
|
|
// layouts:
|
|
vertical,
|
|
horizontal,
|
|
grid,
|
|
mixed,
|
|
// styles:
|
|
text,
|
|
palette,
|
|
};
|
|
|
|
const example = b.option(Examples, "example", "Example to build and/or run. (default: vertical)") orelse .vertical;
|
|
|
|
const options = b.addOptions();
|
|
options.addOption(Examples, "example", example);
|
|
|
|
// dependencies
|
|
const zg = b.dependency("zg", .{
|
|
.target = target,
|
|
.optimize = optimize,
|
|
});
|
|
|
|
// library
|
|
const lib = b.addModule("zterm", .{
|
|
.root_source_file = b.path("src/zterm.zig"),
|
|
.target = target,
|
|
.optimize = optimize,
|
|
});
|
|
lib.addImport("code_point", zg.module("code_point"));
|
|
|
|
//--- Examples ---
|
|
|
|
// elements:
|
|
const button = b.addExecutable(.{
|
|
.name = "button",
|
|
.root_source_file = b.path("examples/elements/button.zig"),
|
|
.target = target,
|
|
.optimize = optimize,
|
|
});
|
|
button.root_module.addImport("zterm", lib);
|
|
|
|
const input = b.addExecutable(.{
|
|
.name = "input",
|
|
.root_source_file = b.path("examples/elements/input.zig"),
|
|
.target = target,
|
|
.optimize = optimize,
|
|
});
|
|
input.root_module.addImport("zterm", lib);
|
|
|
|
const scrollable = b.addExecutable(.{
|
|
.name = "scrollable",
|
|
.root_source_file = b.path("examples/elements/scrollable.zig"),
|
|
.target = target,
|
|
.optimize = optimize,
|
|
});
|
|
scrollable.root_module.addImport("zterm", lib);
|
|
|
|
// layouts:
|
|
const vertical = b.addExecutable(.{
|
|
.name = "vertical",
|
|
.root_source_file = b.path("examples/layouts/vertical.zig"),
|
|
.target = target,
|
|
.optimize = optimize,
|
|
});
|
|
vertical.root_module.addImport("zterm", lib);
|
|
|
|
const horizontal = b.addExecutable(.{
|
|
.name = "horizontal",
|
|
.root_source_file = b.path("examples/layouts/horizontal.zig"),
|
|
.target = target,
|
|
.optimize = optimize,
|
|
});
|
|
horizontal.root_module.addImport("zterm", lib);
|
|
|
|
const grid = b.addExecutable(.{
|
|
.name = "grid",
|
|
.root_source_file = b.path("examples/layouts/grid.zig"),
|
|
.target = target,
|
|
.optimize = optimize,
|
|
});
|
|
grid.root_module.addImport("zterm", lib);
|
|
|
|
const mixed = b.addExecutable(.{
|
|
.name = "mixed",
|
|
.root_source_file = b.path("examples/layouts/mixed.zig"),
|
|
.target = target,
|
|
.optimize = optimize,
|
|
});
|
|
mixed.root_module.addImport("zterm", lib);
|
|
|
|
// styles:
|
|
const palette = b.addExecutable(.{
|
|
.name = "palette",
|
|
.root_source_file = b.path("examples/styles/palette.zig"),
|
|
.target = target,
|
|
.optimize = optimize,
|
|
});
|
|
palette.root_module.addImport("zterm", lib);
|
|
|
|
const text = b.addExecutable(.{
|
|
.name = "text",
|
|
.root_source_file = b.path("examples/styles/text.zig"),
|
|
.target = target,
|
|
.optimize = optimize,
|
|
});
|
|
text.root_module.addImport("zterm", lib);
|
|
|
|
// mapping of user selected example to compile step
|
|
const exe = switch (example) {
|
|
// elements:
|
|
.button => button,
|
|
.input => input,
|
|
.scrollable => scrollable,
|
|
// layouts:
|
|
.vertical => vertical,
|
|
.horizontal => horizontal,
|
|
.grid => grid,
|
|
.mixed => mixed,
|
|
// styles:
|
|
.text => text,
|
|
.palette => palette,
|
|
};
|
|
b.installArtifact(exe);
|
|
|
|
// zig build run
|
|
const run_cmd = b.addRunArtifact(exe);
|
|
run_cmd.step.dependOn(b.getInstallStep());
|
|
// Allow additional arguments, like this: `zig build run -- arg1 arg2 etc`
|
|
if (b.args) |args| run_cmd.addArgs(args);
|
|
|
|
// This creates a build step. It will be visible in the `zig build --help` menu,
|
|
// and can be selected like this: `zig build run`
|
|
// This will evaluate the `run` step rather than the default, which is "install".
|
|
const run_step = b.step("run", "Run the app");
|
|
run_step.dependOn(&run_cmd.step);
|
|
|
|
// zig build test
|
|
const lib_unit_tests = b.addTest(.{
|
|
.root_source_file = b.path("src/zterm.zig"),
|
|
.target = target,
|
|
.optimize = optimize,
|
|
});
|
|
lib_unit_tests.root_module.addImport("code_point", zg.module("code_point"));
|
|
|
|
const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests);
|
|
|
|
const test_step = b.step("test", "Run unit tests");
|
|
test_step.dependOn(&run_lib_unit_tests.step);
|
|
}
|