Commit f37513aa68

Andrew Kelley <andrew@ziglang.org>
2024-01-24 02:01:59
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.
1 parent 6f3ee58
Changed files (1)
lib
std
zig
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;