2024-01-18 04:52:33 +01:00
|
|
|
const std = @import("std");
|
|
|
|
|
|
|
|
pub fn build(b: *std.Build) void {
|
2024-06-04 21:06:17 +02:00
|
|
|
const include_libxev = b.option(bool, "libxev", "Enable support for libxev library (default: true)") orelse true;
|
|
|
|
const include_images = b.option(bool, "images", "Enable support for images (default: true)") orelse true;
|
|
|
|
const include_text_input = b.option(bool, "text_input", "Enable support for the TextInput widget (default: true)") orelse true;
|
2024-06-25 09:27:50 +02:00
|
|
|
const include_aio = b.option(bool, "aio", "Enable support for zig-aio library (default: false)") orelse false;
|
2024-06-04 21:06:17 +02:00
|
|
|
|
|
|
|
const options = b.addOptions();
|
|
|
|
options.addOption(bool, "libxev", include_libxev);
|
|
|
|
options.addOption(bool, "images", include_images);
|
|
|
|
options.addOption(bool, "text_input", include_text_input);
|
2024-06-25 09:27:50 +02:00
|
|
|
options.addOption(bool, "aio", include_aio);
|
2024-06-04 21:06:17 +02:00
|
|
|
|
|
|
|
const options_mod = options.createModule();
|
|
|
|
|
2024-01-18 04:52:33 +01:00
|
|
|
const target = b.standardTargetOptions(.{});
|
|
|
|
const optimize = b.standardOptimizeOption(.{});
|
2024-04-20 02:22:46 +02:00
|
|
|
const root_source_file = b.path("src/main.zig");
|
2024-01-18 04:52:33 +01:00
|
|
|
|
2024-02-11 19:59:33 +01:00
|
|
|
// Dependencies
|
2024-04-29 20:01:04 +02:00
|
|
|
const zg_dep = b.dependency("zg", .{
|
|
|
|
.optimize = optimize,
|
|
|
|
.target = target,
|
|
|
|
});
|
2024-06-04 21:06:17 +02:00
|
|
|
const zigimg_dep = if (include_images) b.lazyDependency("zigimg", .{
|
2024-01-25 20:20:32 +01:00
|
|
|
.optimize = optimize,
|
|
|
|
.target = target,
|
2024-06-04 21:06:17 +02:00
|
|
|
}) else null;
|
|
|
|
const gap_buffer_dep = if (include_text_input) b.lazyDependency("gap_buffer", .{
|
2024-03-12 12:38:23 +01:00
|
|
|
.optimize = optimize,
|
|
|
|
.target = target,
|
2024-06-04 21:06:17 +02:00
|
|
|
}) else null;
|
|
|
|
const xev_dep = if (include_libxev) b.lazyDependency("libxev", .{
|
2024-05-30 16:41:45 +02:00
|
|
|
.optimize = optimize,
|
|
|
|
.target = target,
|
2024-06-04 21:06:17 +02:00
|
|
|
}) else null;
|
2024-06-25 09:27:50 +02:00
|
|
|
const aio_dep = if (include_aio) b.lazyDependency("aio", .{
|
|
|
|
.optimize = optimize,
|
|
|
|
.target = target,
|
|
|
|
}) else null;
|
2024-01-25 20:20:32 +01:00
|
|
|
|
2024-02-11 19:59:33 +01:00
|
|
|
// Module
|
fix: use `select` on macOS
the man page for macOS `poll(2)` says, under "bugs", that polling
devices does not work, and indeed, although the current implementation
based on poll(2) does produce output, it does not appear to actually
be polling for this reason; instead the wait is blocking on the `read`
call, causing the macOS user to need to input another character to
exit.
this change introduces a wrapper over macOS's implementation of
`select`, modeled after `std.io.poll` as `select.zig`. it is a compile
error to use `select.zig` when `builtin.os.tag.isDarwin()` is false. a
lightly altered version of `Tty.zig` accompanies this change. it's
certainly possible to incorporate the two into one file; i didn't just
to leave the other one in its original state.
with this change, writing to the pipe correctly exits.
additionally, on macOS, `Thread.setName` must be called from the
thread whose name you wish to set, so I have just commented out that
line.
2024-03-09 06:23:25 +01:00
|
|
|
const vaxis_mod = b.addModule("vaxis", .{
|
|
|
|
.root_source_file = root_source_file,
|
|
|
|
.target = target,
|
|
|
|
.optimize = optimize,
|
|
|
|
});
|
2024-04-29 21:00:08 +02:00
|
|
|
vaxis_mod.addImport("code_point", zg_dep.module("code_point"));
|
2024-04-29 20:01:04 +02:00
|
|
|
vaxis_mod.addImport("grapheme", zg_dep.module("grapheme"));
|
2024-04-29 21:00:08 +02:00
|
|
|
vaxis_mod.addImport("DisplayWidth", zg_dep.module("DisplayWidth"));
|
2024-06-04 21:06:17 +02:00
|
|
|
if (zigimg_dep) |dep| vaxis_mod.addImport("zigimg", dep.module("zigimg"));
|
|
|
|
if (gap_buffer_dep) |dep| vaxis_mod.addImport("gap_buffer", dep.module("gap_buffer"));
|
|
|
|
if (xev_dep) |dep| vaxis_mod.addImport("xev", dep.module("xev"));
|
2024-06-25 09:27:50 +02:00
|
|
|
if (aio_dep) |dep| vaxis_mod.addImport("aio", dep.module("aio"));
|
|
|
|
if (aio_dep) |dep| vaxis_mod.addImport("coro", dep.module("coro"));
|
2024-06-04 21:06:17 +02:00
|
|
|
vaxis_mod.addImport("build_options", options_mod);
|
2024-02-11 19:59:33 +01:00
|
|
|
|
|
|
|
// Examples
|
2024-04-15 22:36:43 +02:00
|
|
|
const Example = enum {
|
2024-05-02 19:50:33 +02:00
|
|
|
cli,
|
2024-04-15 22:36:43 +02:00
|
|
|
image,
|
|
|
|
main,
|
|
|
|
nvim,
|
|
|
|
table,
|
|
|
|
text_input,
|
2024-05-24 15:04:54 +02:00
|
|
|
vaxis,
|
2024-06-06 23:41:32 +02:00
|
|
|
vt,
|
2024-05-30 16:41:45 +02:00
|
|
|
xev,
|
2024-06-25 09:27:50 +02:00
|
|
|
aio,
|
2024-04-15 22:36:43 +02:00
|
|
|
};
|
2024-04-11 00:37:46 +02:00
|
|
|
const example_option = b.option(Example, "example", "Example to run (default: text_input)") orelse .text_input;
|
|
|
|
const example_step = b.step("example", "Run example");
|
|
|
|
const example = b.addExecutable(.{
|
|
|
|
.name = "example",
|
|
|
|
// future versions should use b.path, see zig PR #19597
|
2024-04-20 02:22:46 +02:00
|
|
|
.root_source_file = b.path(
|
2024-04-11 00:37:46 +02:00
|
|
|
b.fmt("examples/{s}.zig", .{@tagName(example_option)}),
|
|
|
|
),
|
2024-01-18 04:52:33 +01:00
|
|
|
.target = target,
|
|
|
|
.optimize = optimize,
|
|
|
|
});
|
2024-04-11 00:37:46 +02:00
|
|
|
example.root_module.addImport("vaxis", vaxis_mod);
|
2024-06-04 21:06:17 +02:00
|
|
|
if (xev_dep) |dep| example.root_module.addImport("xev", dep.module("xev"));
|
2024-06-25 09:27:50 +02:00
|
|
|
if (aio_dep) |dep| example.root_module.addImport("aio", dep.module("aio"));
|
|
|
|
if (aio_dep) |dep| example.root_module.addImport("coro", dep.module("coro"));
|
2024-05-30 16:41:45 +02:00
|
|
|
|
2024-04-11 00:37:46 +02:00
|
|
|
const example_run = b.addRunArtifact(example);
|
|
|
|
example_step.dependOn(&example_run.step);
|
2024-01-18 04:52:33 +01:00
|
|
|
|
2024-02-11 19:59:33 +01:00
|
|
|
// Tests
|
|
|
|
const tests_step = b.step("test", "Run tests");
|
2024-01-18 04:52:33 +01:00
|
|
|
|
2024-02-11 19:59:33 +01:00
|
|
|
const tests = b.addTest(.{
|
2024-04-20 02:22:46 +02:00
|
|
|
.root_source_file = b.path("src/main.zig"),
|
2024-01-18 04:52:33 +01:00
|
|
|
.target = target,
|
|
|
|
.optimize = optimize,
|
|
|
|
});
|
2024-04-29 21:00:08 +02:00
|
|
|
tests.root_module.addImport("code_point", zg_dep.module("code_point"));
|
2024-04-29 20:01:04 +02:00
|
|
|
tests.root_module.addImport("grapheme", zg_dep.module("grapheme"));
|
2024-04-29 21:00:08 +02:00
|
|
|
tests.root_module.addImport("DisplayWidth", zg_dep.module("DisplayWidth"));
|
2024-06-04 21:06:17 +02:00
|
|
|
if (zigimg_dep) |dep| tests.root_module.addImport("zigimg", dep.module("zigimg"));
|
|
|
|
if (gap_buffer_dep) |dep| tests.root_module.addImport("gap_buffer", dep.module("gap_buffer"));
|
|
|
|
tests.root_module.addImport("build_options", options_mod);
|
2024-02-11 19:59:33 +01:00
|
|
|
|
|
|
|
const tests_run = b.addRunArtifact(tests);
|
fix: use `select` on macOS
the man page for macOS `poll(2)` says, under "bugs", that polling
devices does not work, and indeed, although the current implementation
based on poll(2) does produce output, it does not appear to actually
be polling for this reason; instead the wait is blocking on the `read`
call, causing the macOS user to need to input another character to
exit.
this change introduces a wrapper over macOS's implementation of
`select`, modeled after `std.io.poll` as `select.zig`. it is a compile
error to use `select.zig` when `builtin.os.tag.isDarwin()` is false. a
lightly altered version of `Tty.zig` accompanies this change. it's
certainly possible to incorporate the two into one file; i didn't just
to leave the other one in its original state.
with this change, writing to the pipe correctly exits.
additionally, on macOS, `Thread.setName` must be called from the
thread whose name you wish to set, so I have just commented out that
line.
2024-03-09 06:23:25 +01:00
|
|
|
b.installArtifact(tests);
|
2024-02-11 19:59:33 +01:00
|
|
|
tests_step.dependOn(&tests_run.step);
|
2024-01-18 04:52:33 +01:00
|
|
|
|
2024-02-11 19:59:33 +01:00
|
|
|
// Lints
|
|
|
|
const lints_step = b.step("lint", "Run lints");
|
|
|
|
|
|
|
|
const lints = b.addFmt(.{
|
|
|
|
.paths = &.{ "src", "build.zig" },
|
|
|
|
.check = true,
|
|
|
|
});
|
2024-01-18 04:52:33 +01:00
|
|
|
|
2024-02-11 19:59:33 +01:00
|
|
|
lints_step.dependOn(&lints.step);
|
|
|
|
b.default_step.dependOn(lints_step);
|
2024-02-22 22:54:07 +01:00
|
|
|
|
|
|
|
// Docs
|
2024-05-14 19:53:29 +02:00
|
|
|
const docs_step = b.step("docs", "Build the vaxis library docs");
|
|
|
|
const docs_obj = b.addObject(.{
|
2024-03-29 15:20:42 +01:00
|
|
|
.name = "vaxis",
|
2024-03-29 15:37:07 +01:00
|
|
|
.root_source_file = root_source_file,
|
2024-03-29 15:20:42 +01:00
|
|
|
.target = target,
|
|
|
|
.optimize = optimize,
|
|
|
|
});
|
2024-05-14 19:53:29 +02:00
|
|
|
const docs = docs_obj.getEmittedDocs();
|
|
|
|
docs_step.dependOn(&b.addInstallDirectory(.{
|
|
|
|
.source_dir = docs,
|
2024-02-22 22:54:07 +01:00
|
|
|
.install_dir = .prefix,
|
|
|
|
.install_subdir = "docs",
|
2024-05-14 19:53:29 +02:00
|
|
|
}).step);
|
2024-01-18 04:52:33 +01:00
|
|
|
}
|