mod(build): build configuration for examples
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 54s
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 54s
This commit is contained in:
42
build.zig
42
build.zig
@@ -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);
|
||||
|
||||
@@ -79,11 +79,10 @@ pub fn main() !void {
|
||||
.rectangle = .{ .fill = .blue },
|
||||
.layout = .{
|
||||
.gap = 1,
|
||||
// FIX: horizontal rendering?
|
||||
.direction = .horizontal,
|
||||
.direction = .vertical,
|
||||
.padding = .vertical(1),
|
||||
},
|
||||
.min_size = .{ .cols = 150 },
|
||||
.min_size = .{ .rows = 50 },
|
||||
}, .{});
|
||||
try box.append(try App.Container.init(allocator, .{
|
||||
.rectangle = .{ .fill = .light_green },
|
||||
@@ -98,7 +97,7 @@ pub fn main() !void {
|
||||
|
||||
var scrollable: App.Scrollable = .{
|
||||
.container = box,
|
||||
.horizontal = true,
|
||||
.vertical = true,
|
||||
};
|
||||
|
||||
var container = try App.Container.init(allocator, .{
|
||||
Reference in New Issue
Block a user