zig
zig copied to clipboard
std.zig.system.NativeTargetInfo: look for a shebang line in /usr/bin/env, if any
UPD: See https://github.com/ziglang/zig/pull/12151#pullrequestreview-1044192217
On which system do you observe /usr/bin/env not being an ELF file? And what is it instead?
On which system do you observe
/usr/bin/envnot being an ELF file? And what is it instead?
https://github.com/ziglang/zig/pull/12151#discussion_r923210625
It can be a script instead:
#!/usr/bin/coreutils --coreutils-prog-shebang=env
or similar.
I think you're hitting a stage1 compiler bug. This diff seems to get things working again:
index c5b9454c9..d9467fe2a 100644
--- a/lib/std/zig/system/NativeTargetInfo.zig
+++ b/lib/std/zig/system/NativeTargetInfo.zig
@@ -390,19 +390,16 @@ fn detectAbiAndDynamicLinker(
else => |e| return e,
};
- var should_close = true;
- defer if (should_close) file.close();
const line = file.reader().readUntilDelimiter(&buffer, '\n') catch {
- should_close = false;
break :blk file;
};
if (mem.startsWith(u8, line, "#!")) {
var it = std.mem.tokenize(u8, line[2..], " ");
file_name = it.next() orelse return defaultAbiAndDynamicLinker(cpu, os, cross_target);
+ file.close();
continue;
} else {
- should_close = false;
break :blk file;
}
}
I think you're hitting a stage1 compiler bug. This diff seems to get things working again:
index c5b9454c9..d9467fe2a 100644 --- a/lib/std/zig/system/NativeTargetInfo.zig +++ b/lib/std/zig/system/NativeTargetInfo.zig @@ -390,19 +390,16 @@ fn detectAbiAndDynamicLinker( else => |e| return e, }; - var should_close = true; - defer if (should_close) file.close(); const line = file.reader().readUntilDelimiter(&buffer, '\n') catch { - should_close = false; break :blk file; }; if (mem.startsWith(u8, line, "#!")) { var it = std.mem.tokenize(u8, line[2..], " "); file_name = it.next() orelse return defaultAbiAndDynamicLinker(cpu, os, cross_target); + file.close(); continue; } else { - should_close = false; break :blk file; } }
Thank you!
Thank you for your helpful reviews! :)