build: make the xcframework step dsym aware, even though we don't use it

This was in pursuit of trying to get line numbers in `zig build run` on
macOS to work, but I wasn't able to figure that out and this wasn't the
right path because static libs can't have dsyms. But, it may still be
useful to make the xcframework step dsym aware for future use so I'm
PRing this.
This commit is contained in:
Mitchell Hashimoto
2025-07-09 21:05:54 -07:00
parent 464dc78172
commit cc0d7acaef
3 changed files with 52 additions and 7 deletions

View File

@ -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,
};
}

View File

@ -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,
}},
},
});

View File

@ -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);