authorgravatar for vesim809@pm.meMaciej 'vesim' Kuliński <vesim809@pm.me> 2024-09-18 05:10:36+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-09-17 23:54:04-07:00
logfeaee2ba170766cc905a6aa9c799f3105cdc8145
treea984efc8d76751c38c2b18f6b04ea6e440bf6124
parent41330c96aebddbf26d8fdc0725e7483476175601

cc: Add support for -Wp,


3 files changed, 39 insertions(+), 1 deletions(-)

src/clang_options_data.zig+1-1
......@@ -7472,7 +7472,7 @@ joinpd1("mtp="),
74727472.{
74737473 .name = "Wp,",
74747474 .syntax = .comma_joined,
7475 .zig_equivalent = .other,
7475 .zig_equivalent = .wp,
74767476 .pd1 = true,
74777477 .pd2 = false,
74787478 .psl = false,
src/main.zig+34
......@@ -1791,6 +1791,7 @@ fn buildOutputType(
17911791 var c_out_mode: ?COutMode = null;
17921792 var out_path: ?[]const u8 = null;
17931793 var is_shared_lib = false;
1794 var preprocessor_args = std.ArrayList([]const u8).init(arena);
17941795 var linker_args = std.ArrayList([]const u8).init(arena);
17951796 var it = ClangArgIterator.init(arena, all_args);
17961797 var emit_llvm = false;
......@@ -1946,6 +1947,24 @@ fn buildOutputType(
19461947 is_shared_lib = true;
19471948 },
19481949 .rdynamic => create_module.opts.rdynamic = true,
1950 .wp => {
1951 var split_it = mem.splitScalar(u8, it.only_arg, ',');
1952 while (split_it.next()) |preprocessor_arg| {
1953 if (preprocessor_arg.len >= 3 and
1954 preprocessor_arg[0] == '-' and
1955 preprocessor_arg[2] != '-')
1956 {
1957 if (mem.indexOfScalar(u8, preprocessor_arg, '=')) |equals_pos| {
1958 const key = preprocessor_arg[0..equals_pos];
1959 const value = preprocessor_arg[equals_pos + 1 ..];
1960 try preprocessor_args.append(key);
1961 try preprocessor_args.append(value);
1962 continue;
1963 }
1964 }
1965 try preprocessor_args.append(preprocessor_arg);
1966 }
1967 },
19491968 .wl => {
19501969 var split_it = mem.splitScalar(u8, it.only_arg, ',');
19511970 while (split_it.next()) |linker_arg| {
......@@ -2554,6 +2573,20 @@ fn buildOutputType(
25542573 }
25552574 }
25562575
2576 // Parse preprocessor args.
2577 var preprocessor_args_it = ArgsIterator{
2578 .args = preprocessor_args.items,
2579 };
2580 while (preprocessor_args_it.next()) |arg| {
2581 if (mem.eql(u8, arg, "-MD") or mem.eql(u8, arg, "-MMD") or mem.eql(u8, arg, "-MT")) {
2582 disable_c_depfile = true;
2583 const cc_arg = try std.fmt.allocPrint(arena, "-Wp,{s},{s}", .{ arg, preprocessor_args_it.nextOrFatal() });
2584 try cc_argv.append(arena, cc_arg);
2585 } else {
2586 fatal("unsupported preprocessor arg: {s}", .{arg});
2587 }
2588 }
2589
25572590 if (mod_opts.sanitize_c) |wsc| {
25582591 if (wsc and mod_opts.optimize_mode == .ReleaseFast) {
25592592 mod_opts.optimize_mode = .ReleaseSafe;
......@@ -5771,6 +5804,7 @@ pub const ClangArgIterator = struct {
57715804 shared,
57725805 rdynamic,
57735806 wl,
5807 wp,
57745808 preprocess_only,
57755809 asm_only,
57765810 optimize,
tools/update_clang_options.zig+4
......@@ -154,6 +154,10 @@ const known_options = [_]KnownOpt{
154154 .name = "Wl,",
155155 .ident = "wl",
156156 },
157 .{
158 .name = "Wp,",
159 .ident = "wp",
160 },
157161 .{
158162 .name = "Xlinker",
159163 .ident = "for_linker",