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).
This commit is contained in:
Mitchell Hashimoto
2024-01-13 20:21:49 -08:00
parent 7a4c63522b
commit 3360a008cd
29 changed files with 228 additions and 46 deletions

View File

@@ -45,6 +45,7 @@ const SDK = struct {
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});

View File

@@ -71,10 +71,12 @@ pub fn build(b: *std.Build) !void {
.file = imgui.path("backends/imgui_impl_metal.mm"),
.flags = flags.items,
});
lib.addCSourceFile(.{
.file = imgui.path("backends/imgui_impl_osx.mm"),
.flags = flags.items,
});
if (target.result.os.tag == .macos) {
lib.addCSourceFile(.{
.file = imgui.path("backends/imgui_impl_osx.mm"),
.flags = flags.items,
});
}
}
lib.installHeadersDirectoryOptions(.{

View File

@@ -15,6 +15,11 @@ pub fn build(b: *std.Build) !void {
});
lib.linkLibC();
lib.addIncludePath(upstream.path("include"));
if (target.result.isDarwin()) {
const apple_sdk = @import("apple_sdk");
try apple_sdk.addPaths(b, &lib.root_module);
}
module.addIncludePath(upstream.path("include"));
module.addIncludePath(.{ .path = "" });
@@ -86,7 +91,7 @@ pub fn build(b: *std.Build) !void {
b.installArtifact(lib);
{
if (target.query.isNative()) {
const test_exe = b.addTest(.{
.name = "test",
.root_source_file = .{ .path = "main.zig" },

View File

@@ -1,12 +1,14 @@
.{
.name = "freetype",
.version = "2.13.2",
.paths = .{""},
.dependencies = .{
.freetype = .{
.url = "https://github.com/freetype/freetype/archive/refs/tags/VER-2-13-2.tar.gz",
.hash = "1220b81f6ecfb3fd222f76cf9106fecfa6554ab07ec7fdc4124b9bb063ae2adf969d",
},
.apple_sdk = .{ .path = "../apple-sdk" },
.libpng = .{ .path = "../libpng" },
.zlib = .{ .path = "../zlib" },
},

View File

@@ -12,8 +12,15 @@ pub fn build(b: *std.Build) !void {
module.addIncludePath(upstream.path(""));
module.addIncludePath(.{ .path = "override" });
if (target.result.isDarwin()) {
// See pkg/harfbuzz/build.zig
module.resolved_target = target;
defer module.resolved_target = null;
const apple_sdk = @import("apple_sdk");
try apple_sdk.addPaths(b, module);
}
{
if (target.query.isNative()) {
const test_exe = b.addTest(.{
.name = "test",
.root_source_file = .{ .path = "main.zig" },
@@ -45,6 +52,10 @@ fn buildGlslang(
lib.linkLibCpp();
lib.addIncludePath(upstream.path(""));
lib.addIncludePath(.{ .path = "override" });
if (target.result.isDarwin()) {
const apple_sdk = @import("apple_sdk");
try apple_sdk.addPaths(b, &lib.root_module);
}
var flags = std.ArrayList([]const u8).init(b.allocator);
defer flags.deinit();

View File

@@ -7,5 +7,7 @@
.url = "https://github.com/KhronosGroup/glslang/archive/refs/tags/13.1.1.tar.gz",
.hash = "1220481fe19def1172cd0728743019c0f440181a6342b62d03e24d05c70141516799",
},
.apple_sdk = .{ .path = "../apple-sdk" },
},
}

View File

@@ -34,6 +34,18 @@ pub fn build(b: *std.Build) !void {
lib.addIncludePath(upstream.path("src"));
module.addIncludePath(upstream.path("src"));
if (target.result.isDarwin()) {
// This is definitely super sketchy and not right but without this
// zig build test breaks on macOS. We have to look into what exactly
// is going on here but this getting comitted in the interest of
// unblocking zig build test.
module.resolved_target = target;
defer module.resolved_target = null;
try apple_sdk.addPaths(b, &lib.root_module);
try apple_sdk.addPaths(b, module);
}
const freetype_dep = b.dependency("freetype", .{ .target = target, .optimize = optimize });
lib.linkLibrary(freetype_dep.artifact("freetype"));
module.addIncludePath(freetype_dep.builder.dependency("freetype", .{}).path("include"));
@@ -59,19 +71,10 @@ pub fn build(b: *std.Build) !void {
"-DHAVE_FT_DONE_MM_VAR=1",
"-DHAVE_FT_GET_TRANSFORM=1",
});
if (coretext_enabled and target.result.isDarwin()) {
// This is definitely super sketchy and not right but without this
// zig build test breaks on macOS. We have to look into what exactly
// is going on here but this getting comitted in the interest of
// unblocking zig build test.
module.resolved_target = target;
defer module.resolved_target = null;
if (coretext_enabled) {
try flags.appendSlice(&.{"-DHAVE_CORETEXT=1"});
try apple_sdk.addPaths(b, &lib.root_module);
try apple_sdk.addPaths(b, module);
lib.linkFramework("ApplicationServices");
module.linkFramework("ApplicationServices", .{});
lib.linkFramework("CoreText");
module.linkFramework("CoreText", .{});
}
lib.addCSourceFile(.{

View File

@@ -1,6 +1,7 @@
.{
.name = "harfbuzz",
.version = "8.2.2",
.paths = .{""},
.dependencies = .{
.harfbuzz = .{
.url = "https://github.com/harfbuzz/harfbuzz/archive/refs/tags/8.2.2.tar.gz",

View File

@@ -15,6 +15,10 @@ pub fn build(b: *std.Build) !void {
if (target.result.os.tag == .linux) {
lib.linkSystemLibrary("m");
}
if (target.result.isDarwin()) {
const apple_sdk = @import("apple_sdk");
try apple_sdk.addPaths(b, &lib.root_module);
}
const zlib_dep = b.dependency("zlib", .{ .target = target, .optimize = optimize });
lib.linkLibrary(zlib_dep.artifact("z"));

View File

@@ -1,14 +1,14 @@
.{
.name = "libpng",
.version = "1.6.40",
.paths = .{""},
.dependencies = .{
.libpng = .{
.url = "https://github.com/glennrp/libpng/archive/refs/tags/v1.6.40.tar.gz",
.hash = "12203d2722e3af6f9556503b114c25fe3eead528a93f5f26eefcb187a460d1548e07",
},
.zlib = .{
.path = "../zlib",
},
.zlib = .{ .path = "../zlib" },
.apple_sdk = .{ .path = "../apple-sdk" },
},
}

View File

@@ -28,14 +28,16 @@ pub fn build(b: *std.Build) !void {
.file = .{ .path = "text/ext.c" },
.flags = flags.items,
});
lib.linkFramework("Carbon");
lib.linkFramework("CoreFoundation");
lib.linkFramework("CoreGraphics");
lib.linkFramework("CoreText");
lib.linkFramework("CoreVideo");
if (target.result.os.tag == .macos) {
lib.linkFramework("Carbon");
module.linkFramework("Carbon", .{});
}
if (target.result.isDarwin()) {
module.linkFramework("Carbon", .{});
module.linkFramework("CoreFoundation", .{});
module.linkFramework("CoreGraphics", .{});
module.linkFramework("CoreText", .{});

View File

@@ -12,7 +12,7 @@ pub fn build(b: *std.Build) !void {
module.addIncludePath(upstream.path("src"));
b.installArtifact(lib);
{
if (target.query.isNative()) {
const test_exe = b.addTest(.{
.name = "test",
.root_source_file = .{ .path = "main.zig" },
@@ -44,6 +44,11 @@ fn buildOniguruma(
lib.linkLibC();
lib.addIncludePath(upstream.path("src"));
if (target.result.isDarwin()) {
const apple_sdk = @import("apple_sdk");
try apple_sdk.addPaths(b, &lib.root_module);
}
lib.addConfigHeader(b.addConfigHeader(.{
.style = .{ .cmake = upstream.path("src/config.h.cmake.in") },
}, .{

View File

@@ -7,5 +7,7 @@
.url = "https://github.com/kkos/oniguruma/archive/refs/tags/v6.9.9.tar.gz",
.hash = "1220c15e72eadd0d9085a8af134904d9a0f5dfcbed5f606ad60edc60ebeccd9706bb",
},
.apple_sdk = .{ .path = "../apple-sdk" },
},
}

View File

@@ -16,6 +16,10 @@ pub fn build(b: *std.Build) !void {
if (target.result.os.tag != .windows) {
lib.linkSystemLibrary("pthread");
}
if (target.result.isDarwin()) {
const apple_sdk = @import("apple_sdk");
try apple_sdk.addPaths(b, &lib.root_module);
}
lib.addIncludePath(upstream.path(""));
lib.addIncludePath(.{ .path = "" });
@@ -68,7 +72,7 @@ pub fn build(b: *std.Build) !void {
b.installArtifact(lib);
{
if (target.query.isNative()) {
const test_exe = b.addTest(.{
.name = "test",
.root_source_file = .{ .path = "main.zig" },

View File

@@ -1,10 +1,13 @@
.{
.name = "pixman",
.version = "0.42.2",
.paths = .{""},
.dependencies = .{
.pixman = .{
.url = "https://deps.files.ghostty.dev/pixman-pixman-0.42.2.tar.gz",
.hash = "12209b9206f9a5d31ccd9a2312cc72cb9dfc3e034aee1883c549dc1d753fae457230",
},
.apple_sdk = .{ .path = "../apple-sdk" },
},
}

View File

@@ -12,7 +12,7 @@ pub fn build(b: *std.Build) !void {
const lib = try buildSpirvCross(b, upstream, target, optimize);
b.installArtifact(lib);
{
if (target.query.isNative()) {
const test_exe = b.addTest(.{
.name = "test",
.root_source_file = .{ .path = "main.zig" },
@@ -42,8 +42,10 @@ fn buildSpirvCross(
});
lib.linkLibC();
lib.linkLibCpp();
//lib.addIncludePath(upstream.path(""));
//lib.addIncludePath(.{ .path = "override" });
if (target.result.isDarwin()) {
const apple_sdk = @import("apple_sdk");
try apple_sdk.addPaths(b, &lib.root_module);
}
var flags = std.ArrayList([]const u8).init(b.allocator);
defer flags.deinit();

View File

@@ -7,5 +7,7 @@
.url = "https://github.com/KhronosGroup/SPIRV-Cross/archive/4818f7e7ef7b7078a3a7a5a52c4a338e0dda22f4.tar.gz",
.hash = "1220b2d8a6cff1926ef28a29e312a0a503b555ebc2f082230b882410f49e672ac9c6",
},
.apple_sdk = .{ .path = "../apple-sdk" },
},
}

View File

@@ -13,6 +13,11 @@ pub fn build(b: *std.Build) !void {
});
lib.linkLibC();
lib.addIncludePath(upstream.path(""));
if (target.result.isDarwin()) {
const apple_sdk = @import("apple_sdk");
try apple_sdk.addPaths(b, &lib.root_module);
}
lib.installHeadersDirectoryOptions(.{
.source_dir = upstream.path(""),
.install_dir = .header,

View File

@@ -1,10 +1,13 @@
.{
.name = "zlib",
.version = "1.3.0",
.paths = .{""},
.dependencies = .{
.zlib = .{
.url = "https://github.com/madler/zlib/archive/refs/tags/v1.3.tar.gz",
.hash = "12207d353609d95cee9da7891919e6d9582e97b7aa2831bd50f33bf523a582a08547",
},
.apple_sdk = .{ .path = "../apple-sdk" },
},
}