From 725c82582935d2bb84d52d906edb2975827b01ec Mon Sep 17 00:00:00 2001 From: mlugg Date: Tue, 25 Feb 2025 23:58:14 +0000 Subject: link: make sure MachO closes the damn files Windows is a ridiculous operating system designed by toddlers, and so requires us to close all file handles in the `tmp/xxxxxxx` cache dir before renaming it into `o/xxxxxxx`. We have a hack in place to handle this for the main output file, but the MachO linker also outputs a file with debug symbols, and we weren't closing it! This led to a fuckton of CI failures when we enabled `.whole` cache mode by default for self-hosted backends. thanks jacob for figuring this out while i sat there --- src/Compilation.zig | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src/Compilation.zig') diff --git a/src/Compilation.zig b/src/Compilation.zig index 399b9b30b7..12221ba3dc 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -2397,7 +2397,7 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) !void { // Work around windows `AccessDenied` if any files within this // directory are open by closing and reopening the file handles. - const need_writable_dance = w: { + const need_writable_dance: enum { no, lf_only, lf_and_debug } = w: { if (builtin.os.tag == .windows) { if (comp.bin_file) |lf| { // We cannot just call `makeExecutable` as it makes a false @@ -2410,11 +2410,13 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) !void { if (lf.file) |f| { f.close(); lf.file = null; - break :w true; + + if (lf.closeDebugInfo()) break :w .lf_and_debug; + break :w .lf_only; } } } - break :w false; + break :w .no; }; renameTmpIntoCache(comp.local_cache_directory, tmp_dir_sub_path, o_sub_path) catch |err| { @@ -2441,8 +2443,13 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) !void { }; // Has to be after the `wholeCacheModeSetBinFilePath` above. - if (need_writable_dance) { - try lf.makeWritable(); + switch (need_writable_dance) { + .no => {}, + .lf_only => try lf.makeWritable(), + .lf_and_debug => { + try lf.makeWritable(); + try lf.reopenDebugInfo(); + }, } } -- cgit v1.2.3