libghostty-vt: allow version to be customized from the Zig build command

This commit is contained in:
Jeffrey C. Ollie
2026-04-04 17:04:01 -05:00
parent 0a4cf5877e
commit 06144d30f2
7 changed files with 55 additions and 23 deletions

View File

@@ -38,6 +38,7 @@ wasm_shared: bool = true,
/// Ghostty exe properties
exe_entrypoint: ExeEntrypoint = .ghostty,
version: std.SemanticVersion = .{ .major = 0, .minor = 0, .patch = 0 },
lib_version: std.SemanticVersion = .{ .major = 0, .minor = 0, .patch = 0 },
/// Binary properties
pie: bool = false,
@@ -68,7 +69,7 @@ is_dep: bool = false,
/// Environmental properties
env: std.process.EnvMap,
pub fn init(b: *std.Build, appVersion: []const u8) !Config {
pub fn init(b: *std.Build, appVersion: []const u8, libVersion: []const u8) !Config {
// Setup our standard Zig target and optimize options, i.e.
// `-Doptimize` and `-Dtarget`.
const optimize = b.standardOptimizeOption(.{});
@@ -294,6 +295,20 @@ pub fn init(b: *std.Build, appVersion: []const u8) !Config {
};
};
// libghostty-vt properties
const lib_version_string = b.option(
[]const u8,
"lib-version-string",
"A specific version string to use for the build of libghostty-vt. " ++
"If not specified, git will be used. This must be a semantic version.",
);
config.lib_version = if (lib_version_string) |v|
try std.SemanticVersion.parse(v)
else
try std.SemanticVersion.parse(libVersion);
//---------------------------------------------------------------
// Binary Properties
@@ -519,13 +534,20 @@ pub fn addOptions(self: *const Config, step: *std.Build.Step.Options) !void {
// Our version. We also add the string version so we don't need
// to do any allocations at runtime. This has to be long enough to
// accommodate realistic large branch names for dev versions.
var buf: [1024]u8 = undefined;
var app_version_buf: [1024]u8 = undefined;
step.addOption(std.SemanticVersion, "app_version", self.version);
step.addOption([:0]const u8, "app_version_string", try std.fmt.bufPrintZ(
&buf,
&app_version_buf,
"{f}",
.{self.version},
));
var lib_version_buf: [1024]u8 = undefined;
step.addOption(std.SemanticVersion, "lib_version", self.lib_version);
step.addOption([:0]const u8, "lib_version_string", try std.fmt.bufPrintZ(
&lib_version_buf,
"{f}",
.{self.lib_version},
));
step.addOption(
ReleaseChannel,
"release_channel",
@@ -539,13 +561,16 @@ pub fn addOptions(self: *const Config, step: *std.Build.Step.Options) !void {
/// Returns the build options for the terminal module. This assumes a
/// Ghostty executable being built. Callers should modify this as needed.
pub fn terminalOptions(self: *const Config) TerminalBuildOptions {
pub fn terminalOptions(self: *const Config, artifact: TerminalBuildOptions.Artifact) TerminalBuildOptions {
return .{
.artifact = .ghostty,
.artifact = artifact,
.simd = self.simd,
.oniguruma = true,
.c_abi = false,
.version = self.version,
.version = switch (artifact) {
.ghostty => self.version,
.lib => self.lib_version,
},
.slow_runtime_safety = switch (self.optimize) {
.Debug => true,
.ReleaseSafe,