Merge pull request #1295 from mitchellh/build-updates

build: remove global build options, remove tracy
This commit is contained in:
Mitchell Hashimoto
2024-01-13 16:22:03 -08:00
committed by GitHub
20 changed files with 144 additions and 714 deletions

168
build.zig
View File

@ -9,6 +9,7 @@ const font = @import("src/font/main.zig");
const renderer = @import("src/renderer.zig");
const terminfo = @import("src/terminfo/main.zig");
const config_vim = @import("src/config/vim.zig");
const BuildConfig = @import("src/build_config.zig").BuildConfig;
const WasmTarget = @import("src/os/wasm/target.zig").Target;
const LibtoolStep = @import("src/build/LibtoolStep.zig");
const LipoStep = @import("src/build/LipoStep.zig");
@ -34,23 +35,23 @@ comptime {
/// The version of the next release.
const app_version = std.SemanticVersion{ .major = 0, .minor = 1, .patch = 0 };
/// Build options, see the build options help for more info.
var tracy: bool = false;
var flatpak: bool = false;
var app_runtime: apprt.Runtime = .none;
var renderer_impl: renderer.Impl = .opengl;
var font_backend: font.Backend = .freetype;
var libadwaita: bool = false;
pub fn build(b: *std.Build) !void {
const optimize = b.standardOptimizeOption(.{});
const target = target: {
var result = b.standardTargetOptions(.{});
if (result.result.isDarwin()) {
if (result.query.os_version_min == null) {
result.query.os_version_min = .{ .semver = .{ .major = 12, .minor = 0, .patch = 0 } };
}
// On macOS, we specify a minimum supported version. This is important
// to set since header files will use this to determine the availability
// of certain APIs and I believe it is also encoded in the Mach-O
// binaries.
if (result.result.os.tag == .macos and
result.query.os_version_min == null)
{
result.query.os_version_min = .{ .semver = .{
.major = 12,
.minor = 0,
.patch = 0,
} };
}
break :target result;
@ -62,46 +63,42 @@ pub fn build(b: *std.Build) !void {
var env = try std.process.getEnvMap(b.allocator);
defer env.deinit();
// Note: Our tracy usage has a huge memory leak currently so only enable
// this if you really want tracy integration and don't mind the memory leak.
// Or, please contribute a fix because I don't know where it is.
tracy = b.option(
bool,
"tracy",
"Enable Tracy integration (default true in Debug on Linux)",
) orelse false;
// Our build configuration. This is all on a struct so that we can easily
// modify it for specific build types (for example, wasm we strictly
// control our backends).
var config: BuildConfig = .{};
flatpak = b.option(
config.flatpak = b.option(
bool,
"flatpak",
"Build for Flatpak (integrates with Flatpak APIs). Only has an effect targeting Linux.",
) orelse false;
font_backend = b.option(
config.font_backend = b.option(
font.Backend,
"font-backend",
"The font backend to use for discovery and rasterization.",
) orelse font.Backend.default(target.result, wasm_target);
app_runtime = b.option(
config.app_runtime = b.option(
apprt.Runtime,
"app-runtime",
"The app runtime to use. Not all values supported on all platforms.",
) orelse apprt.Runtime.default(target.result);
libadwaita = b.option(
bool,
"gtk-libadwaita",
"Enables the use of libadwaita when using the gtk rendering backend.",
) orelse true;
renderer_impl = b.option(
config.renderer = b.option(
renderer.Impl,
"renderer",
"The app runtime to use. Not all values supported on all platforms.",
) orelse renderer.Impl.default(target.result, wasm_target);
const static = b.option(
config.libadwaita = b.option(
bool,
"gtk-libadwaita",
"Enables the use of libadwaita when using the gtk rendering backend.",
) orelse true;
config.static = b.option(
bool,
"static",
"Statically build as much as possible for the exe",
@ -189,10 +186,10 @@ pub fn build(b: *std.Build) !void {
b.enable_wasmtime = true;
// Add our benchmarks
try benchSteps(b, target, optimize, emit_bench);
try benchSteps(b, target, optimize, config, emit_bench);
// We only build an exe if we have a runtime set.
const exe_: ?*std.Build.Step.Compile = if (app_runtime != .none) b.addExecutable(.{
const exe_: ?*std.Build.Step.Compile = if (config.app_runtime != .none) b.addExecutable(.{
.name = "ghostty",
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
@ -200,25 +197,20 @@ pub fn build(b: *std.Build) !void {
}) else null;
const exe_options = b.addOptions();
config.addOptions(exe_options);
exe_options.addOption(std.SemanticVersion, "app_version", version);
exe_options.addOption([:0]const u8, "app_version_string", try std.fmt.allocPrintZ(
b.allocator,
"{}",
.{version},
));
exe_options.addOption(bool, "tracy_enabled", tracy);
exe_options.addOption(bool, "flatpak", flatpak);
exe_options.addOption(apprt.Runtime, "app_runtime", app_runtime);
exe_options.addOption(font.Backend, "font_backend", font_backend);
exe_options.addOption(renderer.Impl, "renderer", renderer_impl);
exe_options.addOption(bool, "libadwaita", libadwaita);
// Exe
if (exe_) |exe| {
exe.root_module.addOptions("build_options", exe_options);
// Add the shared dependencies
_ = try addDeps(b, exe, static);
_ = try addDeps(b, exe, config);
// If we're in NixOS but not in the shell environment then we issue
// a warning because the rpath may not be setup properly.
@ -257,7 +249,7 @@ pub fn build(b: *std.Build) !void {
// If we're installing, we get the install step so we can add
// additional dependencies to it.
const install_step = if (app_runtime != .none) step: {
const install_step = if (config.app_runtime != .none) step: {
const step = b.addInstallArtifact(exe, .{});
b.getInstallStep().dependOn(&step.step);
break :step step;
@ -277,7 +269,7 @@ pub fn build(b: *std.Build) !void {
}
// App (Mac)
if (target.result.isDarwin()) {
if (target.result.os.tag == .macos) {
const bin_install = b.addInstallFile(
exe.getEmittedBin(),
"Ghostty.app/Contents/MacOS/ghostty",
@ -298,7 +290,7 @@ pub fn build(b: *std.Build) !void {
});
b.getInstallStep().dependOn(&install.step);
if (target.result.isDarwin() and exe_ != null) {
if (target.result.os.tag == .macos and exe_ != null) {
const mac_install = b.addInstallDirectory(options: {
var copy = install.options;
copy.install_dir = .{
@ -321,7 +313,7 @@ pub fn build(b: *std.Build) !void {
});
b.getInstallStep().dependOn(&install.step);
if (target.result.isDarwin() and exe_ != null) {
if (target.result.os.tag == .macos and exe_ != null) {
const mac_install = b.addInstallDirectory(options: {
var copy = install.options;
copy.install_dir = .{
@ -345,7 +337,7 @@ pub fn build(b: *std.Build) !void {
const src_source = wf.add("share/terminfo/ghostty.terminfo", str.items);
const src_install = b.addInstallFile(src_source, "share/terminfo/ghostty.terminfo");
b.getInstallStep().dependOn(&src_install.step);
if (target.result.isDarwin() and exe_ != null) {
if (target.result.os.tag == .macos and exe_ != null) {
const mac_src_install = b.addInstallFile(
src_source,
"Ghostty.app/Contents/Resources/terminfo/ghostty.terminfo",
@ -366,7 +358,7 @@ pub fn build(b: *std.Build) !void {
const cap_install = b.addInstallFile(out_source, "share/terminfo/ghostty.termcap");
b.getInstallStep().dependOn(&cap_install.step);
if (target.result.isDarwin() and exe_ != null) {
if (target.result.os.tag == .macos and exe_ != null) {
const mac_cap_install = b.addInstallFile(
out_source,
"Ghostty.app/Contents/Resources/terminfo/ghostty.termcap",
@ -395,7 +387,7 @@ pub fn build(b: *std.Build) !void {
b.getInstallStep().dependOn(&copy_step.step);
}
if (target.result.isDarwin() and exe_ != null) {
if (target.result.os.tag == .macos and exe_ != null) {
const copy_step = RunStep.create(b, "copy terminfo db");
copy_step.addArgs(&.{ "cp", "-R" });
copy_step.addFileArg(path);
@ -425,7 +417,7 @@ pub fn build(b: *std.Build) !void {
// https://developer.gnome.org/documentation/guidelines/maintainer/integrating.html
// Desktop file so that we have an icon and other metadata
if (flatpak) {
if (config.flatpak) {
b.installFile("dist/linux/app-flatpak.desktop", "share/applications/com.mitchellh.ghostty.desktop");
} else {
b.installFile("dist/linux/app.desktop", "share/applications/com.mitchellh.ghostty.desktop");
@ -446,6 +438,17 @@ pub fn build(b: *std.Build) !void {
// On Mac we can build the embedding library. This only handles the macOS lib.
if (builtin.target.isDarwin() and target.result.os.tag == .macos) {
// Modify our build configuration for macOS builds.
const macos_config: BuildConfig = config: {
var copy = config;
// Always static for the macOS app because we want all of our
// dependencies in a fat static library.
copy.static = true;
break :config copy;
};
const static_lib_aarch64 = lib: {
const lib = b.addStaticLibrary(.{
.name = "ghostty",
@ -462,7 +465,7 @@ pub fn build(b: *std.Build) !void {
lib.root_module.addOptions("build_options", exe_options);
// Create a single static lib with all our dependencies merged
var lib_list = try addDeps(b, lib, true);
var lib_list = try addDeps(b, lib, macos_config);
try lib_list.append(lib.getEmittedBin());
const libtool = LibtoolStep.create(b, .{
.name = "ghostty",
@ -491,7 +494,7 @@ pub fn build(b: *std.Build) !void {
lib.root_module.addOptions("build_options", exe_options);
// Create a single static lib with all our dependencies merged
var lib_list = try addDeps(b, lib, true);
var lib_list = try addDeps(b, lib, macos_config);
try lib_list.append(lib.getEmittedBin());
const libtool = LibtoolStep.create(b, .{
.name = "ghostty",
@ -557,6 +560,20 @@ pub fn build(b: *std.Build) !void {
}),
};
// Modify our build configuration for wasm builds.
const wasm_config: BuildConfig = config: {
var copy = config;
// Always static for the wasm app because we want all of our
// dependencies in a fat static library.
copy.static = true;
// Backends that are fixed for wasm
copy.font_backend = .web_canvas;
break :config copy;
};
// Whether we're using wasm shared memory. Some behaviors change.
// For now we require this but I wanted to make the code handle both
// up front.
@ -585,7 +602,7 @@ pub fn build(b: *std.Build) !void {
wasm.root_module.stack_protector = false;
// Wasm-specific deps
_ = try addDeps(b, wasm, true);
_ = try addDeps(b, wasm, wasm_config);
// Install
const wasm_install = b.addInstallArtifact(wasm, .{});
@ -605,7 +622,7 @@ pub fn build(b: *std.Build) !void {
});
main_test.root_module.addOptions("build_options", exe_options);
_ = try addDeps(b, main_test, true);
_ = try addDeps(b, main_test, wasm_config);
test_step.dependOn(&main_test.step);
}
@ -642,7 +659,11 @@ pub fn build(b: *std.Build) !void {
{
if (emit_test_exe) b.installArtifact(main_test);
_ = try addDeps(b, main_test, true);
_ = try addDeps(b, main_test, config: {
var copy = config;
copy.static = true;
break :config copy;
});
main_test.root_module.addOptions("build_options", exe_options);
const test_run = b.addRunArtifact(main_test);
@ -658,7 +679,7 @@ const LazyPathList = std.ArrayList(std.Build.LazyPath);
fn addDeps(
b: *std.Build,
step: *std.Build.Step.Compile,
static: bool,
config: BuildConfig,
) !LazyPathList {
var static_libs = LazyPathList.init(b.allocator);
errdefer static_libs.deinit();
@ -743,10 +764,6 @@ fn addDeps(
.cpu = cpu_opts,
.optimize = step.root_module.optimize.?,
});
const tracy_dep = b.dependency("tracy", .{
.target = target_triple,
.optimize = step.root_module.optimize.?,
});
const zlib_dep = b.dependency("zlib", .{
.target = target_triple,
.cpu = cpu_opts,
@ -757,7 +774,7 @@ fn addDeps(
.cpu = cpu_opts,
.optimize = step.root_module.optimize.?,
.@"enable-freetype" = true,
.@"enable-coretext" = font_backend.hasCoretext(),
.@"enable-coretext" = config.font_backend.hasCoretext(),
});
const ziglyph_dep = b.dependency("ziglyph", .{
.target = target_triple,
@ -767,9 +784,6 @@ fn addDeps(
// Wasm we do manually since it is such a different build.
if (step.rootModuleTarget().cpu.arch == .wasm32) {
// We link this package but its a no-op since Tracy
// never actually WORKS with wasm.
step.root_module.addImport("tracy", tracy_dep.module("tracy"));
step.root_module.addImport("zig-js", js_dep.module("zig-js"));
return static_libs;
@ -800,7 +814,7 @@ fn addDeps(
// We always need the Zig packages
// TODO: This can't be the right way to use the new Zig modules system,
// so take a closer look at this again later.
if (font_backend.hasFontconfig()) step.root_module.addImport(
if (config.font_backend.hasFontconfig()) step.root_module.addImport(
"fontconfig",
fontconfig_dep.module("fontconfig"),
);
@ -827,13 +841,6 @@ fn addDeps(
step.linkLibrary(cimgui_dep.artifact("cimgui"));
try static_libs.append(cimgui_dep.artifact("cimgui").getEmittedBin());
// Tracy
step.root_module.addImport("tracy", tracy_dep.module("tracy"));
if (tracy) {
step.linkLibrary(tracy_dep.artifact("tracy"));
try static_libs.append(tracy_dep.artifact("tracy").getEmittedBin());
}
// Glslang
step.linkLibrary(glslang_dep.artifact("glslang"));
try static_libs.append(glslang_dep.artifact("glslang").getEmittedBin());
@ -843,7 +850,7 @@ fn addDeps(
try static_libs.append(spirv_cross_dep.artifact("spirv_cross").getEmittedBin());
// Dynamic link
if (!static) {
if (!config.static) {
step.addIncludePath(freetype_dep.path(""));
step.linkSystemLibrary2("bzip2", dynamic_link_opts);
step.linkSystemLibrary2("freetype2", dynamic_link_opts);
@ -853,13 +860,13 @@ fn addDeps(
step.linkSystemLibrary2("pixman-1", dynamic_link_opts);
step.linkSystemLibrary2("zlib", dynamic_link_opts);
if (font_backend.hasFontconfig()) {
if (config.font_backend.hasFontconfig()) {
step.linkSystemLibrary2("fontconfig", dynamic_link_opts);
}
}
// Other dependencies, we may dynamically link
if (static) {
if (config.static) {
step.linkLibrary(oniguruma_dep.artifact("oniguruma"));
try static_libs.append(oniguruma_dep.artifact("oniguruma").getEmittedBin());
@ -882,7 +889,7 @@ fn addDeps(
try static_libs.append(pixman_dep.artifact("pixman").getEmittedBin());
// Only Linux gets fontconfig
if (font_backend.hasFontconfig()) {
if (config.font_backend.hasFontconfig()) {
// Fontconfig
step.linkLibrary(fontconfig_dep.artifact("fontconfig"));
}
@ -898,9 +905,9 @@ fn addDeps(
// When we're targeting flatpak we ALWAYS link GTK so we
// get access to glib for dbus.
if (flatpak) step.linkSystemLibrary2("gtk4", dynamic_link_opts);
if (config.flatpak) step.linkSystemLibrary2("gtk4", dynamic_link_opts);
switch (app_runtime) {
switch (config.app_runtime) {
.none => {},
.glfw => {
@ -910,7 +917,7 @@ fn addDeps(
.gtk => {
step.linkSystemLibrary2("gtk4", dynamic_link_opts);
if (libadwaita) step.linkSystemLibrary2("adwaita-1", dynamic_link_opts);
if (config.libadwaita) step.linkSystemLibrary2("adwaita-1", dynamic_link_opts);
},
}
}
@ -922,6 +929,7 @@ fn benchSteps(
b: *std.Build,
target: std.Build.ResolvedTarget,
optimize: std.builtin.OptimizeMode,
config: BuildConfig,
install: bool,
) !void {
// Open the directory ./src/bench
@ -956,7 +964,11 @@ fn benchSteps(
// .main_pkg_path = .{ .path = "./src" },
});
if (install) b.installArtifact(c_exe);
_ = try addDeps(b, c_exe, true);
_ = try addDeps(b, c_exe, config: {
var copy = config;
copy.static = true;
break :config copy;
});
}
}

View File

@ -35,7 +35,6 @@
.oniguruma = .{ .path = "./pkg/oniguruma" },
.opengl = .{ .path = "./pkg/opengl" },
.pixman = .{ .path = "./pkg/pixman" },
.tracy = .{ .path = "./pkg/tracy" },
.zlib = .{ .path = "./pkg/zlib" },
// Shader translation

View File

@ -1,3 +1,3 @@
# This file is auto-generated! check build-support/check-zig-cache-hash.sh for
# more details.
"sha256-1qlnSOyr2C9DtUdf+4QRNrBr4vUM1nVnv/mVUXxE5fA="
"sha256-1dYTlmmBVvLyWxcJV2mPetOe3ECDzL6UfqnKr2Azl8M="

View File

@ -1,91 +0,0 @@
const std = @import("std");
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
_ = b.addModule("tracy", .{ .root_source_file = .{ .path = "tracy.zig" } });
const upstream = b.dependency("tracy", .{});
const lib = b.addStaticLibrary(.{
.name = "tracy",
.target = target,
.optimize = optimize,
});
lib.linkLibC();
lib.linkLibCpp();
if (target.result.os.tag == .windows) {
lib.linkSystemLibrary("Advapi32");
lib.linkSystemLibrary("User32");
lib.linkSystemLibrary("Ws2_32");
lib.linkSystemLibrary("DbgHelp");
}
lib.addIncludePath(upstream.path(""));
var flags = std.ArrayList([]const u8).init(b.allocator);
defer flags.deinit();
try flags.appendSlice(&.{
"-DTRACY_ENABLE",
"-fno-sanitize=undefined",
});
if (target.result.os.tag == .windows) {
try flags.appendSlice(&.{
"-D_WIN32_WINNT=0x601",
});
}
lib.addCSourceFile(.{
.file = upstream.path("TracyClient.cpp"),
.flags = flags.items,
});
lib.installHeadersDirectoryOptions(.{
.source_dir = upstream.path(""),
.install_dir = .header,
.install_subdir = "",
.include_extensions = &.{ ".h", ".hpp" },
});
b.installArtifact(lib);
}
const headers = &.{
"TracyC.h",
"TracyOpenGL.hpp",
"Tracy.hpp",
"TracyD3D11.hpp",
"TracyD3D12.hpp",
"TracyOpenCL.hpp",
"TracyVulkan.hpp",
"client/TracyCallstack.h",
"client/TracyScoped.hpp",
"client/TracyStringHelpers.hpp",
"client/TracySysTrace.hpp",
"client/TracyDxt1.hpp",
"client/TracyRingBuffer.hpp",
"client/tracy_rpmalloc.hpp",
"client/TracyDebug.hpp",
"client/TracyLock.hpp",
"client/TracyThread.hpp",
"client/TracyArmCpuTable.hpp",
"client/TracyProfiler.hpp",
"client/TracyCallstack.hpp",
"client/TracySysTime.hpp",
"client/TracyFastVector.hpp",
"common/TracyApi.h",
"common/TracyYield.hpp",
"common/tracy_lz4hc.hpp",
"common/TracySystem.hpp",
"common/TracyProtocol.hpp",
"common/TracyQueue.hpp",
"common/TracyUwp.hpp",
"common/TracyAlloc.hpp",
"common/TracyAlign.hpp",
"common/TracyForceInline.hpp",
"common/TracyColor.hpp",
"common/tracy_lz4.hpp",
"common/TracyStackFrames.hpp",
"common/TracySocket.hpp",
"common/TracyMutex.hpp",
};

View File

@ -1,10 +0,0 @@
.{
.name = "tracy",
.version = "0.8.2",
.dependencies = .{
.tracy = .{
.url = "https://github.com/wolfpld/tracy/archive/refs/tags/v0.8.2.1.tar.gz",
.hash = "1220289ca424ec488316b75c992b9f02846caaa70287f958b3966e02d5ca81789d27",
},
},
}

View File

@ -1,271 +0,0 @@
//! Tracy API.
//!
//! Forked and modified from https://github.com/SpexGuy/Zig-Tracy
const std = @import("std");
const builtin = @import("builtin");
const root = @import("root");
const SourceLocation = std.builtin.SourceLocation;
// Tracy is enabled if the root function tracy_enabled returns true.
pub const enabled = @hasDecl(root, "tracy_enabled") and root.tracy_enabled();
// Bring in the correct implementation depending on if we're enabled or not.
// See Impl for all the real doc comments.
pub usingnamespace if (enabled) Impl else Noop;
const Impl = struct {
const c = @cImport({
//uncomment to enable callstacks, very slow
//@cDefine("TRACY_CALLSTACK", "");
@cDefine("TRACY_ENABLE", "");
@cInclude("TracyC.h");
});
const has_callstack_support = @hasDecl(c, "TRACY_HAS_CALLSTACK") and @hasDecl(c, "TRACY_CALLSTACK");
const callstack_enabled: c_int = if (has_callstack_support) c.TRACY_CALLSTACK else 0;
const callstack_depth = 10; // TODO configurable
/// A zone represents the lifetime of a special on-stack profiler variable.
/// Typically it would exist for the duration of a whole scope of the
/// profiled function, but you also can measure time spent in scopes of a
/// for-loop or an if-branch.
pub const Zone = struct {
zone: c.___tracy_c_zone_context,
/// Text description of a zone.
pub inline fn text(self: Zone, val: []const u8) void {
c.___tracy_emit_zone_text(self.zone, val.ptr, val.len);
}
/// Name of the zone.
pub inline fn name(self: Zone, val: []const u8) void {
c.___tracy_emit_zone_name(self.zone, val.ptr, val.len);
}
/// Color of the zone in the UI. Specify the value as RGB
/// using hex: 0xRRGGBB.
pub inline fn color(self: Zone, val: u32) void {
c.___tracy_emit_zone_color(self.zone, val);
}
/// A value associated with the zone.
pub inline fn value(self: Zone, val: u64) void {
c.___tracy_emit_zone_value(self.zone, val);
}
/// End the zone.
pub inline fn end(self: Zone) void {
c.___tracy_emit_zone_end(self.zone);
}
};
/// Tracy profiles within the context of a frame. This represents
/// a single frame.
pub fn Frame(comptime name: [:0]const u8) type {
return struct {
pub fn end(_: @This()) void {
c.___tracy_emit_frame_mark_end(name.ptr);
}
};
}
/// allocator returns an allocator that tracks allocs/frees.
pub fn allocator(
parent: std.mem.Allocator,
comptime name: ?[:0]const u8,
) Allocator(name) {
return Allocator(name).init(parent);
}
/// Returns an allocator type with the given name.
pub fn Allocator(comptime name: ?[:0]const u8) type {
return struct {
parent: std.mem.Allocator,
const Self = @This();
pub fn init(parent: std.mem.Allocator) Self {
return .{ .parent = parent };
}
pub fn allocator(self: *Self) std.mem.Allocator {
return .{
.ptr = self,
.vtable = &.{
.alloc = allocFn,
.resize = resizeFn,
.free = freeFn,
},
};
}
fn allocFn(
ctx: *anyopaque,
len: usize,
log2_ptr_align: u8,
ret_addr: usize,
) ?[*]u8 {
const self = @as(*Self, @ptrCast(@alignCast(ctx)));
const result = self.parent.rawAlloc(len, log2_ptr_align, ret_addr);
if (result) |data| {
if (len != 0) {
if (name) |n| {
allocNamed(data.ptr, len, n);
} else {
alloc(data, len);
}
}
}
return result;
}
fn resizeFn(
ctx: *anyopaque,
buf: []u8,
log2_buf_align: u8,
new_len: usize,
ret_addr: usize,
) bool {
const self = @as(*Self, @ptrCast(@alignCast(ctx)));
if (self.parent.rawResize(buf, log2_buf_align, new_len, ret_addr)) {
if (name) |n| {
freeNamed(buf.ptr, n);
allocNamed(buf.ptr, new_len, n);
} else {
free(buf.ptr);
alloc(buf.ptr, new_len);
}
return true;
}
// during normal operation the compiler hits this case thousands of times due to this
// emitting messages for it is both slow and causes clutter
return false;
}
fn freeFn(
ctx: *anyopaque,
buf: []u8,
log2_buf_align: u8,
ret_addr: usize,
) void {
const self = @as(*Self, @ptrCast(@alignCast(ctx)));
self.parent.rawFree(buf, log2_buf_align, ret_addr);
if (buf.len != 0) {
if (name) |n| {
freeNamed(buf.ptr, n);
} else {
free(buf.ptr);
}
}
}
};
}
/// Start a trace. Defer calling end() to end the trace.
pub inline fn trace(comptime src: SourceLocation) Zone {
const static = struct {
var loc: c.___tracy_source_location_data = undefined;
};
static.loc = .{
.name = null,
.function = src.fn_name.ptr,
.file = src.file.ptr,
.line = src.line,
.color = 0,
};
const zone = if (has_callstack_support)
c.___tracy_emit_zone_begin_callstack(&static.loc, callstack_depth, 1)
else
c.___tracy_emit_zone_begin(&static.loc, 1);
return Zone{ .zone = zone };
}
/// Mark the boundary of a frame. Good for continuous frames. For
/// discontinuous frames, use frame() and defer end().
pub inline fn frameMark() void {
c.___tracy_emit_frame_mark(null);
}
/// Start a discontinuous frame.
pub inline fn frame(comptime name: [:0]const u8) Frame(name) {
c.___tracy_emit_frame_mark_start(name.ptr);
return .{};
}
/// Name the current thread.
pub inline fn setThreadName(comptime name: [:0]const u8) void {
c.___tracy_set_thread_name(name.ptr);
}
inline fn alloc(ptr: [*]u8, len: usize) void {
if (has_callstack_support) {
c.___tracy_emit_memory_alloc_callstack(ptr, len, callstack_depth, 0);
} else {
c.___tracy_emit_memory_alloc(ptr, len, 0);
}
}
inline fn allocNamed(ptr: [*]u8, len: usize, comptime name: [:0]const u8) void {
if (has_callstack_support) {
c.___tracy_emit_memory_alloc_callstack_named(ptr, len, callstack_depth, 0, name.ptr);
} else {
c.___tracy_emit_memory_alloc_named(ptr, len, 0, name.ptr);
}
}
inline fn free(ptr: [*]u8) void {
if (has_callstack_support) {
c.___tracy_emit_memory_free_callstack(ptr, callstack_depth, 0);
} else {
c.___tracy_emit_memory_free(ptr, 0);
}
}
inline fn freeNamed(ptr: [*]u8, comptime name: [:0]const u8) void {
if (has_callstack_support) {
c.___tracy_emit_memory_free_callstack_named(ptr, callstack_depth, 0, name.ptr);
} else {
c.___tracy_emit_memory_free_named(ptr, 0, name.ptr);
}
}
};
const Noop = struct {
pub const Zone = struct {
pub inline fn text(_: Zone, _: []const u8) void {}
pub inline fn name(_: Zone, _: []const u8) void {}
pub inline fn color(_: Zone, _: u32) void {}
pub inline fn value(_: Zone, _: u64) void {}
pub inline fn end(_: Zone) void {}
};
pub fn Frame(comptime _: [:0]const u8) type {
return struct {
pub fn end(_: @This()) void {}
};
}
pub inline fn trace(comptime src: SourceLocation) Zone {
_ = src;
return .{};
}
pub inline fn frameMark() void {}
pub inline fn frame(comptime name: [:0]const u8) Frame(name) {
return .{};
}
pub inline fn setThreadName(comptime name: [:0]const u8) void {
_ = name;
}
};
test {}

View File

@ -30,7 +30,6 @@ const imgui = @import("imgui");
const Pty = @import("pty.zig").Pty;
const font = @import("font/main.zig");
const Command = @import("Command.zig");
const trace = @import("tracy").trace;
const terminal = @import("terminal/main.zig");
const configpkg = @import("config.zig");
const input = @import("input.zig");
@ -1048,9 +1047,6 @@ fn queueRender(self: *Surface) !void {
}
pub fn sizeCallback(self: *Surface, size: apprt.SurfaceSize) !void {
const tracy = trace(@src());
defer tracy.end();
const new_screen_size: renderer.ScreenSize = .{
.width = size.width,
.height = size.height,
@ -1453,9 +1449,6 @@ pub fn scrollCallback(
yoff: f64,
scroll_mods: input.ScrollMods,
) !void {
const tracy = trace(@src());
defer tracy.end();
// log.info("SCROLL: xoff={} yoff={} mods={}", .{ xoff, yoff, scroll_mods });
// Always show the mouse again if it is hidden
@ -1919,9 +1912,6 @@ pub fn mouseButtonCallback(
) !void {
// log.debug("mouse action={} button={} mods={}", .{ action, button, mods });
const tracy = trace(@src());
defer tracy.end();
// If we have an inspector, we always queue a render
if (self.inspector) |insp| {
defer self.queueRender() catch {};
@ -2275,9 +2265,6 @@ pub fn cursorPosCallback(
self: *Surface,
pos: apprt.CursorPos,
) !void {
const tracy = trace(@src());
defer tracy.end();
// Always show the mouse again if it is hidden
if (self.mouse.hidden) self.showMouse();

View File

@ -8,7 +8,6 @@ const builtin = @import("builtin");
const build_config = @import("../build_config.zig");
const assert = std.debug.assert;
const Allocator = std.mem.Allocator;
const trace = @import("tracy").trace;
const glfw = @import("glfw");
const macos = @import("macos");
const objc = @import("objc");
@ -741,9 +740,6 @@ pub const Surface = struct {
}
fn charCallback(window: glfw.Window, codepoint: u21) void {
const tracy = trace(@src());
defer tracy.end();
const core_win = window.getUserPointer(CoreSurface) orelse return;
// We need a key event in order to process the charcallback. If it
@ -780,8 +776,6 @@ pub const Surface = struct {
glfw_action: glfw.Action,
glfw_mods: glfw.Mods,
) void {
const tracy = trace(@src());
defer tracy.end();
_ = scancode;
const core_win = window.getUserPointer(CoreSurface) orelse return;
@ -954,9 +948,6 @@ pub const Surface = struct {
}
fn focusCallback(window: glfw.Window, focused: bool) void {
const tracy = trace(@src());
defer tracy.end();
const core_win = window.getUserPointer(CoreSurface) orelse return;
core_win.focusCallback(focused) catch |err| {
log.err("error in focus callback err={}", .{err});
@ -965,9 +956,6 @@ pub const Surface = struct {
}
fn refreshCallback(window: glfw.Window) void {
const tracy = trace(@src());
defer tracy.end();
const core_win = window.getUserPointer(CoreSurface) orelse return;
core_win.refreshCallback() catch |err| {
log.err("error in refresh callback err={}", .{err});
@ -976,9 +964,6 @@ pub const Surface = struct {
}
fn scrollCallback(window: glfw.Window, xoff: f64, yoff: f64) void {
const tracy = trace(@src());
defer tracy.end();
// Glfw doesn't support any of the scroll mods.
const scroll_mods: input.ScrollMods = .{};
@ -994,9 +979,6 @@ pub const Surface = struct {
unscaled_xpos: f64,
unscaled_ypos: f64,
) void {
const tracy = trace(@src());
defer tracy.end();
const core_win = window.getUserPointer(CoreSurface) orelse return;
// Convert our unscaled x/y to scaled.
@ -1026,9 +1008,6 @@ pub const Surface = struct {
glfw_action: glfw.Action,
glfw_mods: glfw.Mods,
) void {
const tracy = trace(@src());
defer tracy.end();
const core_win = window.getUserPointer(CoreSurface) orelse return;
// Convert glfw button to input button
@ -1061,9 +1040,6 @@ pub const Surface = struct {
}
fn dropCallback(window: glfw.Window, paths: [][*:0]const u8) void {
const tracy = trace(@src());
defer tracy.end();
const surface = window.getUserPointer(CoreSurface) orelse return;
var list = std.ArrayList(u8).init(surface.alloc);

View File

@ -10,6 +10,46 @@ const apprt = @import("apprt.zig");
const font = @import("font/main.zig");
const rendererpkg = @import("renderer.zig");
/// The build configuratin options. This may not be all available options
/// to `zig build` but it contains all the options that the Ghostty source
/// needs to know about at comptime.
///
/// We put this all in a single struct so that we can check compatibility
/// between options, make it easy to copy and mutate options for different
/// build types, etc.
pub const BuildConfig = struct {
static: bool = false,
flatpak: bool = false,
libadwaita: bool = false,
app_runtime: apprt.Runtime = .none,
renderer: rendererpkg.Impl = .opengl,
font_backend: font.Backend = .freetype,
/// Configure the build options with our values.
pub fn addOptions(self: BuildConfig, step: *std.Build.Step.Options) void {
// We need to break these down individual because addOption doesn't
// support all types.
step.addOption(bool, "flatpak", self.flatpak);
step.addOption(bool, "libadwaita", self.libadwaita);
step.addOption(apprt.Runtime, "app_runtime", self.app_runtime);
step.addOption(font.Backend, "font_backend", self.font_backend);
step.addOption(rendererpkg.Impl, "renderer", self.renderer);
}
/// Rehydrate our BuildConfig from the comptime options. Note that not all
/// options are available at comptime, so look closely at this implementation
/// to see what is and isn't available.
pub fn fromOptions() BuildConfig {
return .{
.flatpak = options.flatpak,
.libadwaita = options.libadwaita,
.app_runtime = std.meta.stringToEnum(apprt.Runtime, @tagName(options.app_runtime)).?,
.font_backend = std.meta.stringToEnum(font.Backend, @tagName(options.font_backend)).?,
.renderer = std.meta.stringToEnum(rendererpkg.Impl, @tagName(options.renderer)).?,
};
}
};
/// The semantic version of this build.
pub const version = options.app_version;
pub const version_string = options.app_version_string;
@ -18,26 +58,14 @@ pub const version_string = options.app_version_string;
/// building a standalone exe, an embedded lib, etc.
pub const artifact = Artifact.detect();
/// The runtime to back exe artifacts with.
pub const app_runtime: apprt.Runtime = switch (artifact) {
.lib => .none,
else => std.meta.stringToEnum(apprt.Runtime, @tagName(options.app_runtime)).?,
};
/// The font backend desired for the build.
pub const font_backend: font.Backend = std.meta.stringToEnum(
font.Backend,
@tagName(options.font_backend),
).?;
/// The renderer implementation to use.
pub const renderer: rendererpkg.Impl = std.meta.stringToEnum(
rendererpkg.Impl,
@tagName(options.renderer),
).?;
/// We want to integrate with Flatpak APIs.
/// Our build configuration. We re-export a lot of these back at the
/// top-level so its a bit cleaner to use throughout the code. See the doc
/// comments in BuildConfig for details on each.
pub const config = BuildConfig.fromOptions();
pub const flatpak = options.flatpak;
pub const app_runtime: apprt.Runtime = config.app_runtime;
pub const font_backend: font.Backend = config.font_backend;
pub const renderer: rendererpkg.Impl = config.renderer;
pub const Artifact = enum {
/// Standalone executable

View File

@ -2,7 +2,6 @@ const std = @import("std");
const assert = std.debug.assert;
const Allocator = std.mem.Allocator;
const harfbuzz = @import("harfbuzz");
const trace = @import("tracy").trace;
const font = @import("../main.zig");
const Face = font.Face;
const DeferredFace = font.DeferredFace;
@ -106,9 +105,6 @@ pub const Shaper = struct {
///
/// If there is not enough space in the cell buffer, an error is returned.
pub fn shape(self: *Shaper, run: font.shape.TextRun) ![]const font.shape.Cell {
const tracy = trace(@src());
defer tracy.end();
// We only do shaping if the font is not a special-case. For special-case
// fonts, the codepoint == glyph_index so we don't need to run any shaping.
if (run.font_index.special() == null) {

View File

@ -4,7 +4,6 @@ const Allocator = std.mem.Allocator;
const font = @import("../main.zig");
const shape = @import("../shape.zig");
const terminal = @import("../../terminal/main.zig");
const trace = @import("tracy").trace;
/// A single text run. A text run is only valid for one Shaper instance and
/// until the next run is created. A text run never goes across multiple
@ -33,9 +32,6 @@ pub const RunIterator = struct {
i: usize = 0,
pub fn next(self: *RunIterator, alloc: Allocator) !?TextRun {
const tracy = trace(@src());
defer tracy.end();
// Trim the right side of a row that might be empty
const max: usize = max: {
var j: usize = self.row.lenCells();

View File

@ -7,7 +7,6 @@ const glfw = @import("glfw");
const glslang = @import("glslang");
const macos = @import("macos");
const oni = @import("oniguruma");
const tracy = @import("tracy");
const cli = @import("cli.zig");
const internal_os = @import("os/main.zig");
const xev = @import("xev");
@ -105,11 +104,6 @@ pub fn main() !MainReturn {
try app_runtime.run();
}
// Required by tracy/tracy.zig to enable/disable tracy support.
pub fn tracy_enabled() bool {
return options.tracy_enabled;
}
pub const std_options = struct {
// Our log level is always at least info in every build mode.
pub const log_level: std.log.Level = switch (builtin.mode) {
@ -172,7 +166,6 @@ pub const GlobalState = struct {
gpa: ?GPA,
alloc: std.mem.Allocator,
tracy: if (tracy.enabled) ?tracy.Allocator(null) else void,
action: ?cli.Action,
logging: Logging,
@ -194,7 +187,6 @@ pub const GlobalState = struct {
self.* = .{
.gpa = null,
.alloc = undefined,
.tracy = undefined,
.action = null,
.logging = .{ .stderr = {} },
.resources_dir = null,
@ -218,19 +210,12 @@ pub const GlobalState = struct {
break :gpa GPA{};
};
self.alloc = alloc: {
const base = if (self.gpa) |*value|
value.allocator()
else if (builtin.link_libc)
std.heap.c_allocator
else
unreachable;
// If we're tracing, wrap the allocator
if (!tracy.enabled) break :alloc base;
self.tracy = tracy.allocator(base, null);
break :alloc self.tracy.?.allocator();
};
self.alloc = if (self.gpa) |*value|
value.allocator()
else if (builtin.link_libc)
std.heap.c_allocator
else
unreachable;
// We first try to parse any action that we may be executing.
self.action = try cli.Action.detectCLI(self.alloc);
@ -297,10 +282,6 @@ pub const GlobalState = struct {
// the point at which it will output if there were safety violations.
_ = value.deinit();
}
if (tracy.enabled) {
self.tracy = null;
}
}
};
test {

View File

@ -19,7 +19,6 @@ const renderer = @import("../renderer.zig");
const terminal = @import("../terminal/main.zig");
const Terminal = terminal.Terminal;
const gl = @import("opengl");
const trace = @import("tracy").trace;
const math = @import("../math.zig");
const Surface = @import("../Surface.zig");
@ -946,9 +945,6 @@ pub fn rebuildCells(
cursor_style_: ?renderer.CursorStyle,
color_palette: *const terminal.color.Palette,
) !void {
const t = trace(@src());
defer t.end();
// Bg cells at most will need space for the visible screen size
self.cells_bg.clearRetainingCapacity();
try self.cells_bg.ensureTotalCapacity(self.alloc, screen.rows * screen.cols);
@ -1344,9 +1340,6 @@ fn updateCell(
x: usize,
y: usize,
) !bool {
const t = trace(@src());
defer t.end();
const BgFg = struct {
/// Background is optional because in un-inverted mode
/// it may just be equivalent to the default background in
@ -1781,9 +1774,6 @@ fn flushAtlas(self: *OpenGL) !void {
/// Render renders the current cell state. This will not modify any of
/// the cells.
pub fn drawFrame(self: *OpenGL, surface: *apprt.Surface) !void {
const t = trace(@src());
defer t.end();
// If we're in single-threaded more we grab a lock since we use shared data.
if (single_threaded_draw) self.draw_mutex.lock();
defer if (single_threaded_draw) self.draw_mutex.unlock();

View File

@ -9,8 +9,6 @@ const renderer = @import("../renderer.zig");
const apprt = @import("../apprt.zig");
const configpkg = @import("../config.zig");
const BlockingQueue = @import("../blocking_queue.zig").BlockingQueue;
const tracy = @import("tracy");
const trace = tracy.trace;
const App = @import("../App.zig");
const Allocator = std.mem.Allocator;
@ -177,7 +175,6 @@ pub fn threadMain(self: *Thread) void {
fn threadMain_(self: *Thread) !void {
defer log.debug("renderer thread exited", .{});
tracy.setThreadName("renderer");
// Run our thread start/end callbacks. This is important because some
// renderers have to do per-thread setup. For example, OpenGL has to set
@ -242,9 +239,6 @@ fn stopDrawTimer(self: *Thread) void {
/// Drain the mailbox.
fn drainMailbox(self: *Thread) !void {
const zone = trace(@src());
defer zone.end();
while (self.mailbox.pop()) |message| {
log.debug("mailbox message={}", .{message});
switch (message) {
@ -358,9 +352,6 @@ fn wakeupCallback(
return .rearm;
};
const zone = trace(@src());
defer zone.end();
const t = self_.?;
// When we wake up, we check the mailbox. Mailbox producers should
@ -425,9 +416,6 @@ fn renderCallback(
_: *xev.Completion,
r: xev.Timer.RunError!void,
) xev.CallbackAction {
const zone = trace(@src());
defer zone.end();
_ = r catch unreachable;
const t = self_ orelse {
// This shouldn't happen so we log it.
@ -470,9 +458,6 @@ fn cursorTimerCallback(
_: *xev.Completion,
r: xev.Timer.RunError!void,
) xev.CallbackAction {
const zone = trace(@src());
defer zone.end();
_ = r catch |err| switch (err) {
// This is sent when our timer is canceled. That's fine.
error.Canceled => return .disarm,

View File

@ -6,7 +6,6 @@ const Parser = @This();
const std = @import("std");
const builtin = @import("builtin");
const trace = @import("tracy").trace;
const testing = std.testing;
const table = @import("parse_table.zig").table;
const osc = @import("osc.zig");
@ -231,9 +230,6 @@ pub fn deinit(self: *Parser) void {
/// Up to 3 actions may need to be executed -- in order -- representing
/// the state exit, transition, and entry actions.
pub fn next(self: *Parser, c: u8) [3]?Action {
const tracy = trace(@src());
defer tracy.end();
// If we're processing UTF-8, we handle this manually.
if (self.state == .utf8) {
return .{ self.next_utf8(c), null, null };

View File

@ -58,7 +58,6 @@ const assert = std.debug.assert;
const Allocator = std.mem.Allocator;
const ziglyph = @import("ziglyph");
const trace = @import("tracy").trace;
const ansi = @import("ansi.zig");
const modes = @import("modes.zig");
const sgr = @import("sgr.zig");
@ -803,9 +802,6 @@ pub const RowIndexTag = enum {
/// so it is 1-indexed. If the value is zero, it means that this
/// section of the screen is empty or disabled.
pub inline fn maxLen(self: RowIndexTag, screen: *const Screen) usize {
const tracy = trace(@src());
defer tracy.end();
return switch (self) {
// Screen can be any of the written rows
.screen => screen.rowsWritten(),
@ -1177,9 +1173,6 @@ pub fn getCellPtr(self: *Screen, tag: RowIndexTag, y: usize, x: usize) *Cell {
/// from index zero of the given row index type. This can therefore iterate
/// from row 0 of the active area, history, viewport, etc.
pub fn rowIterator(self: *Screen, tag: RowIndexTag) RowIterator {
const tracy = trace(@src());
defer tracy.end();
return .{
.screen = self,
.tag = tag,
@ -1234,9 +1227,6 @@ pub fn getLine(self: *Screen, pt: point.ScreenPoint) ?Line {
/// Returns the row at the given index. This row is writable, although
/// only the active area should probably be written to.
pub fn getRow(self: *Screen, index: RowIndex) Row {
const tracy = trace(@src());
defer tracy.end();
// Get our offset into storage
const offset = index.toScreen(self).screen * (self.cols + 1);
@ -1288,9 +1278,6 @@ pub fn copyRow(self: *Screen, dst: RowIndex, src: RowIndex) !void {
///
/// This can be used to implement terminal scroll regions efficiently.
pub fn scrollRegionUp(self: *Screen, top: RowIndex, bottom: RowIndex, count_req: usize) void {
const tracy = trace(@src());
defer tracy.end();
// Avoid a lot of work if we're doing nothing.
if (count_req == 0) return;
@ -2091,9 +2078,6 @@ fn scrollRow(self: *Screen, idx: RowIndex) void {
}
fn scrollDelta(self: *Screen, delta: isize, viewport_only: bool) Allocator.Error!void {
const tracy = trace(@src());
defer tracy.end();
// Just in case, to avoid a bunch of stuff below.
if (delta == 0) return;
@ -2585,9 +2569,6 @@ fn selectionSlices(self: *Screen, sel_raw: Selection) SelectionSlices {
/// be truncated as they are shrunk. If they are grown, the new space is filled
/// with zeros.
pub fn resizeWithoutReflow(self: *Screen, rows: usize, cols: usize) !void {
const tracy = trace(@src());
defer tracy.end();
// If we're resizing to the same size, do nothing.
if (self.cols == cols and self.rows == rows) return;

View File

@ -18,7 +18,6 @@ const csi = @import("csi.zig");
const kitty = @import("kitty.zig");
const sgr = @import("sgr.zig");
const Tabstops = @import("Tabstops.zig");
const trace = @import("tracy").trace;
const color = @import("color.zig");
const Screen = @import("Screen.zig");
const mouse_shape = @import("mouse_shape.zig");
@ -213,9 +212,6 @@ pub fn alternateScreen(
alloc: Allocator,
options: AlternateScreenOptions,
) void {
const tracy = trace(@src());
defer tracy.end();
//log.info("alt screen active={} options={} cursor={}", .{ self.active_screen, options, self.screen.cursor });
// TODO: test
@ -255,9 +251,6 @@ pub fn primaryScreen(
alloc: Allocator,
options: AlternateScreenOptions,
) void {
const tracy = trace(@src());
defer tracy.end();
//log.info("primary screen active={} options={}", .{ self.active_screen, options });
// TODO: test
@ -296,9 +289,6 @@ pub const DeccolmMode = enum(u1) {
/// with the window. This will fix the grid at either 80 or 132 columns.
/// The rows will continue to be variable.
pub fn deccolm(self: *Terminal, alloc: Allocator, mode: DeccolmMode) !void {
const tracy = trace(@src());
defer tracy.end();
// If DEC mode 40 isn't enabled, then this is ignored. We also make
// sure that we don't have deccolm set because we want to fully ignore
// set mode.
@ -327,9 +317,6 @@ pub fn deccolm(self: *Terminal, alloc: Allocator, mode: DeccolmMode) !void {
/// Resize the underlying terminal.
pub fn resize(self: *Terminal, alloc: Allocator, cols: usize, rows: usize) !void {
const tracy = trace(@src());
defer tracy.end();
// If our cols/rows didn't change then we're done
if (self.cols == cols and self.rows == rows) return;
@ -469,9 +456,6 @@ pub fn restoreCursor(self: *Terminal) void {
/// TODO: test
pub fn setAttribute(self: *Terminal, attr: sgr.Attribute) !void {
const tracy = trace(@src());
defer tracy.end();
switch (attr) {
.unset => {
self.screen.cursor.pen.fg = .none;
@ -732,9 +716,6 @@ pub fn printString(self: *Terminal, str: []const u8) !void {
}
pub fn print(self: *Terminal, c: u21) !void {
const tracy = trace(@src());
defer tracy.end();
// log.debug("print={x} y={} x={}", .{ c, self.screen.cursor.y, self.screen.cursor.x });
// If we're not on the main display, do nothing for now
@ -971,9 +952,6 @@ pub fn print(self: *Terminal, c: u21) !void {
}
fn printCell(self: *Terminal, unmapped_c: u21) *Screen.Cell {
// const tracy = trace(@src());
// defer tracy.end();
const c: u21 = c: {
// TODO: non-utf8 handling, gr
@ -1034,9 +1012,6 @@ fn printCell(self: *Terminal, unmapped_c: u21) *Screen.Cell {
}
fn printWrap(self: *Terminal) !void {
const tracy = trace(@src());
defer tracy.end();
const row = self.screen.getRow(.{ .active = self.screen.cursor.y });
row.setWrapped(true);
@ -1068,9 +1043,6 @@ pub fn printRepeat(self: *Terminal, count_req: usize) !void {
///
/// Sets the cursor to the top left corner.
pub fn decaln(self: *Terminal) !void {
const tracy = trace(@src());
defer tracy.end();
// Reset margins, also sets cursor to top-left
self.scrolling_region = .{
.top = 0,
@ -1117,9 +1089,6 @@ pub fn decaln(self: *Terminal) !void {
///
/// This unsets the pending wrap state without wrapping.
pub fn index(self: *Terminal) !void {
const tracy = trace(@src());
defer tracy.end();
// Unset pending wrap state
self.screen.cursor.pending_wrap = false;
@ -1170,9 +1139,6 @@ pub fn index(self: *Terminal) !void {
/// * If the cursor is not on the top-most line of the scrolling region:
/// move the cursor one line up
pub fn reverseIndex(self: *Terminal) !void {
const tracy = trace(@src());
defer tracy.end();
if (self.screen.cursor.y != self.scrolling_region.top or
self.screen.cursor.x < self.scrolling_region.left or
self.screen.cursor.x > self.scrolling_region.right)
@ -1191,9 +1157,6 @@ pub fn reverseIndex(self: *Terminal) !void {
// greater than the bottom-most row it is adjusted to the bottom-most
// row.
pub fn setCursorPos(self: *Terminal, row_req: usize, col_req: usize) void {
const tracy = trace(@src());
defer tracy.end();
// If cursor origin mode is set the cursor row will be moved relative to
// the top margin row and adjusted to be above or at bottom-most row in
// the current scroll region.
@ -1233,9 +1196,6 @@ pub fn eraseDisplay(
mode: csi.EraseDisplay,
protected_req: bool,
) void {
const tracy = trace(@src());
defer tracy.end();
// Erasing clears all attributes / colors _except_ the background
const pen: Screen.Cell = switch (self.screen.cursor.pen.bg) {
.none => .{},
@ -1384,9 +1344,6 @@ pub fn eraseLine(
mode: csi.EraseLine,
protected_req: bool,
) void {
const tracy = trace(@src());
defer tracy.end();
// We always fill with the background
const pen: Screen.Cell = switch (self.screen.cursor.pen.bg) {
.none => .{},
@ -1463,9 +1420,6 @@ pub fn eraseLine(
///
/// Does not change the cursor position.
pub fn deleteChars(self: *Terminal, count: usize) !void {
const tracy = trace(@src());
defer tracy.end();
if (count == 0) return;
// If our cursor is outside the margins then do nothing. We DO reset
@ -1510,9 +1464,6 @@ pub fn deleteChars(self: *Terminal, count: usize) !void {
}
pub fn eraseChars(self: *Terminal, count_req: usize) void {
const tracy = trace(@src());
defer tracy.end();
const count = @max(count_req, 1);
// This resets the pending wrap state
@ -1556,9 +1507,6 @@ pub fn eraseChars(self: *Terminal, count_req: usize) void {
/// Move the cursor to the left amount cells. If amount is 0, adjust it to 1.
pub fn cursorLeft(self: *Terminal, count_req: usize) void {
const tracy = trace(@src());
defer tracy.end();
// Wrapping behavior depends on various terminal modes
const WrapMode = enum { none, reverse, reverse_extended };
const wrap_mode: WrapMode = wrap_mode: {
@ -1665,9 +1613,6 @@ pub fn cursorLeft(self: *Terminal, count_req: usize) void {
/// This sequence will not scroll the screen or scroll region. If amount is
/// 0, adjust it to 1.
pub fn cursorRight(self: *Terminal, count_req: usize) void {
const tracy = trace(@src());
defer tracy.end();
// Always resets pending wrap
self.screen.cursor.pending_wrap = false;
@ -1685,9 +1630,6 @@ pub fn cursorRight(self: *Terminal, count_req: usize) void {
/// move distance then it is internally adjusted to the maximum. This sequence
/// will not scroll the screen or scroll region. If amount is 0, adjust it to 1.
pub fn cursorDown(self: *Terminal, count_req: usize) void {
const tracy = trace(@src());
defer tracy.end();
// Always resets pending wrap
self.screen.cursor.pending_wrap = false;
@ -1705,9 +1647,6 @@ pub fn cursorDown(self: *Terminal, count_req: usize) void {
/// move distance then it is internally adjusted to the maximum. If amount is
/// 0, adjust it to 1.
pub fn cursorUp(self: *Terminal, count_req: usize) void {
const tracy = trace(@src());
defer tracy.end();
// Always resets pending wrap
self.screen.cursor.pending_wrap = false;
@ -1723,18 +1662,12 @@ pub fn cursorUp(self: *Terminal, count_req: usize) void {
/// Backspace moves the cursor back a column (but not less than 0).
pub fn backspace(self: *Terminal) void {
const tracy = trace(@src());
defer tracy.end();
self.cursorLeft(1);
}
/// Horizontal tab moves the cursor to the next tabstop, clearing
/// the screen to the left the tabstop.
pub fn horizontalTab(self: *Terminal) !void {
const tracy = trace(@src());
defer tracy.end();
while (self.screen.cursor.x < self.scrolling_region.right) {
// Move the cursor right
self.screen.cursor.x += 1;
@ -1748,9 +1681,6 @@ pub fn horizontalTab(self: *Terminal) !void {
// Same as horizontalTab but moves to the previous tabstop instead of the next.
pub fn horizontalTabBack(self: *Terminal) !void {
const tracy = trace(@src());
defer tracy.end();
// With origin mode enabled, our leftmost limit is the left margin.
const left_limit = if (self.modes.get(.origin)) self.scrolling_region.left else 0;
@ -1786,9 +1716,6 @@ pub fn tabReset(self: *Terminal) void {
/// Carriage return moves the cursor to the first column.
pub fn carriageReturn(self: *Terminal) void {
const tracy = trace(@src());
defer tracy.end();
// Always reset pending wrap state
self.screen.cursor.pending_wrap = false;
@ -1803,9 +1730,6 @@ pub fn carriageReturn(self: *Terminal) void {
/// Linefeed moves the cursor to the next line.
pub fn linefeed(self: *Terminal) !void {
const tracy = trace(@src());
defer tracy.end();
try self.index();
if (self.modes.get(.linefeed)) self.carriageReturn();
}
@ -1818,9 +1742,6 @@ pub fn linefeed(self: *Terminal) !void {
///
/// The inserted cells are colored according to the current SGR state.
pub fn insertBlanks(self: *Terminal, count: usize) void {
const tracy = trace(@src());
defer tracy.end();
// Unset pending wrap state without wrapping. Note: this purposely
// happens BEFORE the scroll region check below, because that's what
// xterm does.
@ -1901,9 +1822,6 @@ pub fn insertBlanks(self: *Terminal, count: usize) void {
///
/// Moves the cursor to the left margin.
pub fn insertLines(self: *Terminal, count: usize) !void {
const tracy = trace(@src());
defer tracy.end();
// Rare, but happens
if (count == 0) return;
@ -1965,9 +1883,6 @@ pub fn insertLines(self: *Terminal, count: usize) !void {
///
/// Moves the cursor to the left margin.
pub fn deleteLines(self: *Terminal, count: usize) !void {
const tracy = trace(@src());
defer tracy.end();
// If the cursor is outside the scroll region we do nothing.
if (self.screen.cursor.y < self.scrolling_region.top or
self.screen.cursor.y > self.scrolling_region.bottom or
@ -2024,9 +1939,6 @@ pub fn deleteLines(self: *Terminal, count: usize) !void {
/// Scroll the text down by one row.
pub fn scrollDown(self: *Terminal, count: usize) !void {
const tracy = trace(@src());
defer tracy.end();
// Preserve the cursor
const cursor = self.screen.cursor;
defer self.screen.cursor = cursor;
@ -2045,9 +1957,6 @@ pub fn scrollDown(self: *Terminal, count: usize) !void {
///
/// Does not change the (absolute) cursor position.
pub fn scrollUp(self: *Terminal, count: usize) !void {
const tracy = trace(@src());
defer tracy.end();
// Preserve the cursor
const cursor = self.screen.cursor;
defer self.screen.cursor = cursor;
@ -2072,9 +1981,6 @@ pub const ScrollViewport = union(enum) {
/// Scroll the viewport of the terminal grid.
pub fn scrollViewport(self: *Terminal, behavior: ScrollViewport) !void {
const tracy = trace(@src());
defer tracy.end();
try self.screen.scroll(switch (behavior) {
.top => .{ .top = {} },
.bottom => .{ .bottom = {} },
@ -2095,9 +2001,6 @@ pub fn scrollViewport(self: *Terminal, behavior: ScrollViewport) !void {
///
/// Top and bottom are 1-indexed.
pub fn setTopAndBottomMargin(self: *Terminal, top_req: usize, bottom_req: usize) void {
const tracy = trace(@src());
defer tracy.end();
const top = @max(1, top_req);
const bottom = @min(self.rows, if (bottom_req == 0) self.rows else bottom_req);
if (top >= bottom) return;
@ -2109,9 +2012,6 @@ pub fn setTopAndBottomMargin(self: *Terminal, top_req: usize, bottom_req: usize)
/// DECSLRM
pub fn setLeftAndRightMargin(self: *Terminal, left_req: usize, right_req: usize) void {
const tracy = trace(@src());
defer tracy.end();
// We must have this mode enabled to do anything
if (!self.modes.get(.enable_left_and_right_margin)) return;

View File

@ -8,7 +8,6 @@ const kitty = @import("kitty.zig");
const modes = @import("modes.zig");
const osc = @import("osc.zig");
const sgr = @import("sgr.zig");
const trace = @import("tracy").trace;
const MouseShape = @import("mouse_shape.zig").MouseShape;
const log = std.log.scoped(.stream);
@ -44,17 +43,11 @@ pub fn Stream(comptime Handler: type) type {
/// Process a string of characters.
pub fn nextSlice(self: *Self, c: []const u8) !void {
const tracy = trace(@src());
defer tracy.end();
for (c) |single| try self.next(single);
}
/// Process the next character and call any callbacks if necessary.
pub fn next(self: *Self, c: u8) !void {
const tracy = trace(@src());
tracy.value(@as(u64, @intCast(c)));
defer tracy.end();
// log.debug("char: {c}", .{c});
const actions = self.parser.next(c);
for (actions) |action_opt| {
@ -108,10 +101,6 @@ pub fn Stream(comptime Handler: type) type {
}
pub fn execute(self: *Self, c: u8) !void {
const tracy = trace(@src());
tracy.value(@as(u64, @intCast(c)));
defer tracy.end();
switch (@as(ansi.C0, @enumFromInt(c))) {
// We ignore SOH/STX: https://github.com/microsoft/terminal/issues/10786
.NUL, .SOH, .STX => {},

View File

@ -16,8 +16,6 @@ const terminal = @import("../terminal/main.zig");
const terminfo = @import("../terminfo/main.zig");
const xev = @import("xev");
const renderer = @import("../renderer.zig");
const tracy = @import("tracy");
const trace = tracy.trace;
const apprt = @import("../apprt.zig");
const fastmem = @import("../fastmem.zig");
const internal_os = @import("../os/main.zig");
@ -1514,9 +1512,6 @@ const ReadThread = struct {
ev: *EventData,
buf: []const u8,
) void {
const zone = trace(@src());
defer zone.end();
// log.info("DATA: {d}", .{n});
// log.info("DATA: {any}", .{buf[0..@intCast(usize, n)]});

View File

@ -7,8 +7,6 @@ const builtin = @import("builtin");
const xev = @import("xev");
const termio = @import("../termio.zig");
const BlockingQueue = @import("../blocking_queue.zig").BlockingQueue;
const tracy = @import("tracy");
const trace = tracy.trace;
const Allocator = std.mem.Allocator;
const log = std.log.scoped(.io_thread);
@ -142,7 +140,6 @@ pub fn threadMain(self: *Thread) void {
fn threadMain_(self: *Thread) !void {
defer log.debug("IO thread exited", .{});
tracy.setThreadName("pty io");
// Run our thread start/end callbacks. This allows the implementation
// to hook into the event loop as needed.
@ -162,9 +159,6 @@ fn threadMain_(self: *Thread) !void {
/// Drain the mailbox, handling all the messages in our terminal implementation.
fn drainMailbox(self: *Thread) !void {
const zone = trace(@src());
defer zone.end();
// This holds the mailbox lock for the duration of the drain. The
// expectation is that all our message handlers will be non-blocking
// ENOUGH to not mess up throughput on producers.
@ -290,9 +284,6 @@ fn wakeupCallback(
return .rearm;
};
const zone = trace(@src());
defer zone.end();
const t = self_.?;
// When we wake up, we check the mailbox. Mailbox producers should