Skip to content

Commit f8cc6a1

Browse files
committed
zig cc: fix ambiguity with -MT
In an MSVC context, `-MT` means "Use static run-time" and it is a flag with no parameter. On POSIX it means "Specify name of main file output in depfile" and it is "joined or separate". The former was interfering with the latter. Now, the MT flag is required to be specified with a `/` to disambiguate: `/MT`.
1 parent e7f555c commit f8cc6a1

File tree

3 files changed

+104
-17
lines changed

3 files changed

+104
-17
lines changed

src-self-hosted/clang_options.zig

+10
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,16 @@ pub fn flagpd1(name: []const u8) CliArg {
9595
};
9696
}
9797

98+
/// Shortcut function for initializing a `CliArg`
99+
pub fn flagpsl(name: []const u8) CliArg {
100+
return .{
101+
.name = name,
102+
.syntax = .flag,
103+
.zig_equivalent = .other,
104+
.psl = true,
105+
};
106+
}
107+
98108
/// Shortcut function for initializing a `CliArg`
99109
pub fn joinpd1(name: []const u8) CliArg {
100110
return .{

src-self-hosted/clang_options_data.zig

+58-16
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,38 @@ flagpd1("M"),
3434
.pd2 = false,
3535
.psl = false,
3636
},
37-
flagpd1("MG"),
38-
flagpd1("MM"),
39-
flagpd1("MMD"),
40-
flagpd1("MP"),
37+
.{
38+
.name = "MG",
39+
.syntax = .flag,
40+
.zig_equivalent = .dep_file,
41+
.pd1 = true,
42+
.pd2 = false,
43+
.psl = false,
44+
},
45+
.{
46+
.name = "MM",
47+
.syntax = .flag,
48+
.zig_equivalent = .dep_file,
49+
.pd1 = true,
50+
.pd2 = false,
51+
.psl = false,
52+
},
53+
.{
54+
.name = "MMD",
55+
.syntax = .flag,
56+
.zig_equivalent = .dep_file,
57+
.pd1 = true,
58+
.pd2 = false,
59+
.psl = false,
60+
},
61+
.{
62+
.name = "MP",
63+
.syntax = .flag,
64+
.zig_equivalent = .dep_file,
65+
.pd1 = true,
66+
.pd2 = false,
67+
.psl = false,
68+
},
4169
.{
4270
.name = "MV",
4371
.syntax = .flag,
@@ -517,14 +545,7 @@ sepd1("Zlinker-input"),
517545
.pd2 = false,
518546
.psl = true,
519547
},
520-
.{
521-
.name = "MT",
522-
.syntax = .flag,
523-
.zig_equivalent = .other,
524-
.pd1 = true,
525-
.pd2 = false,
526-
.psl = true,
527-
},
548+
flagpsl("MT"),
528549
.{
529550
.name = "MTd",
530551
.syntax = .flag,
@@ -5463,9 +5484,30 @@ joinpd1("G="),
54635484
.pd2 = false,
54645485
.psl = false,
54655486
},
5466-
jspd1("MJ"),
5467-
jspd1("MQ"),
5468-
jspd1("MT"),
5487+
.{
5488+
.name = "MJ",
5489+
.syntax = .joined_or_separate,
5490+
.zig_equivalent = .dep_file,
5491+
.pd1 = true,
5492+
.pd2 = false,
5493+
.psl = false,
5494+
},
5495+
.{
5496+
.name = "MQ",
5497+
.syntax = .joined_or_separate,
5498+
.zig_equivalent = .dep_file,
5499+
.pd1 = true,
5500+
.pd2 = false,
5501+
.psl = false,
5502+
},
5503+
.{
5504+
.name = "MT",
5505+
.syntax = .joined_or_separate,
5506+
.zig_equivalent = .dep_file,
5507+
.pd1 = true,
5508+
.pd2 = false,
5509+
.psl = false,
5510+
},
54695511
.{
54705512
.name = "AI",
54715513
.syntax = .joined_or_separate,
@@ -5589,7 +5631,7 @@ jspd1("MT"),
55895631
.{
55905632
.name = "MP",
55915633
.syntax = .joined,
5592-
.zig_equivalent = .other,
5634+
.zig_equivalent = .dep_file,
55935635
.pd1 = true,
55945636
.pd2 = false,
55955637
.psl = true,

tools/update_clang_options.zig

+36-1
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,34 @@ const known_options = [_]KnownOpt{
206206
.name = "MF",
207207
.ident = "dep_file",
208208
},
209+
.{
210+
.name = "MT",
211+
.ident = "dep_file",
212+
},
213+
.{
214+
.name = "MG",
215+
.ident = "dep_file",
216+
},
217+
.{
218+
.name = "MJ",
219+
.ident = "dep_file",
220+
},
221+
.{
222+
.name = "MM",
223+
.ident = "dep_file",
224+
},
225+
.{
226+
.name = "MMD",
227+
.ident = "dep_file",
228+
},
229+
.{
230+
.name = "MP",
231+
.ident = "dep_file",
232+
},
233+
.{
234+
.name = "MQ",
235+
.ident = "dep_file",
236+
},
209237
.{
210238
.name = "F",
211239
.ident = "framework_dir",
@@ -336,7 +364,12 @@ pub fn main() anyerror!void {
336364
}
337365
const syntax = objSyntax(obj);
338366

339-
if (knownOption(name)) |ident| {
367+
if (std.mem.eql(u8, name, "MT") and syntax == .flag) {
368+
// `-MT foo` is ambiguous because there is also an -MT flag
369+
// The canonical way to specify the flag is with `/MT` and so we make this
370+
// the only way.
371+
try stdout.print("flagpsl(\"{}\"),\n", .{name});
372+
} else if (knownOption(name)) |ident| {
340373
try stdout.print(
341374
\\.{{
342375
\\ .name = "{}",
@@ -350,6 +383,8 @@ pub fn main() anyerror!void {
350383
, .{ name, syntax, ident, pd1, pd2, pslash });
351384
} else if (pd1 and !pd2 and !pslash and syntax == .flag) {
352385
try stdout.print("flagpd1(\"{}\"),\n", .{name});
386+
} else if (!pd1 and !pd2 and pslash and syntax == .flag) {
387+
try stdout.print("flagpsl(\"{}\"),\n", .{name});
353388
} else if (pd1 and !pd2 and !pslash and syntax == .joined) {
354389
try stdout.print("joinpd1(\"{}\"),\n", .{name});
355390
} else if (pd1 and !pd2 and !pslash and syntax == .joined_or_separate) {

0 commit comments

Comments
 (0)