From af9c6f2c696201e16d95f79a7275aae19b34cd59 Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Fri, 14 May 2021 13:09:40 +0200 Subject: macho: put dSYM bundle in zig-cache Originally, I thought that the dSYM bundle has to reside side-by-side with the binary it carries the debugging information for. However, it turns out macOS is clever enough that it auto-searches for matching dSYM bundle based on the embedded UUID of the binary. To verify this, run this on your macOS: ``` mdfind "com_apple_xcode_dsym_uuids == " ``` See [here] for more info. [here]: https://developer.apple.com/documentation/xcode/adding-identifiable-symbol-names-to-a-crash-report --- src/link/MachO.zig | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/link/MachO.zig b/src/link/MachO.zig index 5a0deb67bc..0a4eb6da87 100644 --- a/src/link/MachO.zig +++ b/src/link/MachO.zig @@ -363,18 +363,30 @@ pub fn openPath(allocator: *Allocator, sub_path: []const u8, options: link.Optio self.base.file = file; // Create dSYM bundle. - const d_sym_path = try fmt.allocPrint(allocator, "{s}.dSYM/Contents/Resources/DWARF/", .{sub_path}); - defer allocator.free(d_sym_path); - var d_sym_bundle = try options.emit.?.directory.handle.makeOpenPath(d_sym_path, .{}); - defer d_sym_bundle.close(); - const d_sym_file = try d_sym_bundle.createFile(sub_path, .{ - .truncate = false, - .read = true, - }); - self.d_sym = .{ - .base = self, - .file = d_sym_file, - }; + if (options.module) |mod| { + const dir = mod.zig_cache_artifact_directory; + log.debug("creating {s}.dSYM bundle in {s}", .{ sub_path, dir.path }); + + const d_sym_path = try fmt.allocPrint( + allocator, + "{s}.dSYM" ++ fs.path.sep_str ++ "Contents" ++ fs.path.sep_str ++ "Resources" ++ fs.path.sep_str ++ "DWARF", + .{sub_path}, + ); + defer allocator.free(d_sym_path); + + var d_sym_bundle = try dir.handle.makeOpenPath(d_sym_path, .{}); + defer d_sym_bundle.close(); + + const d_sym_file = try d_sym_bundle.createFile(sub_path, .{ + .truncate = false, + .read = true, + }); + + self.d_sym = .{ + .base = self, + .file = d_sym_file, + }; + } // Index 0 is always a null symbol. try self.locals.append(allocator, .{ @@ -387,7 +399,7 @@ pub fn openPath(allocator: *Allocator, sub_path: []const u8, options: link.Optio switch (options.output_mode) { .Exe => {}, - .Obj => {}, + .Obj => return error.TODOImplementWritingObjFiles, .Lib => return error.TODOImplementWritingLibFiles, } -- cgit v1.2.3