mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-10-14 22:06:10 +00:00
lots of broken stuff
This commit is contained in:
122
src/main.zig
122
src/main.zig
@@ -16,58 +16,88 @@ const App = @import("App.zig");
|
||||
const cli_args = @import("cli_args.zig");
|
||||
const Config = @import("config.zig").Config;
|
||||
|
||||
pub fn main() !void {
|
||||
// Output some debug information right away
|
||||
std.log.info("dependency harfbuzz={s}", .{harfbuzz.versionString()});
|
||||
if (options.fontconfig) {
|
||||
std.log.info("dependency fontconfig={d}", .{fontconfig.version()});
|
||||
}
|
||||
std.log.info("renderer={}", .{renderer.Renderer});
|
||||
std.log.info("libxev backend={}", .{xev.backend});
|
||||
|
||||
// First things first, we fix our file descriptors
|
||||
internal_os.fixMaxFiles();
|
||||
|
||||
// We need to make sure the process locale is set properly. Locale
|
||||
// affects a lot of behaviors in a shell.
|
||||
internal_os.ensureLocale();
|
||||
|
||||
/// ProcessState represents the global process state. There should only
|
||||
/// be one of these at any given moment. This is extracted into a dedicated
|
||||
/// struct because it is reused by main and the static C lib.
|
||||
///
|
||||
/// ProcessState.init should be one of the first things ever called
|
||||
/// when using Ghostty. Ghostty calls this for you so this is more of a note
|
||||
/// for maintainers.
|
||||
pub const ProcessState = struct {
|
||||
const GPA = std.heap.GeneralPurposeAllocator(.{});
|
||||
var gpa: ?GPA = gpa: {
|
||||
// Use the libc allocator if it is available beacuse it is WAY
|
||||
// faster than GPA. We only do this in release modes so that we
|
||||
// can get easy memory leak detection in debug modes.
|
||||
if (builtin.link_libc) {
|
||||
if (switch (builtin.mode) {
|
||||
.ReleaseSafe, .ReleaseFast => true,
|
||||
|
||||
// We also use it if we can detect we're running under
|
||||
// Valgrind since Valgrind only instruments the C allocator
|
||||
else => std.valgrind.runningOnValgrind() > 0,
|
||||
}) break :gpa null;
|
||||
gpa: ?GPA,
|
||||
alloc: std.mem.Allocator,
|
||||
|
||||
pub fn init(self: *ProcessState) void {
|
||||
// Output some debug information right away
|
||||
std.log.info("dependency harfbuzz={s}", .{harfbuzz.versionString()});
|
||||
if (options.fontconfig) {
|
||||
std.log.info("dependency fontconfig={d}", .{fontconfig.version()});
|
||||
}
|
||||
std.log.info("renderer={}", .{renderer.Renderer});
|
||||
std.log.info("libxev backend={}", .{xev.backend});
|
||||
|
||||
break :gpa GPA{};
|
||||
};
|
||||
defer if (gpa) |*value| {
|
||||
// We want to ensure that we deinit the GPA because this is
|
||||
// the point at which it will output if there were safety violations.
|
||||
_ = value.deinit();
|
||||
};
|
||||
// First things first, we fix our file descriptors
|
||||
internal_os.fixMaxFiles();
|
||||
|
||||
const alloc = alloc: {
|
||||
const base = if (gpa) |*value|
|
||||
value.allocator()
|
||||
else if (builtin.link_libc)
|
||||
std.heap.c_allocator
|
||||
else
|
||||
unreachable;
|
||||
// We need to make sure the process locale is set properly. Locale
|
||||
// affects a lot of behaviors in a shell.
|
||||
internal_os.ensureLocale();
|
||||
|
||||
// If we're tracing, wrap the allocator
|
||||
if (!tracy.enabled) break :alloc base;
|
||||
var tracy_alloc = tracy.allocator(base, null);
|
||||
break :alloc tracy_alloc.allocator();
|
||||
};
|
||||
// Initialize ourself to nothing so we don't have any extra state.
|
||||
self.* = .{
|
||||
.gpa = null,
|
||||
.alloc = undefined,
|
||||
};
|
||||
errdefer self.deinit();
|
||||
|
||||
self.gpa = gpa: {
|
||||
// Use the libc allocator if it is available beacuse it is WAY
|
||||
// faster than GPA. We only do this in release modes so that we
|
||||
// can get easy memory leak detection in debug modes.
|
||||
if (builtin.link_libc) {
|
||||
if (switch (builtin.mode) {
|
||||
.ReleaseSafe, .ReleaseFast => true,
|
||||
|
||||
// We also use it if we can detect we're running under
|
||||
// Valgrind since Valgrind only instruments the C allocator
|
||||
else => std.valgrind.runningOnValgrind() > 0,
|
||||
}) break :gpa null;
|
||||
}
|
||||
|
||||
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;
|
||||
var tracy_alloc = tracy.allocator(base, null);
|
||||
break :alloc tracy_alloc.allocator();
|
||||
};
|
||||
}
|
||||
|
||||
pub fn deinit(self: *ProcessState) void {
|
||||
if (self.gpa) |*value| {
|
||||
// We want to ensure that we deinit the GPA because this is
|
||||
// the point at which it will output if there were safety violations.
|
||||
_ = value.deinit();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
pub fn main() !void {
|
||||
var state: ProcessState = undefined;
|
||||
ProcessState.init(&state);
|
||||
defer state.deinit();
|
||||
const alloc = state.alloc;
|
||||
|
||||
// Try reading our config
|
||||
var config = try Config.default(alloc);
|
||||
|
Reference in New Issue
Block a user