From 54714d9103f5faa67edc77bdb2796767107fb3ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matheus=20Catarino=20Fran=C3=A7a?= Date: Tue, 2 Jan 2024 15:07:07 -0300 Subject: [PATCH] zcc: improvement wrapper --- tools/zigcc.zig | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/tools/zigcc.zig b/tools/zigcc.zig index 252ecf0..0534428 100644 --- a/tools/zigcc.zig +++ b/tools/zigcc.zig @@ -21,27 +21,32 @@ pub fn main() !void { try cmds.append("zig"); try cmds.append("cc"); - // LDC2 not set triple targets to cc/linker, except Apple (Why?) - switch (builtin.os.tag) { - .windows => { - try cmds.append("-target"); - try cmds.append("native-native-msvc"); // msvc only - }, - .ios, .macos, .watchos, .tvos => {}, - else => { - try cmds.append("-target"); - try cmds.append("native-native"); - try cmds.append("-lunwind"); - }, - } + if (builtin.os.tag != .windows) + // not working on msvc target (nostdlib++) + try cmds.append("-lunwind"); + // LDC2 not setting triple targets on host build to cc/linker, except Apple (why?) + var isNative = true; while (args.next()) |arg| { if (std.mem.eql(u8, arg, std.fmt.comptimePrint("{s}-apple-{s}", .{ @tagName(builtin.cpu.arch), @tagName(builtin.os.tag) }))) { + isNative = false; try cmds.append("native-native"); - try cmds.append("-lunwind"); try cmds.append("-fapple-link-rtlib"); - } else try cmds.append(arg); + } else if (std.mem.eql(u8, arg, "-target")) { + isNative = false; + } else { + try cmds.append(arg); + } } + if (isNative) { + try cmds.append("-target"); + if (builtin.os.tag == .windows) + try cmds.append("native-native-msvc") + else { + try cmds.append("native-native"); + } + } + var proc = std.ChildProcess.init(cmds.items, allocator); // See all flags