diff --git a/build.zig b/build.zig index 5fd611b6c..472c3957a 100644 --- a/build.zig +++ b/build.zig @@ -2,6 +2,7 @@ const std = @import("std"); const assert = std.debug.assert; const builtin = @import("builtin"); const buildpkg = @import("src/build/main.zig"); + const appVersion = @import("build.zig.zon").version; const minimumZigVersion = @import("build.zig.zon").minimum_zig_version; @@ -317,3 +318,8 @@ pub fn build(b: *std.Build) !void { try translations_step.addError("cannot update translations when i18n is disabled", .{}); } } + +/// Marker used by Config.zig to detect if ghostty is the build root. +/// This avoids running logic such as Git tag checking when Ghostty +/// is used as a dependency. +pub const _ghostty_build_root = true; diff --git a/src/build/Config.zig b/src/build/Config.zig index e88213d71..981cd7de5 100644 --- a/src/build/Config.zig +++ b/src/build/Config.zig @@ -218,6 +218,22 @@ pub fn init(b: *std.Build, appVersion: []const u8) !Config { try std.SemanticVersion.parse(v) else version: { const app_version = try std.SemanticVersion.parse(appVersion); + + // Detect if ghostty is being built as a dependency by checking if the + // build root has our marker. When used as a dependency, we skip git + // detection entirely to avoid reading the downstream project's git state. + const is_dependency = !@hasDecl( + @import("root"), + "_ghostty_build_root", + ); + if (is_dependency) { + break :version .{ + .major = app_version.major, + .minor = app_version.minor, + .patch = app_version.patch, + }; + } + // If no explicit version is given, we try to detect it from git. const vsn = GitVersion.detect(b) catch |err| switch (err) { // If Git isn't available we just make an unknown dev version.