From 51e96a823ce21a6b027bfdf55d94c3872a103703 Mon Sep 17 00:00:00 2001 From: Jacob Young Date: Fri, 16 Feb 2024 06:01:46 +0100 Subject: [PATCH] build.zig: support multiple args in `cxx_compiler_arg1` An example of this happening is during CI runs where it has a value such as `c++ -target x86_64-linux-musl -mcpu=baseline`. --- build.zig | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/build.zig b/build.zig index 3ec58d9696..5ca0e08d4e 100644 --- a/build.zig +++ b/build.zig @@ -811,10 +811,14 @@ fn addCxxKnownPath( if (!std.process.can_spawn) return error.RequiredLibraryNotFound; - const path_padded = if (ctx.cxx_compiler_arg1.len > 0) - b.run(&.{ ctx.cxx_compiler, ctx.cxx_compiler_arg1, b.fmt("-print-file-name={s}", .{objname}) }) - else - b.run(&.{ ctx.cxx_compiler, b.fmt("-print-file-name={s}", .{objname}) }); + const path_padded = run: { + var args = std.ArrayList([]const u8).init(b.allocator); + try args.append(ctx.cxx_compiler); + var it = std.mem.tokenizeAny(u8, ctx.cxx_compiler_arg1, &std.ascii.whitespace); + while (it.next()) |arg| try args.append(arg); + try args.append(b.fmt("-print-file-name={s}", .{objname})); + break :run b.run(args.items); + }; var tokenizer = mem.tokenizeAny(u8, path_padded, "\r\n"); const path_unpadded = tokenizer.next().?; if (mem.eql(u8, path_unpadded, objname)) {