Skip to content

Commit

Permalink
cc: Add support for -Wp,
Browse files Browse the repository at this point in the history
  • Loading branch information
vesim987 authored and andrewrk committed Sep 18, 2024
1 parent 41330c9 commit feaee2b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/clang_options_data.zig
Original file line number Diff line number Diff line change
Expand Up @@ -7472,7 +7472,7 @@ joinpd1("mtp="),
.{
.name = "Wp,",
.syntax = .comma_joined,
.zig_equivalent = .other,
.zig_equivalent = .wp,
.pd1 = true,
.pd2 = false,
.psl = false,
Expand Down
34 changes: 34 additions & 0 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1791,6 +1791,7 @@ fn buildOutputType(
var c_out_mode: ?COutMode = null;
var out_path: ?[]const u8 = null;
var is_shared_lib = false;
var preprocessor_args = std.ArrayList([]const u8).init(arena);
var linker_args = std.ArrayList([]const u8).init(arena);
var it = ClangArgIterator.init(arena, all_args);
var emit_llvm = false;
Expand Down Expand Up @@ -1946,6 +1947,24 @@ fn buildOutputType(
is_shared_lib = true;
},
.rdynamic => create_module.opts.rdynamic = true,
.wp => {
var split_it = mem.splitScalar(u8, it.only_arg, ',');
while (split_it.next()) |preprocessor_arg| {
if (preprocessor_arg.len >= 3 and
preprocessor_arg[0] == '-' and
preprocessor_arg[2] != '-')
{
if (mem.indexOfScalar(u8, preprocessor_arg, '=')) |equals_pos| {
const key = preprocessor_arg[0..equals_pos];
const value = preprocessor_arg[equals_pos + 1 ..];
try preprocessor_args.append(key);
try preprocessor_args.append(value);
continue;
}
}
try preprocessor_args.append(preprocessor_arg);
}
},
.wl => {
var split_it = mem.splitScalar(u8, it.only_arg, ',');
while (split_it.next()) |linker_arg| {
Expand Down Expand Up @@ -2554,6 +2573,20 @@ fn buildOutputType(
}
}

// Parse preprocessor args.
var preprocessor_args_it = ArgsIterator{
.args = preprocessor_args.items,
};
while (preprocessor_args_it.next()) |arg| {
if (mem.eql(u8, arg, "-MD") or mem.eql(u8, arg, "-MMD") or mem.eql(u8, arg, "-MT")) {
disable_c_depfile = true;
const cc_arg = try std.fmt.allocPrint(arena, "-Wp,{s},{s}", .{ arg, preprocessor_args_it.nextOrFatal() });
try cc_argv.append(arena, cc_arg);
} else {
fatal("unsupported preprocessor arg: {s}", .{arg});
}
}

if (mod_opts.sanitize_c) |wsc| {
if (wsc and mod_opts.optimize_mode == .ReleaseFast) {
mod_opts.optimize_mode = .ReleaseSafe;
Expand Down Expand Up @@ -5771,6 +5804,7 @@ pub const ClangArgIterator = struct {
shared,
rdynamic,
wl,
wp,
preprocess_only,
asm_only,
optimize,
Expand Down
4 changes: 4 additions & 0 deletions tools/update_clang_options.zig
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ const known_options = [_]KnownOpt{
.name = "Wl,",
.ident = "wl",
},
.{
.name = "Wp,",
.ident = "wp",
},
.{
.name = "Xlinker",
.ident = "for_linker",
Expand Down

0 comments on commit feaee2b

Please sign in to comment.