Commit af9c6f2c69

Jakub Konka <kubkon@jakubkonka.com>
2021-05-14 13:09:40
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 == <UUID from LC_UUID>" ``` See [here] for more info. [here]: https://developer.apple.com/documentation/xcode/adding-identifiable-symbol-names-to-a-crash-report
1 parent 00ebbe6
Changed files (1)
src
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,
     }