mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-04-14 03:25:50 +00:00
libghostty-vt: allow version to be customized from the Zig build command
This commit is contained in:
@@ -7,7 +7,7 @@ const buildpkg = @import("src/build/main.zig");
|
||||
const app_zon_version = @import("build.zig.zon").version;
|
||||
|
||||
/// Libghostty version. We use a separate version from the app.
|
||||
const lib_version = "0.1.0";
|
||||
const lib_version = "0.1.0-dev";
|
||||
|
||||
/// Minimum required zig version.
|
||||
const minimum_zig_version = @import("build.zig.zon").minimum_zig_version;
|
||||
@@ -37,6 +37,7 @@ pub fn build(b: *std.Build) !void {
|
||||
const config = try buildpkg.Config.init(
|
||||
b,
|
||||
file_version orelse app_zon_version,
|
||||
lib_version,
|
||||
);
|
||||
const test_filters = b.option(
|
||||
[][]const u8,
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
}:
|
||||
stdenv.mkDerivation (finalAttrs: {
|
||||
pname = "ghostty";
|
||||
version = "0.1.0-dev";
|
||||
version = "0.1.0-dev+${revision}-nix";
|
||||
|
||||
# We limit source like this to try and reduce the amount of rebuilds as possible
|
||||
# thus we only provide the source that is needed for the build
|
||||
@@ -51,7 +51,7 @@ stdenv.mkDerivation (finalAttrs: {
|
||||
zigBuildFlags = [
|
||||
"--system"
|
||||
"${finalAttrs.deps}"
|
||||
"-Dversion-string=${finalAttrs.version}-${revision}-nix"
|
||||
"-Dlib-version-string=${finalAttrs.version}"
|
||||
"-Dcpu=baseline"
|
||||
"-Doptimize=${optimize}"
|
||||
"-Dapp-runtime=none"
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -40,7 +40,7 @@ pub fn initWasm(
|
||||
const exe = b.addExecutable(.{
|
||||
.name = "ghostty-vt",
|
||||
.root_module = zig.vt_c,
|
||||
.version = std.SemanticVersion{ .major = 0, .minor = 1, .patch = 0 },
|
||||
.version = zig.version,
|
||||
});
|
||||
|
||||
// Allow exported symbols to actually be exported.
|
||||
@@ -113,7 +113,7 @@ fn initLib(
|
||||
.name = if (kind == .static) "ghostty-vt-static" else "ghostty-vt",
|
||||
.linkage = linkage,
|
||||
.root_module = zig.vt_c,
|
||||
.version = std.SemanticVersion{ .major = 0, .minor = 1, .patch = 0 },
|
||||
.version = zig.version,
|
||||
});
|
||||
lib.installHeadersDirectory(
|
||||
b.path("include/ghostty"),
|
||||
@@ -184,12 +184,12 @@ fn initLib(
|
||||
\\Name: libghostty-vt
|
||||
\\URL: https://github.com/ghostty-org/ghostty
|
||||
\\Description: Ghostty VT library
|
||||
\\Version: 0.1.0
|
||||
\\Version: {f}
|
||||
\\Cflags: -I${{includedir}}
|
||||
\\Libs: -L${{libdir}} -lghostty-vt
|
||||
\\Libs.private: {s}
|
||||
\\Requires.private: {s}
|
||||
, .{ b.install_prefix, libsPrivate(zig), requiresPrivate(b) }));
|
||||
, .{ b.install_prefix, zig.version, libsPrivate(zig), requiresPrivate(b) }));
|
||||
};
|
||||
|
||||
// For static libraries with vendored SIMD dependencies, combine
|
||||
|
||||
@@ -11,6 +11,9 @@ const TerminalBuildOptions = @import("../terminal/build_options.zig").Options;
|
||||
vt: *std.Build.Module,
|
||||
vt_c: *std.Build.Module,
|
||||
|
||||
/// The libghostty-vt version
|
||||
version: std.SemanticVersion,
|
||||
|
||||
/// Static library paths for vendored SIMD dependencies. Populated
|
||||
/// only when the dependencies are built from source (not provided
|
||||
/// by the system via -Dsystem-integration). Used to produce a
|
||||
@@ -23,7 +26,7 @@ pub fn init(
|
||||
deps: *const SharedDeps,
|
||||
) !GhosttyZig {
|
||||
// Terminal module build options
|
||||
var vt_options = cfg.terminalOptions();
|
||||
var vt_options = cfg.terminalOptions(.lib);
|
||||
vt_options.artifact = .lib;
|
||||
// We presently don't allow Oniguruma in our Zig module at all.
|
||||
// We should expose this as a build option in the future so we can
|
||||
@@ -55,6 +58,8 @@ pub fn init(
|
||||
&simd_libs,
|
||||
),
|
||||
|
||||
.version = cfg.lib_version,
|
||||
|
||||
.simd_libs = simd_libs,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ pub fn add(
|
||||
step.root_module.addOptions("build_options", self.options);
|
||||
|
||||
// Every exe needs the terminal options
|
||||
self.config.terminalOptions().add(b, step.root_module);
|
||||
self.config.terminalOptions(.ghostty).add(b, step.root_module);
|
||||
|
||||
// C imports for locale constants and functions
|
||||
{
|
||||
|
||||
@@ -2,6 +2,14 @@ const std = @import("std");
|
||||
|
||||
/// Options set by Zig build.zig and exposed via `terminal_options`.
|
||||
pub const Options = struct {
|
||||
pub const Artifact = enum {
|
||||
/// Ghostty application
|
||||
ghostty,
|
||||
|
||||
/// libghostty-vt, Zig module
|
||||
lib,
|
||||
};
|
||||
|
||||
/// The target artifact to build. This will gate some functionality.
|
||||
artifact: Artifact,
|
||||
|
||||
@@ -65,16 +73,9 @@ pub const Options = struct {
|
||||
opts.addOption(usize, "version_major", self.version.major);
|
||||
opts.addOption(usize, "version_minor", self.version.minor);
|
||||
opts.addOption(usize, "version_patch", self.version.patch);
|
||||
opts.addOption(?[]const u8, "version_pre", self.version.pre);
|
||||
opts.addOption(?[]const u8, "version_build", self.version.build);
|
||||
|
||||
m.addOptions("terminal_options", opts);
|
||||
}
|
||||
};
|
||||
|
||||
pub const Artifact = enum {
|
||||
/// Ghostty application
|
||||
ghostty,
|
||||
|
||||
/// libghostty-vt, Zig module
|
||||
lib,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user