authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-04-01 16:33:29-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-04-01 16:33:29-07:00
log09000c3f77a85b1b1bf0e19b09aae7deaf9f1faa
tree4ac6b935dbf9eb4b50fea206b752bfe4ab178a33
parent50bcfb8c906be67a044ff4bef857a8d6d615de71

zig cc: copy .pdb files from zig-cache/ when appropriate

closes #8407

1 files changed, 31 insertions(+), 6 deletions(-)

src/main.zig+31-6
......@@ -2112,12 +2112,37 @@ fn updateModule(gpa: *Allocator, comp: *Compilation, hook: AfterUpdateHook) !voi
21122112 } else switch (hook) {
21132113 .none => {},
21142114 .print => |bin_path| try io.getStdOut().writer().print("{s}\n", .{bin_path}),
2115 .update => |full_path| _ = try comp.bin_file.options.emit.?.directory.handle.updateFile(
2116 comp.bin_file.options.emit.?.sub_path,
2117 fs.cwd(),
2118 full_path,
2119 .{},
2120 ),
2115 .update => |full_path| {
2116 const bin_sub_path = comp.bin_file.options.emit.?.sub_path;
2117 const cwd = fs.cwd();
2118 const cache_dir = comp.bin_file.options.emit.?.directory.handle;
2119 _ = try cache_dir.updateFile(bin_sub_path, cwd, full_path, .{});
2120
2121 // If a .pdb file is part of the expected output, we must also copy
2122 // it into place here.
2123 const coff_or_pe = switch (comp.bin_file.options.object_format) {
2124 .coff, .pe => true,
2125 else => false,
2126 };
2127 const have_pdb = coff_or_pe and !comp.bin_file.options.strip;
2128 if (have_pdb) {
2129 // Replace `.out` or `.exe` with `.pdb` on both the source and destination
2130 const src_bin_ext = fs.path.extension(bin_sub_path);
2131 const dst_bin_ext = fs.path.extension(full_path);
2132
2133 const src_pdb_path = try std.fmt.allocPrint(gpa, "{s}.pdb", .{
2134 bin_sub_path[0 .. bin_sub_path.len - src_bin_ext.len],
2135 });
2136 defer gpa.free(src_pdb_path);
2137
2138 const dst_pdb_path = try std.fmt.allocPrint(gpa, "{s}.pdb", .{
2139 full_path[0 .. full_path.len - dst_bin_ext.len],
2140 });
2141 defer gpa.free(dst_pdb_path);
2142
2143 _ = try cache_dir.updateFile(src_pdb_path, cwd, dst_pdb_path, .{});
2144 }
2145 },
21212146 }
21222147}
21232148