From 7ddf3f0b5d2bcc20ab801ab846bf348df47cc0e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Tue, 2 May 2023 14:40:35 +0300 Subject: [PATCH] launcher: workaround `zig cc -Wl,--version` A hack for https://github.com/ziglang/zig/issues/15549 --- toolchain/launcher.zig | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/toolchain/launcher.zig b/toolchain/launcher.zig index d0bf711..bac146e 100644 --- a/toolchain/launcher.zig +++ b/toolchain/launcher.zig @@ -219,11 +219,25 @@ fn parseArgs( // args is the path to the zig binary and args to it. var args = ArrayListUnmanaged([]const u8){}; try args.appendSlice(arena, &[_][]const u8{ zig_exe, zig_tool }); + if (maybe_target) |target| try args.appendSlice(arena, &[_][]const u8{ "-target", target }); - while (argv_it.next()) |arg| - try args.append(arena, arg); + const is_linux = if (maybe_target) |target| + mem.indexOf(u8, target, "linux") != null + else + false; + + while (argv_it.next()) |arg| { + // hack for https://github.com/ziglang/zig/issues/15549 + if (is_linux and mem.eql(u8, "-Wl,--version", arg)) { + args.shrinkRetainingCapacity(1); // only external/zig_sdk/zig + try args.appendSlice(arena, &[_][]const u8{ "ld.lld", "--version" }); + break; + } else { + try args.append(arena, arg); + } + } return ParseResults{ .exec = .{ .args = args, .env = env } }; } @@ -361,6 +375,24 @@ test "launcher:parseArgs" { }, }, }, + .{ + .args = &[_][:0]const u8{ + "tools" ++ sep ++ "x86_64-linux-musl" ++ sep ++ "c++" ++ EXE, + "-Wl,--version", + }, + .want_result = .{ + .exec = .{ + .args = &[_][:0]const u8{ + "tools" ++ sep ++ "x86_64-linux-musl" ++ sep ++ + ".." ++ sep ++ ".." ++ sep ++ "zig" ++ EXE, + "ld.lld", + "--version", + }, + .env_zig_lib_dir = "tools" ++ sep ++ "x86_64-linux-musl" ++ + sep ++ ".." ++ sep ++ ".." ++ sep ++ "lib", + }, + }, + }, .{ .args = &[_][:0]const u8{ "tools" ++ sep ++ "x86_64-linux-musl" ++ sep ++ "ar" ++ EXE,