diff options
| author | mlugg <mlugg@mlugg.co.uk> | 2025-02-25 23:58:14 +0000 |
|---|---|---|
| committer | Jacob Young <jacobly0@users.noreply.github.com> | 2025-03-02 16:39:18 -0500 |
| commit | 725c82582935d2bb84d52d906edb2975827b01ec (patch) | |
| tree | 4a46d9a3f26ec99e4da17e61eeec7c5b5a601fb3 /src/Compilation.zig | |
| parent | c2983a3f88411c1c9c20582c43054c07cbbd88b3 (diff) | |
| download | zig-725c82582935d2bb84d52d906edb2975827b01ec.tar.gz zig-725c82582935d2bb84d52d906edb2975827b01ec.zip | |
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
Diffstat (limited to 'src/Compilation.zig')
| -rw-r--r-- | src/Compilation.zig | 17 |
1 files changed, 12 insertions, 5 deletions
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(); + }, } } |
