summaryrefslogtreecommitdiff
path: root/build.zig
diff options
context:
space:
mode:
Diffstat (limited to 'build.zig')
-rw-r--r--build.zig52
1 files changed, 51 insertions, 1 deletions
diff --git a/build.zig b/build.zig
index 22dd7158..beeba648 100644
--- a/build.zig
+++ b/build.zig
@@ -16,6 +16,7 @@ pub fn build(b: *std.Build) void {
const optimize = if (is_emscripten) .ReleaseSmall else requested_optimize;
const default_grammars: TreeSitterGrammars = if (is_emscripten) .minimal else .full;
const tree_sitter_grammars = b.option(TreeSitterGrammars, "tree-sitter", "tree-sitter grammar set: disabled, minimal, full") orelse default_grammars;
+ const tracy = b.option([]const u8, "tracy", "enable Tracy profiling; supply the path to a Tracy source checkout");
// the browser shell: zig object + emcc link + html, installed to zig-out/web
const web_step = b.step("web", "build the browser shell into zig-out/web (-Dplatform=web -Dtarget=wasm32-emscripten -Ddump=<dump.zon>)");
@@ -59,13 +60,41 @@ pub fn build(b: *std.Build) void {
// static archives the emcc link needs beyond the zig object (grammars, SDL)
var wasm_libs: std.ArrayList(std.Build.LazyPath) = .empty;
+ // forkpty: in libc proper on glibc>=2.34 and darwin; the BSDs keep it in libutil
+ if (target.result.os.tag == .freebsd or target.result.os.tag == .netbsd or target.result.os.tag == .openbsd)
+ root_mod.linkSystemLibrary("util", .{});
+
const opts = b.addOptions();
opts.addOption(Platform, "platform", platform);
opts.addOption(bool, "syntax_highlighting", tree_sitter_grammars != .disabled);
opts.addOption(bool, "syntax_minimal_grammars", tree_sitter_grammars != .disabled);
opts.addOption(bool, "syntax_full_grammars", tree_sitter_grammars == .full);
+ opts.addOption(bool, "enable_tracy", tracy != null);
root_mod.addOptions("pardes_config", opts);
+ // Tracy zones (src/tracy.zig): compile the client into the binary only when
+ // -Dtracy=<path> names a Tracy checkout; otherwise every zone is a no-op.
+ // Sampling/callstacks/system tracing stay off: tracy's symbol worker
+ // SIGSEGVs on this binary's debug info, and its crash handler then parks
+ // every thread — the app wedges before the first frame. Zones don't need
+ // any of it.
+ if (tracy) |tracy_path| {
+ root_mod.addIncludePath(.{ .cwd_relative = tracy_path });
+ root_mod.addCSourceFile(.{
+ .file = .{ .cwd_relative = b.pathJoin(&.{ tracy_path, "public", "TracyClient.cpp" }) },
+ .flags = &.{
+ "-DTRACY_ENABLE=1",
+ "-DTRACY_NO_SAMPLING",
+ "-DTRACY_NO_CALLSTACK",
+ "-DTRACY_NO_SYSTEM_TRACING",
+ "-DTRACY_NO_CRASH_HANDLER",
+ "-DTRACY_NO_CODE_TRANSFER",
+ "-fno-sanitize=undefined",
+ },
+ });
+ root_mod.link_libcpp = true;
+ }
+
// tree-sitter: the zig bindings + C runtime, one static lib per grammar,
// and each grammar's highlights.scm slurped at build time into the
// ts_queries options module (codegen consumed by comptime in syntax.zig).
@@ -171,7 +200,26 @@ pub fn build(b: *std.Build) void {
}).module("vaxis");
var ghostty_vt_for_snap: ?*std.Build.Module = null;
- if (b.lazyDependency("ghostty", .{ .simd = target.result.os.tag != .emscripten })) |dep| {
+ // ghostty's simd libs (simdutf/highway, C++) locate the Apple SDK via
+ // xcrun on darwin targets, so cross-compiling to macOS from elsewhere
+ // uses the scalar fallback (the same configuration the web shell ships).
+ // Native/cross builds hand ghostty the real target (it defaults to the
+ // host otherwise); the web path keeps its original no-target fetch, whose
+ // zig object never uses ghostty's artifacts.
+ // NOTE: darwin targets also need two one-line zig-0.16 fixes in the
+ // pinned ghostty (applied in the zig-pkg cache; re-apply after a fresh
+ // fetch, or bump the pin once upstream carries them):
+ // src/os/mach.zig — std.heap.next_mmap_addr_hint is gone (make the hint
+ // var module-local) and posix.mmap prot is now a packed struct
+ // (.{ .READ = true, .WRITE = true });
+ // src/terminal/kitty/graphics_image.zig:185 — shm_open's variadic mode
+ // literal 0 must be @as(std.c.mode_t, 0).
+ const ghostty_simd = !target.result.os.tag.isDarwin() or b.graph.host.result.os.tag.isDarwin();
+ const ghostty_dep = if (is_emscripten)
+ b.lazyDependency("ghostty", .{ .simd = false })
+ else
+ b.lazyDependency("ghostty", .{ .target = target, .optimize = optimize, .simd = ghostty_simd });
+ if (ghostty_dep) |dep| {
const ghostty_vt = dep.module("ghostty-vt");
ghostty_vt_for_snap = ghostty_vt;
ghostty_vt.addImport("uucode", uucode_mod);
@@ -309,6 +357,8 @@ pub fn build(b: *std.Build) void {
}),
});
if (ghostty_vt_for_snap) |vt| snap.root_module.addImport("ghostty-vt", vt);
+ if (target.result.os.tag == .freebsd or target.result.os.tag == .netbsd or target.result.os.tag == .openbsd)
+ snap.root_module.linkSystemLibrary("util", .{});
b.installArtifact(snap);
const run_snap = b.addRunArtifact(snap);
run_snap.addArtifactArg(exe);