libghostty-vt: add semver pre info to build info

pull/12150/head
Jeffrey C. Ollie 2026-04-06 17:17:30 -05:00
parent da835757b0
commit 06340cd3f0
No known key found for this signature in database
GPG Key ID: 1BB9EB7EA602265B
4 changed files with 34 additions and 7 deletions

View File

@ -19,18 +19,25 @@ void query_build_info() {
size_t version_major = 0; size_t version_major = 0;
size_t version_minor = 0; size_t version_minor = 0;
size_t version_patch = 0; size_t version_patch = 0;
GhosttyString version_pre = {0};
GhosttyString version_build = {0}; GhosttyString version_build = {0};
ghostty_build_info(GHOSTTY_BUILD_INFO_VERSION_STRING, &version_string); ghostty_build_info(GHOSTTY_BUILD_INFO_VERSION_STRING, &version_string);
ghostty_build_info(GHOSTTY_BUILD_INFO_VERSION_MAJOR, &version_major); ghostty_build_info(GHOSTTY_BUILD_INFO_VERSION_MAJOR, &version_major);
ghostty_build_info(GHOSTTY_BUILD_INFO_VERSION_MINOR, &version_minor); ghostty_build_info(GHOSTTY_BUILD_INFO_VERSION_MINOR, &version_minor);
ghostty_build_info(GHOSTTY_BUILD_INFO_VERSION_PATCH, &version_patch); ghostty_build_info(GHOSTTY_BUILD_INFO_VERSION_PATCH, &version_patch);
ghostty_build_info(GHOSTTY_BUILD_INFO_VERSION_PRE, &version_pre);
ghostty_build_info(GHOSTTY_BUILD_INFO_VERSION_BUILD, &version_build); ghostty_build_info(GHOSTTY_BUILD_INFO_VERSION_BUILD, &version_build);
printf("Version: %.*s\n", (int)version_string.len, version_string.ptr); printf("Version: %.*s\n", (int)version_string.len, version_string.ptr);
printf("Version major: %zu\n", version_major); printf("Version major: %zu\n", version_major);
printf("Version minor: %zu\n", version_minor); printf("Version minor: %zu\n", version_minor);
printf("Version patch: %zu\n", version_patch); printf("Version patch: %zu\n", version_patch);
if (version_pre.len > 0) {
printf("Version pre : %.*s\n", (int)version_pre.len, version_pre.ptr);
} else {
printf("Version pre : (none)\n");
}
if (version_build.len > 0) { if (version_build.len > 0) {
printf("Version build: %.*s\n", (int)version_build.len, version_build.ptr); printf("Version build: %.*s\n", (int)version_build.len, version_build.ptr);
} else { } else {

View File

@ -107,13 +107,21 @@ typedef enum {
*/ */
GHOSTTY_BUILD_INFO_VERSION_PATCH = 8, GHOSTTY_BUILD_INFO_VERSION_PATCH = 8,
/**
* The pre metadata string (e.g. "alpha", "beta", "dev"). Has zero length if
* no pre metadata is present.
*
* Output type: GhosttyString *
*/
GHOSTTY_BUILD_INFO_VERSION_PRE = 9,
/** /**
* The build metadata string (e.g. commit hash). Has zero length if * The build metadata string (e.g. commit hash). Has zero length if
* no build metadata is present. * no build metadata is present.
* *
* Output type: GhosttyString * * Output type: GhosttyString *
*/ */
GHOSTTY_BUILD_INFO_VERSION_BUILD = 9, GHOSTTY_BUILD_INFO_VERSION_BUILD = 10,
} GhosttyBuildInfo; } GhosttyBuildInfo;
/** /**

View File

@ -75,15 +75,13 @@ pub const Options = struct {
opts.addOption(bool, "tmux_control_mode", self.oniguruma); opts.addOption(bool, "tmux_control_mode", self.oniguruma);
// Version information. // Version information.
var buf: [1024]u8 = undefined;
opts.addOption( opts.addOption(
[]const u8, []const u8,
"version_string", "version_string",
std.fmt.bufPrint( b.fmt(
&buf,
"{f}", "{f}",
.{self.version}, .{self.version},
) catch @panic("version string too long"), ),
); );
opts.addOption(usize, "version_major", self.version.major); opts.addOption(usize, "version_major", self.version.major);
opts.addOption(usize, "version_minor", self.version.minor); opts.addOption(usize, "version_minor", self.version.minor);

View File

@ -25,7 +25,8 @@ pub const BuildInfo = enum(c_int) {
version_major = 6, version_major = 6,
version_minor = 7, version_minor = 7,
version_patch = 8, version_patch = 8,
version_build = 9, version_pre = 9,
version_build = 10,
/// Output type expected for querying the data of the given kind. /// Output type expected for querying the data of the given kind.
pub fn OutType(comptime self: BuildInfo) type { pub fn OutType(comptime self: BuildInfo) type {
@ -33,7 +34,7 @@ pub const BuildInfo = enum(c_int) {
.invalid => void, .invalid => void,
.simd, .kitty_graphics, .tmux_control_mode => bool, .simd, .kitty_graphics, .tmux_control_mode => bool,
.optimize => OptimizeMode, .optimize => OptimizeMode,
.version_string, .version_build => lib.String, .version_string, .version_pre, .version_build => lib.String,
.version_major, .version_minor, .version_patch => usize, .version_major, .version_minor, .version_patch => usize,
}; };
} }
@ -78,6 +79,13 @@ fn getTyped(
.version_major => out.* = build_options.version_major, .version_major => out.* = build_options.version_major,
.version_minor => out.* = build_options.version_minor, .version_minor => out.* = build_options.version_minor,
.version_patch => out.* = build_options.version_patch, .version_patch => out.* = build_options.version_patch,
.version_pre => {
if (build_options.version_pre) |b| {
out.* = .{ .ptr = b.ptr, .len = b.len };
} else {
out.* = .{ .ptr = "", .len = 0 };
}
},
.version_build => { .version_build => {
if (build_options.version_build) |b| { if (build_options.version_build) |b| {
out.* = .{ .ptr = b.ptr, .len = b.len }; out.* = .{ .ptr = b.ptr, .len = b.len };
@ -151,6 +159,12 @@ test "get version_patch" {
try testing.expectEqual(build_options.version_patch, value); try testing.expectEqual(build_options.version_patch, value);
} }
test "get version_pre" {
const testing = std.testing;
var value: lib.String = undefined;
try testing.expectEqual(Result.success, get(.version_pre, @ptrCast(&value)));
}
test "get version_build" { test "get version_build" {
const testing = std.testing; const testing = std.testing;
var value: lib.String = undefined; var value: lib.String = undefined;