feat: add build version to home screen

This commit is contained in:
CJ van den Berg 2025-03-26 19:09:49 +01:00
parent b410687339
commit 4283321542
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
3 changed files with 28 additions and 6 deletions

View file

@ -17,6 +17,13 @@ pub fn build(b: *std.Build) void {
const test_step = b.step("test", "Run unit tests");
const lint_step = b.step("lint", "Run lints");
var version = std.ArrayList(u8).init(b.allocator);
defer version.deinit();
gen_version(b, version.writer()) catch {
version.clearAndFree();
version.appendSlice("unknown") catch {};
};
return (if (release) &build_release else &build_development)(
b,
run_step,
@ -29,6 +36,7 @@ pub fn build(b: *std.Build) void {
use_llvm,
pie,
gui,
version.items,
);
}
@ -44,6 +52,7 @@ fn build_development(
use_llvm: ?bool,
pie: ?bool,
gui: bool,
version: []const u8,
) void {
const target = b.standardTargetOptions(.{ .default_target = .{ .abi = if (builtin.os.tag == .linux and !tracy_enabled) .musl else null } });
const optimize = b.standardOptimizeOption(.{});
@ -63,6 +72,7 @@ fn build_development(
use_llvm,
pie,
gui,
version,
);
}
@ -78,6 +88,7 @@ fn build_release(
use_llvm: ?bool,
pie: ?bool,
_: bool, //gui
version: []const u8,
) void {
const targets: []const std.Target.Query = &.{
.{ .cpu_arch = .x86_64, .os_tag = .linux, .abi = .musl },
@ -91,11 +102,8 @@ fn build_release(
};
const optimize = .ReleaseFast;
var version = std.ArrayList(u8).init(b.allocator);
defer version.deinit();
gen_version(b, version.writer()) catch unreachable;
const write_file_step = b.addWriteFiles();
const version_file = write_file_step.add("version", version.items);
const version_file = write_file_step.add("version", version);
b.getInstallStep().dependOn(&b.addInstallFile(version_file, "version").step);
for (targets) |t| {
@ -120,6 +128,7 @@ fn build_release(
use_llvm,
pie,
false, //gui
version,
);
if (t.os_tag == .windows)
@ -138,6 +147,7 @@ fn build_release(
use_llvm,
pie,
true, //gui
version,
);
}
}
@ -157,6 +167,7 @@ pub fn build_exe(
use_llvm: ?bool,
pie: ?bool,
gui: bool,
version: []const u8,
) void {
const options = b.addOptions();
options.addOption(bool, "enable_tracy", tracy_enabled);
@ -183,7 +194,8 @@ pub fn build_exe(
};
const wf = b.addWriteFiles();
const version_info_file = wf.add("version", version_info.items);
const version_file = wf.add("version", version);
const version_info_file = wf.add("version_info", version_info.items);
const vaxis_dep = b.dependency("vaxis", .{
.target = target,
@ -511,6 +523,7 @@ pub fn build_exe(
exe.root_module.addImport("input", input_mod);
exe.root_module.addImport("syntax", syntax_mod);
exe.root_module.addImport("color", color_mod);
exe.root_module.addImport("version", b.createModule(.{ .root_source_file = version_file }));
exe.root_module.addImport("version_info", b.createModule(.{ .root_source_file = version_info_file }));
if (target.result.os.tag == .windows) {
@ -553,6 +566,7 @@ pub fn build_exe(
check_exe.root_module.addImport("input", input_mod);
check_exe.root_module.addImport("syntax", syntax_mod);
check_exe.root_module.addImport("color", color_mod);
check_exe.root_module.addImport("version", b.createModule(.{ .root_source_file = version_file }));
check_exe.root_module.addImport("version_info", b.createModule(.{ .root_source_file = version_info_file }));
check_step.dependOn(&check_exe.step);

View file

@ -15,6 +15,7 @@ const c = @cImport({
const build_options = @import("build_options");
const log = @import("log");
pub const version = @embedFile("version");
pub const version_info = @embedFile("version_info");
pub var max_diff_lines: usize = 50000;

View file

@ -300,8 +300,15 @@ pub fn render(self: *Self, theme: *const Widget.Theme) bool {
const x = @min(self.plane.dim_x() -| 32, 8);
self.position_menu(self.v_center(5, self.menu_len, 5), self.center(x, self.menu_w));
}
const more = self.menu.render(theme);
self.plane.cursor_move_yx(
@intCast(self.plane.dim_y() - 2),
@intCast(@max(self.plane.dim_x(), root.version.len + 3) - root.version.len - 3),
) catch {};
self.plane.set_style_bg_transparent(style_subtext);
_ = self.plane.print("{s}", .{root.version}) catch return false;
const more = self.menu.render(theme);
return more or self.fire != null;
}