From be75109a1dcc2add39f9b868f67f620728986717 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 14 Feb 2023 20:58:33 -0800 Subject: [PATCH] new build system --- build.zig | 130 +++++++++++++++++++-------------- pkg/fontconfig/build.zig | 21 +++--- pkg/freetype/build.zig | 21 +++--- pkg/harfbuzz/build.zig | 26 ++++--- pkg/imgui/build.zig | 21 +++--- pkg/libpng/build.zig | 12 +-- pkg/macos/build.zig | 17 +++-- pkg/pixman/build.zig | 23 +++--- pkg/stb_image_resize/build.zig | 21 +++--- pkg/tracy/build.zig | 21 +++--- pkg/utf8proc/build.zig | 21 +++--- pkg/zlib/build.zig | 8 +- src/apprt/glfw.zig | 38 +++++----- src/main.zig | 6 +- src/renderer/OpenGL.zig | 11 ++- vendor/libxev | 2 +- vendor/mach | 2 +- vendor/zig-js | 2 +- vendor/zig-libxml2 | 2 +- vendor/zig-objc | 2 +- 20 files changed, 228 insertions(+), 179 deletions(-) diff --git a/build.zig b/build.zig index 05ef2e1a2..6687ddff5 100644 --- a/build.zig +++ b/build.zig @@ -44,7 +44,7 @@ var enable_coretext: bool = false; var enable_fontconfig: bool = false; pub fn build(b: *std.build.Builder) !void { - const mode = b.standardReleaseOptions(); + const optimize = b.standardOptimizeOption(.{}); const target = target: { var result = b.standardTargetOptions(.{}); @@ -60,7 +60,7 @@ pub fn build(b: *std.build.Builder) !void { bool, "tracy", "Enable Tracy integration (default true in Debug on Linux)", - ) orelse (mode == .Debug and target.isLinux()); + ) orelse (optimize == .Debug and target.isLinux()); enable_coretext = b.option( bool, @@ -96,9 +96,14 @@ pub fn build(b: *std.build.Builder) !void { b.enable_wasmtime = true; // Add our benchmarks - try benchSteps(b, target, mode); + try benchSteps(b, target, optimize); - const exe = b.addExecutable("ghostty", "src/main.zig"); + const exe = b.addExecutable(.{ + .name = "ghostty", + .root_source_file = .{ .path = "src/main.zig" }, + .target = target, + .optimize = optimize, + }); const exe_options = b.addOptions(); exe_options.addOption(bool, "tracy_enabled", tracy); exe_options.addOption(bool, "coretext", enable_coretext); @@ -111,8 +116,6 @@ pub fn build(b: *std.build.Builder) !void { exe.addCSourceFile("src/renderer/metal_workaround.c", &.{}); } - exe.setTarget(target); - exe.setBuildMode(mode); exe.addOptions("build_options", exe_options); exe.install(); @@ -157,13 +160,12 @@ pub fn build(b: *std.build.Builder) !void { const wasm_specific_target: WasmTarget = .browser; exe_options.addOption(WasmTarget, "wasm_target", wasm_specific_target); - const wasm = b.addSharedLibrary( - "ghostty-wasm", - "src/main_wasm.zig", - .{ .unversioned = {} }, - ); - wasm.setTarget(wasm_target); - wasm.setBuildMode(mode); + const wasm = b.addSharedLibrary(.{ + .name = "ghostty-wasm", + .root_source_file = .{ .path = "src/main_wasm.zig" }, + .target = wasm_target, + .optimize = optimize, + }); wasm.setOutputDir("zig-out"); wasm.addOptions("build_options", exe_options); @@ -186,8 +188,11 @@ pub fn build(b: *std.build.Builder) !void { // isn't an exact match to our freestanding target above but // it lets us test some basic functionality. const test_step = b.step("test-wasm", "Run all tests for wasm"); - const main_test = b.addTest("src/main_wasm.zig"); - main_test.setTarget(wasm_target); + const main_test = b.addTest(.{ + .name = "wasm-test", + .root_source_file = .{ .path = "src/main_wasm.zig" }, + .target = wasm_target, + }); main_test.addOptions("build_options", exe_options); try addDeps(b, main_test, true); test_step.dependOn(&main_test.step); @@ -198,7 +203,7 @@ pub fn build(b: *std.build.Builder) !void { // Build our run step, which runs the main app by default, but will // run a conformance app if `-Dconformance` is set. const run_exe = if (conformance) |name| blk: { - var conformance_exes = try conformanceSteps(b, target, mode); + var conformance_exes = try conformanceSteps(b, target, optimize); defer conformance_exes.deinit(); break :blk conformance_exes.get(name) orelse return error.InvalidConformance; } else exe; @@ -217,12 +222,16 @@ pub fn build(b: *std.build.Builder) !void { const test_step = b.step("test", "Run all tests"); var test_filter = b.option([]const u8, "test-filter", "Filter for test"); - const main_test = b.addTestExe("ghostty-test", "src/main.zig"); + const main_test = b.addTest(.{ + .name = "ghostty-test", + .kind = .test_exe, + .root_source_file = .{ .path = "src/main.zig" }, + .target = target, + }); { if (emit_test_exe) main_test.install(); const main_test_run = main_test.run(); main_test.setFilter(test_filter); - main_test.setTarget(target); try addDeps(b, main_test, true); main_test.addOptions("build_options", exe_options); @@ -236,26 +245,29 @@ pub fn build(b: *std.build.Builder) !void { // Named package dependencies don't have their tests run by reference, // so we iterate through them here. We're only interested in dependencies // we wrote (are in the "pkg/" directory). - for (main_test.packages.items) |pkg_| { - const pkg: std.build.Pkg = pkg_; - if (std.mem.eql(u8, pkg.name, "build_options")) continue; - if (std.mem.eql(u8, pkg.name, "glfw")) continue; + var it = main_test.modules.iterator(); + while (it.next()) |entry| { + const name = entry.key_ptr.*; + const module = entry.value_ptr.*; + if (std.mem.eql(u8, name, "build_options")) continue; + if (std.mem.eql(u8, name, "glfw")) continue; var buf: [256]u8 = undefined; - var test_ = b.addTestExeSource( - try std.fmt.bufPrint(&buf, "{s}-test", .{pkg.name}), - pkg.source, - ); + var test_ = b.addTest(.{ + .name = try std.fmt.bufPrint(&buf, "{s}-test", .{name}), + .kind = .test_exe, + .root_source_file = module.source_file, + .target = target, + }); const test_run = test_.run(); - test_.setTarget(target); try addDeps(b, test_, true); - if (pkg.dependencies) |children| { - test_.packages = std.ArrayList(std.build.Pkg).init(b.allocator); - try test_.packages.appendSlice(children); - } + // if (pkg.dependencies) |children| { + // test_.packages = std.ArrayList(std.build.Pkg).init(b.allocator); + // try test_.packages.appendSlice(children); + // } - var before = b.addLog("\x1b[" ++ color_map.get("cyan").? ++ "\x1b[" ++ color_map.get("b").? ++ "[{s} tests]" ++ "\x1b[" ++ color_map.get("d").? ++ " ----" ++ "\x1b[0m", .{pkg.name}); + var before = b.addLog("\x1b[" ++ color_map.get("cyan").? ++ "\x1b[" ++ color_map.get("b").? ++ "[{s} tests]" ++ "\x1b[" ++ color_map.get("d").? ++ " ----" ++ "\x1b[0m", .{name}); var after = b.addLog("\x1b[" ++ color_map.get("d").? ++ "–––---\n\n" ++ "\x1b[0m", .{}); test_step.dependOn(&before.step); test_step.dependOn(&test_run.step); @@ -276,9 +288,9 @@ fn addDeps( if (step.target.getCpuArch() == .wasm32) { // We link this package but its a no-op since Tracy // never actualy WORKS with wasm. - step.addPackage(tracylib.pkg); - step.addPackage(utf8proc.pkg); - step.addPackage(js.pkg); + step.addModule("tracy", tracylib.module(b)); + step.addModule("utf8proc", utf8proc.module(b)); + // TODO: step.addPackage(js.pkg); // utf8proc _ = try utf8proc.link(b, step); @@ -287,20 +299,20 @@ fn addDeps( } // We always need the Zig packages - if (enable_fontconfig) step.addPackage(fontconfig.pkg); - step.addPackage(freetype.pkg); - step.addPackage(harfbuzz.pkg); - step.addPackage(imgui.pkg); - step.addPackage(glfw.pkg); - step.addPackage(libxev.pkg); - step.addPackage(pixman.pkg); - step.addPackage(stb_image_resize.pkg); - step.addPackage(utf8proc.pkg); + if (enable_fontconfig) step.addModule("fontconfig", fontconfig.module(b)); + step.addModule("freetype", freetype.module(b)); + step.addModule("harfbuzz", harfbuzz.module(b)); + step.addModule("imgui", imgui.module(b)); + step.addModule("glfw", glfw.module(b)); + step.addModule("xev", libxev.module(b)); + step.addModule("pixman", pixman.module(b)); + step.addModule("stb_image_resize", stb_image_resize.module(b)); + step.addModule("utf8proc", utf8proc.module(b)); // Mac Stuff if (step.target.isDarwin()) { - step.addPackage(objc.pkg); - step.addPackage(macos.pkg); + step.addModule("objc", objc.module(b)); + step.addModule("macos", macos.module(b)); _ = try macos.link(b, step, .{}); } @@ -309,7 +321,7 @@ fn addDeps( step.addCSourceFile("vendor/glad/src/gl.c", &.{}); // Tracy - step.addPackage(tracylib.pkg); + step.addModule("tracy", tracylib.module(b)); if (tracy) { var tracy_step = try tracylib.link(b, step); system_sdk.include(b, tracy_step, .{}); @@ -400,7 +412,7 @@ fn addDeps( const libxml2_lib = try libxml2.create( b, step.target, - step.build_mode, + step.optimize, .{ .lzma = false, .zlib = false }, ); libxml2_lib.link(step); @@ -431,7 +443,7 @@ fn addDeps( fn benchSteps( b: *std.build.Builder, target: std.zig.CrossTarget, - mode: std.builtin.Mode, + optimize: std.builtin.Mode, ) !void { // Open the directory ./src/bench const c_dir_path = (comptime root()) ++ "/src/bench"; @@ -457,9 +469,12 @@ fn benchSteps( // Executable builder. const bin_name = try std.fmt.allocPrint(b.allocator, "bench-{s}", .{name}); - const c_exe = b.addExecutable(bin_name, path); - c_exe.setTarget(target); - c_exe.setBuildMode(mode); + const c_exe = b.addExecutable(.{ + .name = bin_name, + .root_source_file = .{ .path = path }, + .target = target, + .optimize = optimize, + }); c_exe.setMainPkgPath("./src"); c_exe.install(); try addDeps(b, c_exe, true); @@ -469,7 +484,7 @@ fn benchSteps( fn conformanceSteps( b: *std.build.Builder, target: std.zig.CrossTarget, - mode: std.builtin.Mode, + optimize: std.builtin.Mode, ) !std.StringHashMap(*LibExeObjStep) { var map = std.StringHashMap(*LibExeObjStep).init(b.allocator); @@ -493,9 +508,12 @@ fn conformanceSteps( }); // Executable builder. - const c_exe = b.addExecutable(name, path); - c_exe.setTarget(target); - c_exe.setBuildMode(mode); + const c_exe = b.addExecutable(.{ + .name = name, + .root_source_file = .{ .path = path }, + .target = target, + .optimize = optimize, + }); c_exe.setOutputDir("zig-out/bin/conformance"); c_exe.install(); diff --git a/pkg/fontconfig/build.zig b/pkg/fontconfig/build.zig index 8778584fe..3bd47193b 100644 --- a/pkg/fontconfig/build.zig +++ b/pkg/fontconfig/build.zig @@ -8,10 +8,11 @@ const include_path_self = thisDir(); pub const include_paths = .{ include_path, include_path_self }; -pub const pkg = std.build.Pkg{ - .name = "fontconfig", - .source = .{ .path = thisDir() ++ "/main.zig" }, -}; +pub fn module(b: *std.Build) *std.build.Module { + return b.createModule(.{ + .source_file = .{ .path = (comptime thisDir()) ++ "/main.zig" }, + }); +} fn thisDir() []const u8 { return std.fs.path.dirname(@src().file) orelse "."; @@ -36,7 +37,7 @@ pub const Options = struct { }; pub fn link( - b: *std.build.Builder, + b: *std.Build, step: *std.build.LibExeObjStep, opt: Options, ) !*std.build.LibExeObjStep { @@ -48,14 +49,16 @@ pub fn link( } pub fn buildFontconfig( - b: *std.build.Builder, + b: *std.Build, step: *std.build.LibExeObjStep, opt: Options, ) !*std.build.LibExeObjStep { const target = step.target; - const lib = b.addStaticLibrary("fontconfig", null); - lib.setTarget(step.target); - lib.setBuildMode(step.build_mode); + const lib = b.addStaticLibrary(.{ + .name = "fontconfig", + .target = step.target, + .optimize = step.optimize, + }); // Include lib.addIncludePath(include_path); diff --git a/pkg/freetype/build.zig b/pkg/freetype/build.zig index 04840624e..6bc5a25bb 100644 --- a/pkg/freetype/build.zig +++ b/pkg/freetype/build.zig @@ -7,10 +7,11 @@ pub const include_path_self = thisDir(); pub const include_paths = .{ include_path, include_path_self }; -pub const pkg = std.build.Pkg{ - .name = "freetype", - .source = .{ .path = thisDir() ++ "/main.zig" }, -}; +pub fn module(b: *std.Build) *std.build.Module { + return b.createModule(.{ + .source_file = .{ .path = (comptime thisDir()) ++ "/main.zig" }, + }); +} fn thisDir() []const u8 { return std.fs.path.dirname(@src().file) orelse "."; @@ -34,7 +35,7 @@ pub const Options = struct { }; pub fn link( - b: *std.build.Builder, + b: *std.Build, step: *std.build.LibExeObjStep, opt: Options, ) !*std.build.LibExeObjStep { @@ -46,14 +47,16 @@ pub fn link( } pub fn buildFreetype( - b: *std.build.Builder, + b: *std.Build, step: *std.build.LibExeObjStep, opt: Options, ) !*std.build.LibExeObjStep { const target = step.target; - const lib = b.addStaticLibrary("freetype", null); - lib.setTarget(step.target); - lib.setBuildMode(step.build_mode); + const lib = b.addStaticLibrary(.{ + .name = "freetype", + .target = target, + .optimize = step.optimize, + }); // Include lib.addIncludePath(include_path); diff --git a/pkg/harfbuzz/build.zig b/pkg/harfbuzz/build.zig index 0ca97c598..9c0d26129 100644 --- a/pkg/harfbuzz/build.zig +++ b/pkg/harfbuzz/build.zig @@ -8,11 +8,15 @@ const include_path = root ++ "src/"; pub const include_paths = .{include_path}; -pub const pkg = std.build.Pkg{ - .name = "harfbuzz", - .source = .{ .path = thisDir() ++ "/main.zig" }, - .dependencies = &.{ freetypepkg.pkg, macospkg.pkg }, -}; +pub fn module(b: *std.Build) *std.build.Module { + return b.createModule(.{ + .source_file = .{ .path = (comptime thisDir()) ++ "/main.zig" }, + .dependencies = &.{ + .{ .name = "freetype", .module = freetypepkg.module(b) }, + .{ .name = "macos", .module = macospkg.module(b) }, + }, + }); +} fn thisDir() []const u8 { return std.fs.path.dirname(@src().file) orelse "."; @@ -34,7 +38,7 @@ pub const Options = struct { }; pub fn link( - b: *std.build.Builder, + b: *std.Build, step: *std.build.LibExeObjStep, opt: Options, ) !*std.build.LibExeObjStep { @@ -45,13 +49,15 @@ pub fn link( } pub fn buildHarfbuzz( - b: *std.build.Builder, + b: *std.Build, step: *std.build.LibExeObjStep, opt: Options, ) !*std.build.LibExeObjStep { - const lib = b.addStaticLibrary("harfbuzz", null); - lib.setTarget(step.target); - lib.setBuildMode(step.build_mode); + const lib = b.addStaticLibrary(.{ + .name = "harfbuzz", + .target = step.target, + .optimize = step.optimize, + }); // Include lib.addIncludePath(include_path); diff --git a/pkg/imgui/build.zig b/pkg/imgui/build.zig index c67fd70d5..1ca817104 100644 --- a/pkg/imgui/build.zig +++ b/pkg/imgui/build.zig @@ -8,10 +8,11 @@ pub const include_paths = [_][]const u8{ root ++ "imgui/backends", }; -pub const pkg = std.build.Pkg{ - .name = "imgui", - .source = .{ .path = thisDir() ++ "/main.zig" }, -}; +pub fn module(b: *std.Build) *std.build.Module { + return b.createModule(.{ + .source_file = .{ .path = (comptime thisDir()) ++ "/main.zig" }, + }); +} fn thisDir() []const u8 { return std.fs.path.dirname(@src().file) orelse "."; @@ -30,7 +31,7 @@ pub const Options = struct { }; pub fn link( - b: *std.build.Builder, + b: *std.Build, step: *std.build.LibExeObjStep, opt: Options, ) !*std.build.LibExeObjStep { @@ -41,14 +42,16 @@ pub fn link( } pub fn buildImgui( - b: *std.build.Builder, + b: *std.Build, step: *std.build.LibExeObjStep, opt: Options, ) !*std.build.LibExeObjStep { const target = step.target; - const lib = b.addStaticLibrary("imgui", null); - lib.setTarget(step.target); - lib.setBuildMode(step.build_mode); + const lib = b.addStaticLibrary(.{ + .name = "imgui", + .target = step.target, + .optimize = step.optimize, + }); // Include inline for (include_paths) |path| lib.addIncludePath(path); diff --git a/pkg/libpng/build.zig b/pkg/libpng/build.zig index c2478c0b2..a097e9240 100644 --- a/pkg/libpng/build.zig +++ b/pkg/libpng/build.zig @@ -26,7 +26,7 @@ pub const Options = struct { }; pub fn link( - b: *std.build.Builder, + b: *std.Build, step: *std.build.LibExeObjStep, opt: Options, ) !*std.build.LibExeObjStep { @@ -37,14 +37,16 @@ pub fn link( } pub fn buildLib( - b: *std.build.Builder, + b: *std.Build, step: *std.build.LibExeObjStep, opt: Options, ) !*std.build.LibExeObjStep { const target = step.target; - const lib = b.addStaticLibrary("png", null); - lib.setTarget(step.target); - lib.setBuildMode(step.build_mode); + const lib = b.addStaticLibrary(.{ + .name = "png", + .target = step.target, + .optimize = step.optimize, + }); // Include lib.addIncludePath(include_path); diff --git a/pkg/macos/build.zig b/pkg/macos/build.zig index 670a7ccb9..a75087cdd 100644 --- a/pkg/macos/build.zig +++ b/pkg/macos/build.zig @@ -1,10 +1,11 @@ const std = @import("std"); const builtin = @import("builtin"); -pub const pkg = std.build.Pkg{ - .name = "macos", - .source = .{ .path = thisDir() ++ "/main.zig" }, -}; +pub fn module(b: *std.Build) *std.build.Module { + return b.createModule(.{ + .source_file = .{ .path = (comptime thisDir()) ++ "/main.zig" }, + }); +} fn thisDir() []const u8 { return std.fs.path.dirname(@src().file) orelse "."; @@ -13,7 +14,7 @@ fn thisDir() []const u8 { pub const Options = struct {}; pub fn link( - b: *std.build.Builder, + b: *std.Build, step: *std.build.LibExeObjStep, opt: Options, ) !*std.build.LibExeObjStep { @@ -21,7 +22,11 @@ pub fn link( var flags = std.ArrayList([]const u8).init(b.allocator); defer flags.deinit(); - const lib = b.addStaticLibrary("macos", null); + const lib = b.addStaticLibrary(.{ + .name = "macos", + .target = step.target, + .optimize = step.optimize, + }); step.addCSourceFile(comptime thisDir() ++ "/os/log.c", flags.items); step.addCSourceFile(comptime thisDir() ++ "/text/ext.c", flags.items); step.linkFramework("CoreFoundation"); diff --git a/pkg/pixman/build.zig b/pkg/pixman/build.zig index 6f5d35648..16df1f85d 100644 --- a/pkg/pixman/build.zig +++ b/pkg/pixman/build.zig @@ -8,10 +8,11 @@ const include_path_self = thisDir(); pub const include_paths = .{ include_path, include_path_self }; -pub const pkg = std.build.Pkg{ - .name = "pixman", - .source = .{ .path = thisDir() ++ "/main.zig" }, -}; +pub fn module(b: *std.Build) *std.build.Module { + return b.createModule(.{ + .source_file = .{ .path = (comptime thisDir()) ++ "/main.zig" }, + }); +} fn thisDir() []const u8 { return std.fs.path.dirname(@src().file) orelse "."; @@ -19,7 +20,7 @@ fn thisDir() []const u8 { pub const Options = struct {}; -pub fn build(b: *std.build.Builder) !void { +pub fn build(b: *std.Build) !void { const target = b.standardTargetOptions(.{}); const mode = b.standardReleaseOptions(); @@ -35,7 +36,7 @@ pub fn build(b: *std.build.Builder) !void { } pub fn link( - b: *std.build.Builder, + b: *std.Build, step: *std.build.LibExeObjStep, opt: Options, ) !*std.build.LibExeObjStep { @@ -47,16 +48,18 @@ pub fn link( } pub fn buildPixman( - b: *std.build.Builder, + b: *std.Build, step: *std.build.LibExeObjStep, opt: Options, ) !*std.build.LibExeObjStep { _ = opt; const target = step.target; - const lib = b.addStaticLibrary("pixman", null); - lib.setTarget(step.target); - lib.setBuildMode(step.build_mode); + const lib = b.addStaticLibrary(.{ + .name = "pixman", + .target = step.target, + .optimize = step.optimize, + }); // Include lib.addIncludePath(include_path); diff --git a/pkg/stb_image_resize/build.zig b/pkg/stb_image_resize/build.zig index f7259b401..6a0deb2a8 100644 --- a/pkg/stb_image_resize/build.zig +++ b/pkg/stb_image_resize/build.zig @@ -6,10 +6,11 @@ pub const include_paths = [_][]const u8{ root, }; -pub const pkg = std.build.Pkg{ - .name = "stb_image_resize", - .source = .{ .path = thisDir() ++ "/main.zig" }, -}; +pub fn module(b: *std.Build) *std.build.Module { + return b.createModule(.{ + .source_file = .{ .path = (comptime thisDir()) ++ "/main.zig" }, + }); +} fn thisDir() []const u8 { return std.fs.path.dirname(@src().file) orelse "."; @@ -18,7 +19,7 @@ fn thisDir() []const u8 { pub const Options = struct {}; pub fn link( - b: *std.build.Builder, + b: *std.Build, step: *std.build.LibExeObjStep, opt: Options, ) !*std.build.LibExeObjStep { @@ -29,15 +30,17 @@ pub fn link( } pub fn buildStbImageResize( - b: *std.build.Builder, + b: *std.Build, step: *std.build.LibExeObjStep, opt: Options, ) !*std.build.LibExeObjStep { _ = opt; - const lib = b.addStaticLibrary("stb_image_resize", null); - lib.setTarget(step.target); - lib.setBuildMode(step.build_mode); + const lib = b.addStaticLibrary(.{ + .name = "stb_image_resize", + .target = step.target, + .optimize = step.optimize, + }); // Include inline for (include_paths) |path| lib.addIncludePath(path); diff --git a/pkg/tracy/build.zig b/pkg/tracy/build.zig index 9bdb0978e..debef1df6 100644 --- a/pkg/tracy/build.zig +++ b/pkg/tracy/build.zig @@ -3,16 +3,17 @@ const std = @import("std"); /// Directories with our includes. const root = thisDir() ++ "../../../vendor/tracy/"; -pub const pkg = std.build.Pkg{ - .name = "tracy", - .source = .{ .path = thisDir() ++ "/tracy.zig" }, -}; +pub fn module(b: *std.Build) *std.build.Module { + return b.createModule(.{ + .source_file = .{ .path = (comptime thisDir()) ++ "/tracy.zig" }, + }); +} fn thisDir() []const u8 { return std.fs.path.dirname(@src().file) orelse "."; } -pub fn link(b: *std.build.Builder, step: *std.build.LibExeObjStep) !*std.build.LibExeObjStep { +pub fn link(b: *std.Build, step: *std.build.LibExeObjStep) !*std.build.LibExeObjStep { const tracy = try buildTracy(b, step); step.linkLibrary(tracy); step.addIncludePath(root); @@ -20,13 +21,15 @@ pub fn link(b: *std.build.Builder, step: *std.build.LibExeObjStep) !*std.build.L } pub fn buildTracy( - b: *std.build.Builder, + b: *std.Build, step: *std.build.LibExeObjStep, ) !*std.build.LibExeObjStep { const target = step.target; - const lib = b.addStaticLibrary("tracy", null); - lib.setTarget(step.target); - lib.setBuildMode(step.build_mode); + const lib = b.addStaticLibrary(.{ + .name = "tracy", + .target = step.target, + .optimize = step.optimize, + }); var flags = std.ArrayList([]const u8).init(b.allocator); defer flags.deinit(); diff --git a/pkg/utf8proc/build.zig b/pkg/utf8proc/build.zig index 6fe9dc3ac..23bfa8346 100644 --- a/pkg/utf8proc/build.zig +++ b/pkg/utf8proc/build.zig @@ -6,16 +6,17 @@ const include_path = root; pub const include_paths = .{include_path}; -pub const pkg = std.build.Pkg{ - .name = "utf8proc", - .source = .{ .path = thisDir() ++ "/main.zig" }, -}; +pub fn module(b: *std.Build) *std.build.Module { + return b.createModule(.{ + .source_file = .{ .path = (comptime thisDir()) ++ "/main.zig" }, + }); +} fn thisDir() []const u8 { return std.fs.path.dirname(@src().file) orelse "."; } -pub fn link(b: *std.build.Builder, step: *std.build.LibExeObjStep) !*std.build.LibExeObjStep { +pub fn link(b: *std.Build, step: *std.build.LibExeObjStep) !*std.build.LibExeObjStep { const lib = try buildLib(b, step); step.linkLibrary(lib); step.addIncludePath(include_path); @@ -23,12 +24,14 @@ pub fn link(b: *std.build.Builder, step: *std.build.LibExeObjStep) !*std.build.L } pub fn buildLib( - b: *std.build.Builder, + b: *std.Build, step: *std.build.LibExeObjStep, ) !*std.build.LibExeObjStep { - const lib = b.addStaticLibrary("utf8proc", null); - lib.setTarget(step.target); - lib.setBuildMode(step.build_mode); + const lib = b.addStaticLibrary(.{ + .name = "utf8proc", + .target = step.target, + .optimize = step.optimize, + }); // Include lib.addIncludePath(include_path); diff --git a/pkg/zlib/build.zig b/pkg/zlib/build.zig index 6ca3c9a25..7628479cc 100644 --- a/pkg/zlib/build.zig +++ b/pkg/zlib/build.zig @@ -26,9 +26,11 @@ pub fn buildLib( b: *std.build.Builder, step: *std.build.LibExeObjStep, ) !*std.build.LibExeObjStep { - const lib = b.addStaticLibrary("z", null); - lib.setTarget(step.target); - lib.setBuildMode(step.build_mode); + const lib = b.addStaticLibrary(.{ + .name = "z", + .target = step.target, + .optimize = step.optimize, + }); // Include lib.addIncludePath(include_path); diff --git a/src/apprt/glfw.zig b/src/apprt/glfw.zig index 9aded5d21..0cb5fab8e 100644 --- a/src/apprt/glfw.zig +++ b/src/apprt/glfw.zig @@ -27,7 +27,7 @@ const log = std.log.scoped(.glfw); pub const App = struct { pub fn init() !App { - try glfw.init(.{}); + if (!glfw.init(.{})) return error.GlfwInitFailed; return .{}; } @@ -39,13 +39,13 @@ pub const App = struct { /// Wakeup the event loop. This should be able to be called from any thread. pub fn wakeup(self: App) !void { _ = self; - try glfw.postEmptyEvent(); + glfw.postEmptyEvent(); } /// Wait for events in the event loop to process. pub fn wait(self: App) !void { _ = self; - try glfw.waitEvents(); + glfw.waitEvents(); } }; @@ -58,14 +58,14 @@ pub const Window = struct { pub fn init(app: *const CoreApp, core_win: *CoreWindow) !Window { // Create our window - const win = try glfw.Window.create( + const win = glfw.Window.create( 640, 480, "ghostty", null, null, Renderer.glfwWindowHints(), - ); + ) orelse return glfw.mustGetErrorCode(); errdefer win.destroy(); if (builtin.mode == .Debug) { @@ -76,7 +76,7 @@ pub const Window = struct { break :monitor glfw.Monitor.getPrimary().?; }; const physical_size = monitor.getPhysicalSize(); - const video_mode = try monitor.getVideoMode(); + const video_mode = monitor.getVideoMode() orelse return glfw.mustGetErrorCode(); const physical_x_dpi = @intToFloat(f32, video_mode.getWidth()) / (@intToFloat(f32, physical_size.width_mm) / 25.4); const physical_y_dpi = @intToFloat(f32, video_mode.getHeight()) / (@intToFloat(f32, physical_size.height_mm) / 25.4); log.debug("physical dpi x={} y={}", .{ @@ -99,13 +99,13 @@ pub const Window = struct { } // Create the cursor - const cursor = try glfw.Cursor.createStandard(.ibeam); + const cursor = glfw.Cursor.createStandard(.ibeam) orelse return glfw.mustGetErrorCode(); errdefer cursor.destroy(); if ((comptime !builtin.target.isDarwin()) or internal_os.macosVersionAtLeast(13, 0, 0)) { // We only set our cursor if we're NOT on Mac, or if we are then the // macOS version is >= 13 (Ventura). On prior versions, glfw crashes // since we use a tab group. - try win.setCursor(cursor); + win.setCursor(cursor); } // Set our callbacks @@ -178,7 +178,7 @@ pub const Window = struct { /// to use this more. i.e. you can't set max width but no max height, /// or no mins. pub fn setSizeLimits(self: *Window, min: apprt.WindowSize, max_: ?apprt.WindowSize) !void { - try self.window.setSizeLimits(.{ + self.window.setSizeLimits(.{ .width = min.width, .height = min.height, }, if (max_) |max| .{ @@ -192,7 +192,7 @@ pub const Window = struct { /// Returns the content scale for the created window. pub fn getContentScale(self: *const Window) !apprt.ContentScale { - const scale = try self.window.getContentScale(); + const scale = self.window.getContentScale(); return apprt.ContentScale{ .x = scale.x_scale, .y = scale.y_scale }; } @@ -200,18 +200,14 @@ pub const Window = struct { /// not match screen coordinate size but we should be able to convert /// back and forth using getContentScale. pub fn getSize(self: *const Window) !apprt.WindowSize { - const size = self.window.getFramebufferSize() catch |err| err: { - log.err("error querying window size in pixels, will use screen size err={}", .{err}); - break :err try self.window.getSize(); - }; - + const size = self.window.getFramebufferSize(); return apprt.WindowSize{ .width = size.width, .height = size.height }; } /// Returns the cursor position in scaled pixels relative to the /// upper-left of the window. pub fn getCursorPos(self: *const Window) !apprt.CursorPos { - const unscaled_pos = try self.window.getCursorPos(); + const unscaled_pos = self.window.getCursorPos(); const pos = try self.cursorPosToPixels(unscaled_pos); return apprt.CursorPos{ .x = @floatCast(f32, pos.xpos), @@ -232,7 +228,7 @@ pub const Window = struct { /// Set the title of the window. pub fn setTitle(self: *Window, slice: [:0]const u8) !void { - try self.window.setTitle(slice.ptr); + self.window.setTitle(slice.ptr); } /// Read the clipboard. The windowing system is responsible for allocating @@ -240,13 +236,13 @@ pub const Window = struct { /// time getClipboardString is called. pub fn getClipboardString(self: *const Window) ![:0]const u8 { _ = self; - return try glfw.getClipboardString(); + return glfw.getClipboardString() orelse return glfw.mustGetErrorCode(); } /// Set the clipboard. pub fn setClipboardString(self: *const Window, val: [:0]const u8) !void { _ = self; - try glfw.setClipboardString(val); + glfw.setClipboardString(val); } /// The cursor position from glfw directly is in screen coordinates but @@ -255,8 +251,8 @@ pub const Window = struct { // The cursor position is in screen coordinates but we // want it in pixels. we need to get both the size of the // window in both to get the ratio to make the conversion. - const size = try self.window.getSize(); - const fb_size = try self.window.getFramebufferSize(); + const size = self.window.getSize(); + const fb_size = self.window.getFramebufferSize(); // If our framebuffer and screen are the same, then there is no scaling // happening and we can short-circuit by returning the pos as-is. diff --git a/src/main.zig b/src/main.zig index 0fd4b1a7b..61dc5e2ba 100644 --- a/src/main.zig +++ b/src/main.zig @@ -192,17 +192,17 @@ pub const std_options = struct { } }; -fn glfwErrorCallback(code: glfw.Error, desc: [:0]const u8) void { +fn glfwErrorCallback(code: glfw.ErrorCode, desc: [:0]const u8) void { std.log.warn("glfw error={} message={s}", .{ code, desc }); // Workaround for: https://github.com/ocornut/imgui/issues/5908 // If we get an invalid value with "scancode" in the message we assume // it is from the glfw key callback that imgui sets and we clear the // error so that our future code doesn't crash. - if (code == glfw.Error.InvalidValue and + if (code == glfw.ErrorCode.InvalidValue and std.mem.indexOf(u8, desc, "scancode") != null) { - glfw.errors.getError() catch {}; + _ = glfw.getError(); } } diff --git a/src/renderer/OpenGL.zig b/src/renderer/OpenGL.zig index 7e0f40842..6be6fc90c 100644 --- a/src/renderer/OpenGL.zig +++ b/src/renderer/OpenGL.zig @@ -423,10 +423,9 @@ pub fn threadEnter(self: *const OpenGL, win: apprt.runtime.Window) !void { // ensures that the context switches over to our thread. Important: // the prior thread MUST have detached the context prior to calling // this entrypoint. - try glfw.makeContextCurrent(win.window); - errdefer glfw.makeContextCurrent(null) catch |err| - log.warn("failed to cleanup OpenGL context err={}", .{err}); - try glfw.swapInterval(1); + glfw.makeContextCurrent(win.window); + errdefer glfw.makeContextCurrent(null); + glfw.swapInterval(1); // Load OpenGL bindings. This API is context-aware so this sets // a threadlocal context for these pointers. @@ -443,7 +442,7 @@ pub fn threadExit(self: *const OpenGL) void { _ = self; gl.glad.unload(); - glfw.makeContextCurrent(null) catch {}; + glfw.makeContextCurrent(null); } /// Callback when the focus changes for the terminal this is rendering. @@ -641,7 +640,7 @@ pub fn render( } // Swap our window buffers - try win.window.swapBuffers(); + win.window.swapBuffers(); } /// rebuildCells rebuilds all the GPU cells from our CPU state. This is a diff --git a/vendor/libxev b/vendor/libxev index f578d81eb..62f25af92 160000 --- a/vendor/libxev +++ b/vendor/libxev @@ -1 +1 @@ -Subproject commit f578d81ebe60d3afe6593771f10cf650e4d891cb +Subproject commit 62f25af92c666a0b0771b9d35719b88a342a2ced diff --git a/vendor/mach b/vendor/mach index c9793a466..6ebeb5ea8 160000 --- a/vendor/mach +++ b/vendor/mach @@ -1 +1 @@ -Subproject commit c9793a4666d21608b1b28d0b67aaa7f7fd8b8031 +Subproject commit 6ebeb5ea854ebfb023653656094d124aaf1c18b1 diff --git a/vendor/zig-js b/vendor/zig-js index c89c1965c..ff405f62c 160000 --- a/vendor/zig-js +++ b/vendor/zig-js @@ -1 +1 @@ -Subproject commit c89c1965cc6bf6ede97c1b891b624ce5282853d1 +Subproject commit ff405f62ce9990f88a8eabea4156fc1cafa0352a diff --git a/vendor/zig-libxml2 b/vendor/zig-libxml2 index 2fad039cd..eabfcf3a0 160000 --- a/vendor/zig-libxml2 +++ b/vendor/zig-libxml2 @@ -1 +1 @@ -Subproject commit 2fad039cd983084b615347333790680983c2f4d4 +Subproject commit eabfcf3a0b3ca319693d3e5991098a77dace5e9b diff --git a/vendor/zig-objc b/vendor/zig-objc index 4f5eda096..1ebffc81e 160000 --- a/vendor/zig-objc +++ b/vendor/zig-objc @@ -1 +1 @@ -Subproject commit 4f5eda096c327a6943c834762cead4d1c9db2366 +Subproject commit 1ebffc81ef7265ed6c6823370b2e2aaaee6bd860