Skip to content

Commit

Permalink
refactor: move Ghext to the build system
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesrocket committed Aug 21, 2024
1 parent ea0039e commit ff510f2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
20 changes: 10 additions & 10 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const build_options = b.addOptions();

const exe = b.addExecutable(.{
.name = "xtxf",
Expand All @@ -16,7 +17,7 @@ pub fn build(b: *std.Build) void {
.optimize = optimize,
});

const cova = cova_dep.module("cova");
const cova_mod = cova_dep.module("cova");

const cova_gen = @import("cova").addCovaDocGenStep(b, cova_dep, exe, .{
.kinds = &.{.all},
Expand All @@ -25,19 +26,13 @@ pub fn build(b: *std.Build) void {
const meta_doc_gen = b.step("gen-doc", "Generate Meta Docs");
meta_doc_gen.dependOn(&cova_gen.step);

const ghext_dep = b.dependency("ghext", .{
.target = target,
.optimize = optimize,
});

const ghext = ghext_dep.module("ghext");

exe.addIncludePath(b.dependency("termbox2", .{}).path("."));
exe.addCSourceFile(.{ .file = b.path("src/termbox_impl.c") });
exe.linkLibC();
exe.root_module.addImport("cova", cova);
exe.root_module.addImport("ghext", ghext);
exe.root_module.addImport("cova", cova_mod);
exe.root_module.addOptions("build_options", build_options);

build_options.addOption([]const u8, "head_hash", try hash());
b.installArtifact(exe);

const run_cmd = b.addRunArtifact(exe);
Expand Down Expand Up @@ -91,3 +86,8 @@ pub fn build(b: *std.Build) void {
const coverage_step = b.step("coverage", "Generate test coverage (kcov)");
coverage_step.dependOn(&merge_step.step);
}

inline fn hash() ![]const u8 {
const gxt = @import("ghext").Ghext.read(std.heap.page_allocator) catch unreachable;
return gxt.hash;
}
4 changes: 2 additions & 2 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
.hash = "12200ac5cfa52c6ed5df6cbbf6be03f5b5b4a95abe67b750f9f2b0216da11b21e70c",
},
.ghext = .{
.url = "https://github.com/charlesrocket/ghext/archive/refs/tags/0.3.0.tar.gz",
.hash = "12200acee906e217dafde5539a1e5905d093c97b6ba2408e0653772814e3643efc76",
.url = "https://github.com/charlesrocket/ghext/archive/983eac9d280b2db7c7ca9ede2c977815c26b0074.tar.gz",
.hash = "122081d642ad5e81b306b7a0b849b4f9e976f4653468eb18580d2115c3b4654b23b6",
},
},
}
2 changes: 1 addition & 1 deletion src/assets.zig
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ pub const help_message =
\\
;

pub const cli_usage = "{u}{?u}{s} {s}{s?} <{s}:{s}>";
pub const opt_usage = "{u}{?u}{s} {s}{s?} <{s}:{s}>";
5 changes: 3 additions & 2 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const tb = @cImport({
});

const cova = @import("cova");
const Ghext = @import("ghext");
const build_opt = @import("build_options");

const Thread = std.Thread;
const Mutex = Thread.Mutex;
Expand All @@ -24,9 +24,10 @@ const Style = enum { default, columns, crypto, grid, blocks };
const Color = enum(u32) { default = tb.TB_DEFAULT, red = tb.TB_RED, green = tb.TB_GREEN, blue = tb.TB_BLUE, yellow = tb.TB_YELLOW, magenta = tb.TB_MAGENTA };

pub const CommandT = cova.Command.Custom(.{
.global_help_prefix = "xtxf-" ++ build_opt.head_hash[0..7],
.help_header_fmt = assets.help_message,
.opt_config = .{
.usage_fmt = assets.cli_usage,
.usage_fmt = assets.opt_usage,
},
.val_config = .{
.custom_types = &.{
Expand Down

0 comments on commit ff510f2

Please sign in to comment.