refactor(build): simplify dependency detection logic

- Removes unnecessary marker constant from build.zig that existed
  solely to signal build root status
- Uses filesystem check (@src().file access) instead of compile-time
  declaration lookup to detect when ghostty is a dependency
- Same behavior with less indirection: file resolves from build root
  only when ghostty is the main project
pull/9914/head
kadekillary 2025-12-15 06:31:54 -06:00
parent 1d7fe9e70d
commit a0a915a06f
2 changed files with 8 additions and 19 deletions

View File

@ -318,8 +318,3 @@ pub fn build(b: *std.Build) !void {
try translations_step.addError("cannot update translations when i18n is disabled", .{}); 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;

View File

@ -219,20 +219,14 @@ pub fn init(b: *std.Build, appVersion: []const u8) !Config {
else version: { else version: {
const app_version = try std.SemanticVersion.parse(appVersion); const app_version = try std.SemanticVersion.parse(appVersion);
// Detect if ghostty is being built as a dependency by checking if the // Is ghostty a dependency? If so, skip git detection.
// build root has our marker. When used as a dependency, we skip git // @src().file won't resolve from b.build_root unless ghostty
// detection entirely to avoid reading the downstream project's git state. // is the project being built.
const is_dependency = !@hasDecl( b.build_root.handle.access(@src().file, .{}) catch break :version .{
@import("root"), .major = app_version.major,
"_ghostty_build_root", .minor = app_version.minor,
); .patch = app_version.patch,
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. // If no explicit version is given, we try to detect it from git.
const vsn = GitVersion.detect(b) catch |err| switch (err) { const vsn = GitVersion.detect(b) catch |err| switch (err) {