From 6f3ee587ba5ad82178e9fe8a8d788729a3e18d6b Mon Sep 17 00:00:00 2001 From: Winter Date: Thu, 14 Sep 2023 19:16:34 -0400 Subject: [PATCH 1/2] std.zig.system.NativePaths: ignore linkage directives in `NIX_LDFLAGS` `NIX_LDFLAGS` typically contains just `-rpath` and `-L`, which we already handle. However, at least one setup hook in Nixpkgs [0] adds a linkage directive to it. To prevent library paths from being missed (as I've observed myself with `NIX_LDFLAGS` being `-liconv ...`, making it so that *all* paths are missed), let's just skip over them. [0]: https://github.com/NixOS/nixpkgs/blob/08f615eb1b3c5cf7481996f29c6092c7c891b15b/pkgs/development/libraries/libiconv/setup-hook.sh --- lib/std/zig/system/NativePaths.zig | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/std/zig/system/NativePaths.zig b/lib/std/zig/system/NativePaths.zig index 5fd4d56f30..ea07956417 100644 --- a/lib/std/zig/system/NativePaths.zig +++ b/lib/std/zig/system/NativePaths.zig @@ -60,6 +60,8 @@ pub fn detect(arena: Allocator, native_target: std.Target) !NativePaths { const lib_path = word[2..]; try self.addLibDir(lib_path); try self.addRPath(lib_path); + } else if (word.len > 2 and word[0] == '-' and word[1] == 'l') { + // There could still be paths after this. } else { try self.addWarningFmt("Unrecognized C flag from NIX_LDFLAGS: {s}", .{word}); break; From f37513aa68ab128961ef797f83da1a0f9d9673f1 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 23 Jan 2024 18:01:59 -0700 Subject: [PATCH 2/2] NativePaths: support -L and -l arguments in NIX_LDFLAGS A slightly more robust parsing of these flags in case of a separate argument appearing after "-L" in the flags. --- lib/std/zig/system/NativePaths.zig | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/std/zig/system/NativePaths.zig b/lib/std/zig/system/NativePaths.zig index ea07956417..de800f866b 100644 --- a/lib/std/zig/system/NativePaths.zig +++ b/lib/std/zig/system/NativePaths.zig @@ -56,12 +56,17 @@ pub fn detect(arena: Allocator, native_target: std.Target) !NativePaths { break; }; try self.addRPath(rpath); - } else if (word.len > 2 and word[0] == '-' and word[1] == 'L') { + } else if (mem.eql(u8, word, "-L") or mem.eql(u8, word, "-l")) { + _ = it.next() orelse { + try self.addWarning("Expected argument after -L or -l in NIX_LDFLAGS"); + break; + }; + } else if (mem.startsWith(u8, word, "-L")) { const lib_path = word[2..]; try self.addLibDir(lib_path); try self.addRPath(lib_path); - } else if (word.len > 2 and word[0] == '-' and word[1] == 'l') { - // There could still be paths after this. + } else if (mem.startsWith(u8, word, "-l")) { + // Ignore this argument. } else { try self.addWarningFmt("Unrecognized C flag from NIX_LDFLAGS: {s}", .{word}); break;