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 target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{}); 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", .{ const zg = b.dependency("zg", .{
.target = target, .target = target,
.optimize = optimize, .optimize = optimize,
@@ -17,27 +28,30 @@ pub fn build(b: *std.Build) void {
}); });
lib.addImport("code_point", zg.module("code_point")); lib.addImport("code_point", zg.module("code_point"));
// main executable (usually used for testing) // Examples.Scrollable
const exe = b.addExecutable(.{ const scrollable = b.addExecutable(.{
.name = "zterm", .name = "scrollable",
.root_source_file = b.path("src/main.zig"), .root_source_file = b.path("examples/scrollable.zig"),
.target = target, .target = target,
.optimize = optimize, .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 // Examples.Layout
// an example application instead of the main executable const layout = b.addExecutable(.{
.name = "layout",
// example applications (usually used for documentation and demonstrations) .root_source_file = b.path("examples/layout.zig"),
const container = b.addExecutable(.{
.name = "container",
.root_source_file = b.path("examples/container.zig"),
.target = target, .target = target,
.optimize = optimize, .optimize = optimize,
}); });
container.root_module.addImport("zterm", lib); layout.root_module.addImport("zterm", lib);
b.installArtifact(container);
// mapping of user selected example to compile step
const exe = switch (example) {
.Layout => layout,
.Scrollable => scrollable,
};
b.installArtifact(exe);
// zig build run // zig build run
const run_cmd = b.addRunArtifact(exe); const run_cmd = b.addRunArtifact(exe);

View File

@@ -79,11 +79,10 @@ pub fn main() !void {
.rectangle = .{ .fill = .blue }, .rectangle = .{ .fill = .blue },
.layout = .{ .layout = .{
.gap = 1, .gap = 1,
// FIX: horizontal rendering? .direction = .vertical,
.direction = .horizontal,
.padding = .vertical(1), .padding = .vertical(1),
}, },
.min_size = .{ .cols = 150 }, .min_size = .{ .rows = 50 },
}, .{}); }, .{});
try box.append(try App.Container.init(allocator, .{ try box.append(try App.Container.init(allocator, .{
.rectangle = .{ .fill = .light_green }, .rectangle = .{ .fill = .light_green },
@@ -98,7 +97,7 @@ pub fn main() !void {
var scrollable: App.Scrollable = .{ var scrollable: App.Scrollable = .{
.container = box, .container = box,
.horizontal = true, .vertical = true,
}; };
var container = try App.Container.init(allocator, .{ var container = try App.Container.init(allocator, .{