Skip to content

Commit 6e456fb

Browse files
committed
Use the rename shuffle on all platforms
1 parent be4eaed commit 6e456fb

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

src/Compilation.zig

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3127,23 +3127,26 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) UpdateE
31273127

31283128
// Work around windows `AccessDenied` if any files within this
31293129
// directory are open by closing and reopening the file handles.
3130+
// While this need is only documented on windows, there are some
3131+
// niche scenarios, such as WSL on ReFS, where it may be required
3132+
// on other platforms. As the workaround is low-cost, just
3133+
// use it on all platforms rather than trying to isolate every
3134+
// specific case where it's needed.
31303135
const need_writable_dance: enum { no, lf_only, lf_and_debug } = w: {
3131-
if (builtin.os.tag == .windows) {
3132-
if (comp.bin_file) |lf| {
3133-
// We cannot just call `makeExecutable` as it makes a false
3134-
// assumption that we have a file handle open only when linking
3135-
// an executable file. This used to be true when our linkers
3136-
// were incapable of emitting relocatables and static archive.
3137-
// Now that they are capable, we need to unconditionally close
3138-
// the file handle and re-open it in the follow up call to
3139-
// `makeWritable`.
3140-
if (lf.file) |f| {
3141-
f.close();
3142-
lf.file = null;
3143-
3144-
if (lf.closeDebugInfo()) break :w .lf_and_debug;
3145-
break :w .lf_only;
3146-
}
3136+
if (comp.bin_file) |lf| {
3137+
// We cannot just call `makeExecutable` as it makes a false
3138+
// assumption that we have a file handle open only when linking
3139+
// an executable file. This used to be true when our linkers
3140+
// were incapable of emitting relocatables and static archive.
3141+
// Now that they are capable, we need to unconditionally close
3142+
// the file handle and re-open it in the follow up call to
3143+
// `makeWritable`.
3144+
if (lf.file) |f| {
3145+
f.close();
3146+
lf.file = null;
3147+
3148+
if (lf.closeDebugInfo()) break :w .lf_and_debug;
3149+
break :w .lf_only;
31473150
}
31483151
}
31493152
break :w .no;
@@ -3177,7 +3180,7 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) UpdateE
31773180
.root_dir = comp.dirs.local_cache,
31783181
.sub_path = try fs.path.join(arena, &.{ o_sub_path, comp.emit_bin.? }),
31793182
};
3180-
const result: (link.File.OpenError || error{HotSwapUnavailableOnHostOperatingSystem})!void = switch (need_writable_dance) {
3183+
const result: (link.File.OpenError || error{HotSwapUnavailableOnHostOperatingSystem,RenameAcrossMountPoints,InvalidFileName})!void = switch (need_writable_dance) {
31813184
.no => {},
31823185
.lf_only => lf.makeWritable(),
31833186
.lf_and_debug => res: {

0 commit comments

Comments
 (0)