@@ -800,7 +800,7 @@ pub fn linkFrameworkWeak(c: *Compile, name: []const u8) void {
800800 c .root_module .linkFramework (name , .{ .weak = true });
801801}
802802
803- /// Handy when you have many C/C++ source files and want them all to have the same flags.
803+ /// Handy when you have many non-Zig source files and want them all to have the same flags.
804804pub fn addCSourceFiles (compile : * Compile , options : Module.AddCSourceFilesOptions ) void {
805805 compile .root_module .addCSourceFiles (options );
806806}
@@ -1250,47 +1250,72 @@ fn getZigArgs(compile: *Compile, fuzz: bool) ![][]const u8 {
12501250 .c_source_file = > | c_source_file | l : {
12511251 if (! my_responsibility ) break :l ;
12521252
1253- if (c_source_file .flags .len == 0 ) {
1254- if (prev_has_cflags ) {
1255- try zig_args .append ("-cflags" );
1256- try zig_args .append ("--" );
1257- prev_has_cflags = false ;
1258- }
1259- } else {
1253+ if (prev_has_cflags or c_source_file .flags .len != 0 ) {
12601254 try zig_args .append ("-cflags" );
12611255 for (c_source_file .flags ) | arg | {
12621256 try zig_args .append (arg );
12631257 }
12641258 try zig_args .append ("--" );
1265- prev_has_cflags = true ;
12661259 }
1260+ prev_has_cflags = (c_source_file .flags .len != 0 );
1261+
1262+ if (c_source_file .language != .find_by_file_extension ) {
1263+ try zig_args .append ("-x" );
1264+ try zig_args .append (switch (c_source_file .language ) {
1265+ .find_by_file_extension = > unreachable ,
1266+ .c = > "c" ,
1267+ .cpp = > "c++" ,
1268+ .assembly = > "assembler" ,
1269+ .assembly_with_cpp = > "assembler-with-cpp" ,
1270+ .objc = > "objective-c" ,
1271+ .objcpp = > "objective-c++" ,
1272+ });
1273+ }
1274+
12671275 try zig_args .append (c_source_file .file .getPath2 (dep .module .owner , step ));
1276+
1277+ if (c_source_file .language != .find_by_file_extension ) {
1278+ try zig_args .append ("-x" );
1279+ try zig_args .append ("none" );
1280+ }
12681281 total_linker_objects += 1 ;
12691282 },
12701283
12711284 .c_source_files = > | c_source_files | l : {
12721285 if (! my_responsibility ) break :l ;
12731286
1274- if (c_source_files .flags .len == 0 ) {
1275- if (prev_has_cflags ) {
1276- try zig_args .append ("-cflags" );
1277- try zig_args .append ("--" );
1278- prev_has_cflags = false ;
1279- }
1280- } else {
1287+ if (prev_has_cflags or c_source_files .flags .len != 0 ) {
12811288 try zig_args .append ("-cflags" );
1282- for (c_source_files .flags ) | flag | {
1283- try zig_args .append (flag );
1289+ for (c_source_files .flags ) | arg | {
1290+ try zig_args .append (arg );
12841291 }
12851292 try zig_args .append ("--" );
1286- prev_has_cflags = true ;
1293+ }
1294+ prev_has_cflags = (c_source_files .flags .len != 0 );
1295+
1296+ if (c_source_files .language != .find_by_file_extension ) {
1297+ try zig_args .append ("-x" );
1298+ try zig_args .append (switch (c_source_files .language ) {
1299+ .find_by_file_extension = > unreachable ,
1300+ .c = > "c" ,
1301+ .cpp = > "c++" ,
1302+ .assembly = > "assembler" ,
1303+ .assembly_with_cpp = > "assembler-with-cpp" ,
1304+ .objc = > "objective-c" ,
1305+ .objcpp = > "objective-c++" ,
1306+ });
12871307 }
12881308
12891309 const root_path = c_source_files .root .getPath2 (dep .module .owner , step );
12901310 for (c_source_files .files ) | file | {
12911311 try zig_args .append (b .pathJoin (&.{ root_path , file }));
12921312 }
12931313
1314+ if (c_source_files .language != .find_by_file_extension ) {
1315+ try zig_args .append ("-x" );
1316+ try zig_args .append ("none" );
1317+ }
1318+
12941319 total_linker_objects += c_source_files .files .len ;
12951320 },
12961321
0 commit comments