diff options
| author | Can Celik <ogulcancelik@gmail.com> | 2026-09-10 21:51:57 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-09-10 21:51:57 +0300 |
| commit | 425c86179791cd32e2d4ce0ae7f269940b4b0663 (patch) | |
| tree | e52c4383a6d69216cbe2a32638bf90841d7e2189 /vendor/libghostty-vt/pkg/apple-sdk/native_link.zig | |
| parent | 90e947a6e26e02f10ec7f1694c4eb5b78a86406b (diff) | |
chore: upgrade libghostty and preserve terminal behavior (#3906)
Diffstat (limited to 'vendor/libghostty-vt/pkg/apple-sdk/native_link.zig')
| -rw-r--r-- | vendor/libghostty-vt/pkg/apple-sdk/native_link.zig | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/vendor/libghostty-vt/pkg/apple-sdk/native_link.zig b/vendor/libghostty-vt/pkg/apple-sdk/native_link.zig new file mode 100644 index 00000000..46ceeb76 --- /dev/null +++ b/vendor/libghostty-vt/pkg/apple-sdk/native_link.zig @@ -0,0 +1,85 @@ +//! Helpers for invoking Apple's native linker through the target SDK. +//! +//! Callers provide all artifact-specific flags, inputs, and outputs. + +const std = @import("std"); +const builtin = @import("builtin"); +const RunStep = std.Build.Step.Run; + +/// Returns true when the host Apple toolchain can link the target. +/// +/// This is limited to targets covered by the SDK and target-triple mappings +/// below. Add other Darwin platforms alongside support for those mappings. +pub fn available(target: std.Build.ResolvedTarget) bool { + if (!builtin.os.tag.isDarwin()) return false; + + return switch (target.result.os.tag) { + .macos, .ios => true, + else => false, + }; +} + +/// Create an Apple Clang link command configured for the target SDK and +/// deployment version. The caller supplies the artifact-specific link flags, +/// inputs, and output. +pub fn addCommand( + b: *std.Build, + name: []const u8, + target: std.Build.ResolvedTarget, +) !*RunStep { + if (!available(target)) return error.AppleNativeLinkerUnavailable; + + const run = RunStep.create(b, name); + run.addArgs(&.{ + "/usr/bin/xcrun", + "--sdk", + try sdkName(target), + "clang", + "-fuse-ld=ld", + "-target", + try clangTarget(b, target), + }); + return run; +} + +fn sdkName(target: std.Build.ResolvedTarget) ![]const u8 { + return switch (target.result.os.tag) { + .macos => "macosx", + .ios => switch (target.result.abi) { + .simulator => "iphonesimulator", + else => "iphoneos", + }, + else => error.UnsupportedAppleTarget, + }; +} + +fn clangTarget( + b: *std.Build, + target: std.Build.ResolvedTarget, +) ![]const u8 { + const arch = switch (target.result.cpu.arch) { + .aarch64 => "arm64", + .x86_64 => "x86_64", + else => return error.UnsupportedAppleArchitecture, + }; + const minimum = target.query.os_version_min orelse + return error.AppleDeploymentTargetMissing; + + return switch (target.result.os.tag) { + .macos => b.fmt( + "{s}-apple-macosx{f}", + .{ arch, minimum.semver }, + ), + .ios => switch (target.result.abi) { + .simulator => b.fmt( + "{s}-apple-ios{f}-simulator", + .{ arch, minimum.semver }, + ), + else => b.fmt( + "{s}-apple-ios{f}", + .{ arch, minimum.semver }, + ), + }, + else => error.UnsupportedAppleTarget, + }; +} |
