diff --git a/src/build/GhosttyLib.zig b/src/build/GhosttyLib.zig index 4e36c57c8..857fd1798 100644 --- a/src/build/GhosttyLib.zig +++ b/src/build/GhosttyLib.zig @@ -1,6 +1,7 @@ const GhosttyLib = @This(); const std = @import("std"); +const RunStep = std.Build.Step.Run; const Config = @import("Config.zig"); const SharedDeps = @import("SharedDeps.zig"); const LibtoolStep = @import("LibtoolStep.zig"); @@ -11,6 +12,7 @@ step: *std.Build.Step, /// The final static library file output: std.Build.LazyPath, +dsym: ?std.Build.LazyPath, pub fn initStatic( b: *std.Build, @@ -18,9 +20,14 @@ pub fn initStatic( ) !GhosttyLib { const lib = b.addStaticLibrary(.{ .name = "ghostty", - .root_source_file = b.path("src/main_c.zig"), - .target = deps.config.target, - .optimize = deps.config.optimize, + .root_module = b.createModule(.{ + .root_source_file = b.path("src/main_c.zig"), + .target = deps.config.target, + .optimize = deps.config.optimize, + .strip = deps.config.strip, + .omit_frame_pointer = deps.config.strip, + .unwind_tables = if (deps.config.strip) .none else .sync, + }), }); lib.linkLibC(); @@ -37,6 +44,7 @@ pub fn initStatic( if (!deps.config.target.result.os.tag.isDarwin()) return .{ .step = &lib.step, .output = lib.getEmittedBin(), + .dsym = null, }; // Create a static lib that contains all our dependencies. @@ -50,6 +58,9 @@ pub fn initStatic( return .{ .step = libtool.step, .output = libtool.output, + + // Static libraries cannot have dSYMs because they aren't linked. + .dsym = null, }; } @@ -59,16 +70,35 @@ pub fn initShared( ) !GhosttyLib { const lib = b.addSharedLibrary(.{ .name = "ghostty", - .root_source_file = b.path("src/main_c.zig"), - .target = deps.config.target, - .optimize = deps.config.optimize, - .strip = deps.config.strip, + .root_module = b.createModule(.{ + .root_source_file = b.path("src/main_c.zig"), + .target = deps.config.target, + .optimize = deps.config.optimize, + .strip = deps.config.strip, + .omit_frame_pointer = deps.config.strip, + .unwind_tables = if (deps.config.strip) .none else .sync, + }), }); _ = try deps.add(lib); + // Get our debug symbols + const dsymutil: ?std.Build.LazyPath = dsymutil: { + if (!deps.config.target.result.os.tag.isDarwin()) { + break :dsymutil null; + } + + const dsymutil = RunStep.create(b, "dsymutil"); + dsymutil.addArgs(&.{"dsymutil"}); + dsymutil.addFileArg(lib.getEmittedBin()); + dsymutil.addArgs(&.{"-o"}); + const output = dsymutil.addOutputFileArg("libghostty.dSYM"); + break :dsymutil output; + }; + return .{ .step = &lib.step, .output = lib.getEmittedBin(), + .dsym = dsymutil, }; } @@ -95,6 +125,10 @@ pub fn initMacOSUniversal( return .{ .step = universal.step, .output = universal.output, + + // You can't run dsymutil on a universal binary, you have to + // do it on the individual binaries. + .dsym = null, }; } diff --git a/src/build/GhosttyXCFramework.zig b/src/build/GhosttyXCFramework.zig index 7debd6906..d036e7020 100644 --- a/src/build/GhosttyXCFramework.zig +++ b/src/build/GhosttyXCFramework.zig @@ -64,20 +64,24 @@ pub fn init( .{ .library = macos_universal.output, .headers = b.path("include"), + .dsym = macos_universal.dsym, }, .{ .library = ios.output, .headers = b.path("include"), + .dsym = ios.dsym, }, .{ .library = ios_sim.output, .headers = b.path("include"), + .dsym = ios_sim.dsym, }, }, .native => &.{.{ .library = macos_native.output, .headers = b.path("include"), + .dsym = macos_native.dsym, }}, }, }); diff --git a/src/build/XCFrameworkStep.zig b/src/build/XCFrameworkStep.zig index 8a0d5dc67..39f0f9bac 100644 --- a/src/build/XCFrameworkStep.zig +++ b/src/build/XCFrameworkStep.zig @@ -26,6 +26,9 @@ pub const Library = struct { /// Path to a directory with the headers. headers: LazyPath, + + /// Path to a debug symbols file (.dSYM) if available. + dsym: ?LazyPath, }; step: *Step, @@ -52,6 +55,10 @@ pub fn create(b: *std.Build, opts: Options) *XCFrameworkStep { run.addFileArg(lib.library); run.addArg("-headers"); run.addFileArg(lib.headers); + if (lib.dsym) |dsym| { + run.addArg("-debug-symbols"); + run.addFileArg(dsym); + } } run.addArg("-output"); run.addArg(opts.out_path);