ghostty/pkg/apple-sdk/build.zig
Mitchell Hashimoto 3360a008cd build: build produces a broken object file for iOS
This gets `zig build -Dtarget=aarch64-ios` working. By "working" I mean
it produces an object file without compiler errors. However, the object
file certainly isn't useful since it uses a number of features that will
not work in the iOS sandbox.

This is just an experiment more than anything to see how hard it would be to
get libghostty working within iOS to render a terminal. Note iOS doesn't
support ptys so this wouldn't be a true on-device terminal. The
challenge right now is to just get a terminal rendering (not usable).
2024-01-13 21:38:58 -08:00

57 lines
1.9 KiB
Zig

const std = @import("std");
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
_ = target;
_ = optimize;
}
/// Add the SDK framework, include, and library paths to the given module.
/// The module target is used to determine the SDK to use so it must have
/// a resolved target.
pub fn addPaths(b: *std.Build, m: *std.Build.Module) !void {
// The active SDK we want to use
const sdk = try SDK.fromTarget(m.resolved_target.?.result);
// Get the path to our active Xcode installation. If this fails then
// the zig build will fail. We store this in a struct variable so its
// static and only calculated once per build.
const Path = struct {
var value: ?[]const u8 = null;
};
const path = Path.value orelse path: {
const path = std.mem.trim(u8, b.run(&.{ "xcode-select", "--print-path" }), " \r\n");
Path.value = path;
break :path path;
};
// Base path
const base = b.fmt("{s}/Platforms/{s}.platform/Developer/SDKs/{s}{s}.sdk", .{
path,
sdk.platform,
sdk.platform,
sdk.version,
});
m.addSystemFrameworkPath(.{ .cwd_relative = b.pathJoin(&.{ base, "/System/Library/Frameworks" }) });
m.addSystemIncludePath(.{ .cwd_relative = b.pathJoin(&.{ base, "/usr/include" }) });
m.addLibraryPath(.{ .cwd_relative = b.pathJoin(&.{ base, "/usr/lib" }) });
}
const SDK = struct {
platform: []const u8,
version: []const u8,
pub fn fromTarget(target: std.Target) !SDK {
return switch (target.os.tag) {
.ios => .{ .platform = "iPhoneOS", .version = "" },
.macos => .{ .platform = "MacOSX", .version = "14" },
else => {
std.log.err("unsupported os={}", .{target.os.tag});
return error.UnsupportedOS;
},
};
}
};