mod(build): build configuration for examples
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 54s

This commit is contained in:
2025-02-20 11:16:42 +01:00
parent 9322785ca0
commit 96375e3b72
3 changed files with 31 additions and 18 deletions

View File

@@ -4,6 +4,17 @@ pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const Examples = enum {
Layout,
Scrollable,
};
const example = b.option(Examples, "example", "Example to build and/or run.") orelse .Layout;
const options = b.addOptions();
options.addOption(Examples, "example", example);
// dependencies
const zg = b.dependency("zg", .{
.target = target,
.optimize = optimize,
@@ -17,27 +28,30 @@ pub fn build(b: *std.Build) void {
});
lib.addImport("code_point", zg.module("code_point"));
// main executable (usually used for testing)
const exe = b.addExecutable(.{
.name = "zterm",
.root_source_file = b.path("src/main.zig"),
// Examples.Scrollable
const scrollable = b.addExecutable(.{
.name = "scrollable",
.root_source_file = b.path("examples/scrollable.zig"),
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("zterm", lib);
scrollable.root_module.addImport("zterm", lib);
// TODO: add example execution through optional argument to `zig run` to run
// an example application instead of the main executable
// example applications (usually used for documentation and demonstrations)
const container = b.addExecutable(.{
.name = "container",
.root_source_file = b.path("examples/container.zig"),
// Examples.Layout
const layout = b.addExecutable(.{
.name = "layout",
.root_source_file = b.path("examples/layout.zig"),
.target = target,
.optimize = optimize,
});
container.root_module.addImport("zterm", lib);
b.installArtifact(container);
layout.root_module.addImport("zterm", lib);
// mapping of user selected example to compile step
const exe = switch (example) {
.Layout => layout,
.Scrollable => scrollable,
};
b.installArtifact(exe);
// zig build run
const run_cmd = b.addRunArtifact(exe);