This value, std.os.PATH_MAX applies to the host target. However the linker is supposed to be linking for the target given to the compiler at runtime.
|
const name_len = if (assume_max_path_len) std.os.PATH_MAX else std.mem.len(name) + 1; |
This bug is revealed clearly when compiling for WASI which has no std.os.PATH_MAX value, yet should still be able to cross-compile macos binaries:
$ stage3/bin/zig build -p wasi -Dskip-install-lib-files -Dtarget=wasm32-wasi
/home/andy/Downloads/zig/lib/std/os.zig:110:28: error: root struct of file 'os.wasi' has no member named 'PATH_MAX'
pub const PATH_MAX = system.PATH_MAX;
~~~~~~^~~~~~~~~
referenced by:
calcInstallNameLen: /home/andy/Downloads/zig/src/link/MachO.zig:3540:53
calcLCsSize: /home/andy/Downloads/zig/src/link/MachO.zig:3577:24
remaining reference traces hidden; use '-freference-trace' to see all reference traces
In theory we should be able to use instead something like std.os.darwin.PATH_MAX however the std lib is organized in a way that only makes that work if the host matches.
A quickfix instead would look something like this:
--- a/src/link/MachO.zig
+++ b/src/link/MachO.zig
@@ -3537,7 +3537,8 @@ pub fn populateMissingMetadata(self: *MachO) !void {
}
inline fn calcInstallNameLen(cmd_size: u64, name: []const u8, assume_max_path_len: bool) u64 {
- const name_len = if (assume_max_path_len) std.os.PATH_MAX else std.mem.len(name) + 1;
+ const darwin_path_max = 1024;
+ const name_len = if (assume_max_path_len) darwin_path_max else std.mem.len(name) + 1;
return mem.alignForwardGeneric(u64, cmd_size + name_len, @alignOf(u64));
}
This value,
std.os.PATH_MAXapplies to the host target. However the linker is supposed to be linking for the target given to the compiler at runtime.zig/src/link/MachO.zig
Line 3540 in 3f577f0
This bug is revealed clearly when compiling for WASI which has no
std.os.PATH_MAXvalue, yet should still be able to cross-compile macos binaries:In theory we should be able to use instead something like
std.os.darwin.PATH_MAXhowever the std lib is organized in a way that only makes that work if the host matches.A quickfix instead would look something like this: