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="),...@@ -7472,7 +7472,7 @@ joinpd1("mtp="),
7472.{7472.{
7473 .name = "Wp,",7473 .name = "Wp,",
7474 .syntax = .comma_joined,7474 .syntax = .comma_joined,
7475 .zig_equivalent = .other,7475 .zig_equivalent = .wp,
7476 .pd1 = true,7476 .pd1 = true,
7477 .pd2 = false,7477 .pd2 = false,
7478 .psl = false,7478 .psl = false,
src/main.zig+34
...@@ -1791,6 +1791,7 @@ fn buildOutputType(...@@ -1791,6 +1791,7 @@ fn buildOutputType(
1791 var c_out_mode: ?COutMode = null;1791 var c_out_mode: ?COutMode = null;
1792 var out_path: ?[]const u8 = null;1792 var out_path: ?[]const u8 = null;
1793 var is_shared_lib = false;1793 var is_shared_lib = false;
1794 var preprocessor_args = std.ArrayList([]const u8).init(arena);
1794 var linker_args = std.ArrayList([]const u8).init(arena);1795 var linker_args = std.ArrayList([]const u8).init(arena);
1795 var it = ClangArgIterator.init(arena, all_args);1796 var it = ClangArgIterator.init(arena, all_args);
1796 var emit_llvm = false;1797 var emit_llvm = false;
...@@ -1946,6 +1947,24 @@ fn buildOutputType(...@@ -1946,6 +1947,24 @@ fn buildOutputType(
1946 is_shared_lib = true;1947 is_shared_lib = true;
1947 },1948 },
1948 .rdynamic => create_module.opts.rdynamic = true,1949 .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 },
1949 .wl => {1968 .wl => {
1950 var split_it = mem.splitScalar(u8, it.only_arg, ',');1969 var split_it = mem.splitScalar(u8, it.only_arg, ',');
1951 while (split_it.next()) |linker_arg| {1970 while (split_it.next()) |linker_arg| {
...@@ -2554,6 +2573,20 @@ fn buildOutputType(...@@ -2554,6 +2573,20 @@ fn buildOutputType(
2554 }2573 }
2555 }2574 }
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
2557 if (mod_opts.sanitize_c) |wsc| {2590 if (mod_opts.sanitize_c) |wsc| {
2558 if (wsc and mod_opts.optimize_mode == .ReleaseFast) {2591 if (wsc and mod_opts.optimize_mode == .ReleaseFast) {
2559 mod_opts.optimize_mode = .ReleaseSafe;2592 mod_opts.optimize_mode = .ReleaseSafe;
...@@ -5771,6 +5804,7 @@ pub const ClangArgIterator = struct {...@@ -5771,6 +5804,7 @@ pub const ClangArgIterator = struct {
5771 shared,5804 shared,
5772 rdynamic,5805 rdynamic,
5773 wl,5806 wl,
5807 wp,
5774 preprocess_only,5808 preprocess_only,
5775 asm_only,5809 asm_only,
5776 optimize,5810 optimize,
tools/update_clang_options.zig+4
...@@ -154,6 +154,10 @@ const known_options = [_]KnownOpt{...@@ -154,6 +154,10 @@ const known_options = [_]KnownOpt{
154 .name = "Wl,",154 .name = "Wl,",
155 .ident = "wl",155 .ident = "wl",
156 },156 },
157 .{
158 .name = "Wp,",
159 .ident = "wp",
160 },
157 .{161 .{
158 .name = "Xlinker",162 .name = "Xlinker",
159 .ident = "for_linker",163 .ident = "for_linker",