-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
93 lines (77 loc) · 3.05 KB
/
Copy pathbuild.zig
File metadata and controls
93 lines (77 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// ghostty-vt xcframework headers path
const xcfw_headers = b.path("lib/ghostty-vt.xcframework/macos-arm64_x86_64/Headers");
// Build a static library from Zig sources (exports C-callable functions)
const lib = b.addLibrary(.{
.name = "stvt-core",
.root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
}),
.linkage = .static,
});
// ghostty-vt headers for Zig @cImport
lib.root_module.addIncludePath(xcfw_headers);
lib.root_module.addIncludePath(b.path("src"));
// Compile Core Text font shim as part of the library
lib.addCSourceFile(.{
.file = b.path("src/font_shim.c"),
.flags = &.{},
});
// macOS frameworks for the Zig library
if (std.process.getEnvVarOwned(b.allocator, "SDKROOT")) |sdk| {
const fw_path = std.fmt.allocPrint(b.allocator, "{s}/System/Library/Frameworks", .{sdk}) catch unreachable;
lib.root_module.addFrameworkPath(.{ .cwd_relative = fw_path });
} else |_| {}
lib.root_module.linkFramework("CoreFoundation", .{});
lib.root_module.linkFramework("CoreText", .{});
lib.root_module.linkFramework("CoreGraphics", .{});
// Build the ObjC executable
const exe = b.addExecutable(.{
.name = "stvt",
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
}),
});
// ObjC source
exe.addCSourceFile(.{
.file = b.path("src/app.m"),
.flags = &.{"-fobjc-arc"},
});
exe.root_module.addIncludePath(b.path("src"));
exe.root_module.addIncludePath(xcfw_headers);
// Link Zig static library
exe.linkLibrary(lib);
// Link prebuilt ghostty-vt
exe.addObjectFile(b.path("lib/ghostty-vt.xcframework/macos-arm64_x86_64/libghostty-vt.a"));
// System libraries
exe.root_module.linkSystemLibrary("c++", .{});
exe.linkLibC();
// macOS frameworks
if (std.process.getEnvVarOwned(b.allocator, "SDKROOT")) |sdk| {
const fw_path = std.fmt.allocPrint(b.allocator, "{s}/System/Library/Frameworks", .{sdk}) catch unreachable;
exe.root_module.addFrameworkPath(.{ .cwd_relative = fw_path });
} else |_| {}
exe.root_module.linkFramework("CoreFoundation", .{});
exe.root_module.linkFramework("CoreText", .{});
exe.root_module.linkFramework("CoreGraphics", .{});
exe.root_module.linkFramework("AppKit", .{});
exe.root_module.linkFramework("Metal", .{});
exe.root_module.linkFramework("QuartzCore", .{});
b.installArtifact(exe);
// Run step
const run_step = b.step("run", "Run stvt");
const run_cmd = b.addRunArtifact(exe);
run_step.dependOn(&run_cmd.step);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}
// Test step
_ = b.step("test", "Run tests");
}