diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-04-01 16:33:29 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-04-01 16:33:29 -0700 |
| commit | 09000c3f77a85b1b1bf0e19b09aae7deaf9f1faa (patch) | |
| tree | 4ac6b935dbf9eb4b50fea206b752bfe4ab178a33 /src/main.zig | |
| parent | 50bcfb8c906be67a044ff4bef857a8d6d615de71 (diff) | |
| download | zig-09000c3f77a85b1b1bf0e19b09aae7deaf9f1faa.tar.gz zig-09000c3f77a85b1b1bf0e19b09aae7deaf9f1faa.zip | |
zig cc: copy .pdb files from zig-cache/ when appropriate
closes #8407
Diffstat (limited to 'src/main.zig')
| -rw-r--r-- | src/main.zig | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/src/main.zig b/src/main.zig index 9e7e0541b1..a40be84e56 100644 --- a/src/main.zig +++ b/src/main.zig @@ -2112,12 +2112,37 @@ fn updateModule(gpa: *Allocator, comp: *Compilation, hook: AfterUpdateHook) !voi } else switch (hook) { .none => {}, .print => |bin_path| try io.getStdOut().writer().print("{s}\n", .{bin_path}), - .update => |full_path| _ = try comp.bin_file.options.emit.?.directory.handle.updateFile( - comp.bin_file.options.emit.?.sub_path, - fs.cwd(), - full_path, - .{}, - ), + .update => |full_path| { + const bin_sub_path = comp.bin_file.options.emit.?.sub_path; + const cwd = fs.cwd(); + const cache_dir = comp.bin_file.options.emit.?.directory.handle; + _ = try cache_dir.updateFile(bin_sub_path, cwd, full_path, .{}); + + // If a .pdb file is part of the expected output, we must also copy + // it into place here. + const coff_or_pe = switch (comp.bin_file.options.object_format) { + .coff, .pe => true, + else => false, + }; + const have_pdb = coff_or_pe and !comp.bin_file.options.strip; + if (have_pdb) { + // Replace `.out` or `.exe` with `.pdb` on both the source and destination + const src_bin_ext = fs.path.extension(bin_sub_path); + const dst_bin_ext = fs.path.extension(full_path); + + const src_pdb_path = try std.fmt.allocPrint(gpa, "{s}.pdb", .{ + bin_sub_path[0 .. bin_sub_path.len - src_bin_ext.len], + }); + defer gpa.free(src_pdb_path); + + const dst_pdb_path = try std.fmt.allocPrint(gpa, "{s}.pdb", .{ + full_path[0 .. full_path.len - dst_bin_ext.len], + }); + defer gpa.free(dst_pdb_path); + + _ = try cache_dir.updateFile(src_pdb_path, cwd, dst_pdb_path, .{}); + } + }, } } |
