build: make most dependencies optional
This commit is contained in:
parent
b2ffc953dd
commit
d21940bdbd
4 changed files with 45 additions and 19 deletions
47
build.zig
47
build.zig
|
@ -1,6 +1,19 @@
|
|||
const std = @import("std");
|
||||
|
||||
pub fn build(b: *std.Build) void {
|
||||
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_nvim = b.option(bool, "nvim", "Enable support for the neovim widget (default: false)") orelse true;
|
||||
const include_text_input = b.option(bool, "text_input", "Enable support for the TextInput widget (default: true)") orelse true;
|
||||
|
||||
const options = b.addOptions();
|
||||
options.addOption(bool, "libxev", include_libxev);
|
||||
options.addOption(bool, "images", include_images);
|
||||
options.addOption(bool, "nvim", include_nvim);
|
||||
options.addOption(bool, "text_input", include_text_input);
|
||||
|
||||
const options_mod = options.createModule();
|
||||
|
||||
const target = b.standardTargetOptions(.{});
|
||||
const optimize = b.standardOptimizeOption(.{});
|
||||
const root_source_file = b.path("src/main.zig");
|
||||
|
@ -10,22 +23,22 @@ pub fn build(b: *std.Build) void {
|
|||
.optimize = optimize,
|
||||
.target = target,
|
||||
});
|
||||
const zigimg_dep = b.dependency("zigimg", .{
|
||||
const zigimg_dep = if (include_images) b.lazyDependency("zigimg", .{
|
||||
.optimize = optimize,
|
||||
.target = target,
|
||||
});
|
||||
const gap_buffer_dep = b.dependency("gap_buffer", .{
|
||||
}) else null;
|
||||
const gap_buffer_dep = if (include_text_input) b.lazyDependency("gap_buffer", .{
|
||||
.optimize = optimize,
|
||||
.target = target,
|
||||
});
|
||||
const znvim_dep = b.dependency("znvim", .{
|
||||
}) else null;
|
||||
const znvim_dep = if (include_nvim) b.lazyDependency("znvim", .{
|
||||
.optimize = optimize,
|
||||
.target = target,
|
||||
});
|
||||
const xev_dep = b.dependency("libxev", .{
|
||||
}) else null;
|
||||
const xev_dep = if (include_libxev) b.lazyDependency("libxev", .{
|
||||
.optimize = optimize,
|
||||
.target = target,
|
||||
});
|
||||
}) else null;
|
||||
|
||||
// Module
|
||||
const vaxis_mod = b.addModule("vaxis", .{
|
||||
|
@ -36,10 +49,11 @@ pub fn build(b: *std.Build) void {
|
|||
vaxis_mod.addImport("code_point", zg_dep.module("code_point"));
|
||||
vaxis_mod.addImport("grapheme", zg_dep.module("grapheme"));
|
||||
vaxis_mod.addImport("DisplayWidth", zg_dep.module("DisplayWidth"));
|
||||
vaxis_mod.addImport("zigimg", zigimg_dep.module("zigimg"));
|
||||
vaxis_mod.addImport("gap_buffer", gap_buffer_dep.module("gap_buffer"));
|
||||
vaxis_mod.addImport("znvim", znvim_dep.module("znvim"));
|
||||
vaxis_mod.addImport("xev", xev_dep.module("xev"));
|
||||
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 (znvim_dep) |dep| vaxis_mod.addImport("znvim", dep.module("znvim"));
|
||||
if (xev_dep) |dep| vaxis_mod.addImport("xev", dep.module("xev"));
|
||||
vaxis_mod.addImport("build_options", options_mod);
|
||||
|
||||
// Examples
|
||||
const Example = enum {
|
||||
|
@ -64,7 +78,7 @@ pub fn build(b: *std.Build) void {
|
|||
.optimize = optimize,
|
||||
});
|
||||
example.root_module.addImport("vaxis", vaxis_mod);
|
||||
example.root_module.addImport("xev", xev_dep.module("xev"));
|
||||
if (xev_dep) |dep| example.root_module.addImport("xev", dep.module("xev"));
|
||||
|
||||
const example_run = b.addRunArtifact(example);
|
||||
example_step.dependOn(&example_run.step);
|
||||
|
@ -80,9 +94,10 @@ pub fn build(b: *std.Build) void {
|
|||
tests.root_module.addImport("code_point", zg_dep.module("code_point"));
|
||||
tests.root_module.addImport("grapheme", zg_dep.module("grapheme"));
|
||||
tests.root_module.addImport("DisplayWidth", zg_dep.module("DisplayWidth"));
|
||||
tests.root_module.addImport("zigimg", zigimg_dep.module("zigimg"));
|
||||
tests.root_module.addImport("gap_buffer", gap_buffer_dep.module("gap_buffer"));
|
||||
tests.root_module.addImport("znvim", znvim_dep.module("znvim"));
|
||||
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"));
|
||||
if (znvim_dep) |dep| tests.root_module.addImport("znvim", dep.module("znvim"));
|
||||
tests.root_module.addImport("build_options", options_mod);
|
||||
|
||||
const tests_run = b.addRunArtifact(tests);
|
||||
b.installArtifact(tests);
|
||||
|
|
|
@ -6,14 +6,17 @@
|
|||
.zigimg = .{
|
||||
.url = "git+https://github.com/zigimg/zigimg#637974e2d31dcdbc33f1e9cc8ffb2e46abd2e215",
|
||||
.hash = "122012026c3a65ff1d4acba3b3fe80785f7cee9c6b4cdaff7ed0fbf23b0a6c803989",
|
||||
.lazy = true,
|
||||
},
|
||||
.gap_buffer = .{
|
||||
.url = "https://github.com/ryleelyman/GapBuffer.zig/archive/6a746497d5a2494026d0f471e42556f1f153f153.tar.gz",
|
||||
.hash = "12205354d9903e773f9d934dcfe756b0b5ffd895571ad631ab86ebc1aebba074dd82",
|
||||
.lazy = true,
|
||||
},
|
||||
.znvim = .{
|
||||
.url = "git+https://github.com/jinzhongjia/znvim#7927b8042872d5fa5f30862302bea1290d372d4f",
|
||||
.hash = "12202372c2043a9ac557144d327c09638ccd8d615bba459ba17d1a7a4197a213d939",
|
||||
.lazy = true,
|
||||
},
|
||||
.zg = .{
|
||||
.url = "git+https://codeberg.org/dude_the_builder/zg#16735685fcc3410de361ba3411788ad1fb4fe188",
|
||||
|
@ -22,6 +25,7 @@
|
|||
.libxev = .{
|
||||
.url = "git+https://github.com/mitchellh/libxev#b3f9918776b8700b337b7ebe769060328fe246b0",
|
||||
.hash = "122044caf67c7833c7110dc93531031899e459a6818ed125a0bcfdb0b5243bd7700b",
|
||||
.lazy = true,
|
||||
},
|
||||
},
|
||||
.paths = .{
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
const std = @import("std");
|
||||
const builtin = @import("builtin");
|
||||
const build_options = @import("build_options");
|
||||
|
||||
pub const Vaxis = @import("Vaxis.zig");
|
||||
|
||||
|
@ -75,5 +76,6 @@ test {
|
|||
|
||||
_ = @import("gwidth.zig");
|
||||
_ = @import("queue.zig");
|
||||
_ = @import("widgets/TextInput.zig");
|
||||
if (build_options.text_input)
|
||||
_ = @import("widgets/TextInput.zig");
|
||||
}
|
||||
|
|
|
@ -1,12 +1,17 @@
|
|||
//! Specialized TUI Widgets
|
||||
|
||||
const opts = @import("build_options");
|
||||
|
||||
pub const border = @import("widgets/border.zig");
|
||||
pub const alignment = @import("widgets/alignment.zig");
|
||||
pub const Scrollbar = @import("widgets/Scrollbar.zig");
|
||||
pub const Table = @import("widgets/Table.zig");
|
||||
pub const TextInput = @import("widgets/TextInput.zig");
|
||||
pub const nvim = @import("widgets/nvim.zig");
|
||||
pub const ScrollView = @import("widgets/ScrollView.zig");
|
||||
pub const LineNumbers = @import("widgets/LineNumbers.zig");
|
||||
pub const TextView = @import("widgets/TextView.zig");
|
||||
pub const CodeView = @import("widgets/CodeView.zig");
|
||||
|
||||
// Widgets with dependencies
|
||||
|
||||
pub const TextInput = if (opts.text_input) @import("widgets/TextInput.zig") else undefined;
|
||||
pub const nvim = if (opts.nvim) @import("widgets/nvim.zig") else undefined;
|
||||
|
|
Loading…
Reference in a new issue