@@ -385,6 +385,7 @@ const usage_build_generic =
385
385
\\ -mcmodel=[default|tiny| Limit range of code and data virtual addresses
386
386
\\ small|kernel|
387
387
\\ medium|large]
388
+ \\ -x language Treat subsequent input files as having type <language>
388
389
\\ -mred-zone Force-enable the "red-zone"
389
390
\\ -mno-red-zone Force-disable the "red-zone"
390
391
\\ -fomit-frame-pointer Omit the stack frame pointer
@@ -892,6 +893,7 @@ fn buildOutputType(
892
893
var cssan = ClangSearchSanitizer .init (gpa , & clang_argv );
893
894
defer cssan .map .deinit ();
894
895
896
+ var file_ext : ? Compilation.FileExt = null ;
895
897
args_loop : while (args_iter .next ()) | arg | {
896
898
if (mem .startsWith (u8 , arg , "@" )) {
897
899
// This is a "compiler response file". We must parse the file and treat its
@@ -1372,33 +1374,39 @@ fn buildOutputType(
1372
1374
try clang_argv .append (arg );
1373
1375
} else if (mem .startsWith (u8 , arg , "-I" )) {
1374
1376
try cssan .addIncludePath (.I , arg , arg [2.. ], true );
1377
+ } else if (mem .eql (u8 , arg , "-x" )) {
1378
+ const lang = args_iter .nextOrFatal ();
1379
+ if (mem .eql (u8 , lang , "none" )) {
1380
+ file_ext = null ;
1381
+ } else if (Compilation .LangToExt .get (lang )) | got_ext | {
1382
+ file_ext = got_ext ;
1383
+ } else {
1384
+ fatal ("language not recognized: '{s}'" , .{lang });
1385
+ }
1375
1386
} else if (mem .startsWith (u8 , arg , "-mexec-model=" )) {
1376
1387
wasi_exec_model = std .meta .stringToEnum (std .builtin .WasiExecModel , arg ["-mexec-model=" .len .. ]) orelse {
1377
1388
fatal ("expected [command|reactor] for -mexec-mode=[value], found '{s}'" , .{arg ["-mexec-model=" .len .. ]});
1378
1389
};
1379
1390
} else {
1380
1391
fatal ("unrecognized parameter: '{s}'" , .{arg });
1381
1392
}
1382
- } else switch (Compilation .classifyFileExt (arg )) {
1383
- .object , .static_library , .shared_library = > {
1384
- try link_objects .append (.{ .path = arg });
1385
- },
1386
- .assembly , .c , .cpp , .h , .ll , .bc , .m , .mm , .cu = > {
1393
+ } else switch (file_ext orelse
1394
+ Compilation .classifyFileExt (arg )) {
1395
+ .object , .static_library , .shared_library = > try link_objects .append (.{ .path = arg }),
1396
+ .assembly , .assembly_with_cpp , .c , .cpp , .h , .ll , .bc , .m , .mm , .cu = > {
1387
1397
try c_source_files .append (.{
1388
1398
.src_path = arg ,
1389
1399
.extra_flags = try arena .dupe ([]const u8 , extra_cflags .items ),
1400
+ // duped when parsing the args.
1401
+ .ext = file_ext ,
1390
1402
});
1391
1403
},
1392
1404
.zig = > {
1393
1405
if (root_src_file ) | other | {
1394
1406
fatal ("found another zig file '{s}' after root source file '{s}'" , .{ arg , other });
1395
- } else {
1396
- root_src_file = arg ;
1397
- }
1398
- },
1399
- .unknown = > {
1400
- fatal ("unrecognized file extension of parameter '{s}'" , .{arg });
1407
+ } else root_src_file = arg ;
1401
1408
},
1409
+ .unknown = > fatal ("unrecognized file extension of parameter '{s}'" , .{arg }),
1402
1410
}
1403
1411
}
1404
1412
if (optimize_mode_string ) | s | {
@@ -1435,6 +1443,7 @@ fn buildOutputType(
1435
1443
var needed = false ;
1436
1444
var must_link = false ;
1437
1445
var force_static_libs = false ;
1446
+ var file_ext : ? Compilation.FileExt = null ;
1438
1447
while (it .has_next ) {
1439
1448
it .next () catch | err | {
1440
1449
fatal ("unable to parse command line parameters: {s}" , .{@errorName (err )});
@@ -1455,29 +1464,36 @@ fn buildOutputType(
1455
1464
.asm_only = > c_out_mode = .assembly , // -S
1456
1465
.preprocess_only = > c_out_mode = .preprocessor , // -E
1457
1466
.emit_llvm = > emit_llvm = true ,
1467
+ .x = > {
1468
+ const lang = mem .sliceTo (it .only_arg , 0 );
1469
+ if (mem .eql (u8 , lang , "none" )) {
1470
+ file_ext = null ;
1471
+ } else if (Compilation .LangToExt .get (lang )) | got_ext | {
1472
+ file_ext = got_ext ;
1473
+ } else {
1474
+ fatal ("language not recognized: '{s}'" , .{lang });
1475
+ }
1476
+ },
1458
1477
.other = > {
1459
1478
try clang_argv .appendSlice (it .other_args );
1460
1479
},
1461
- .positional = > {
1462
- const file_ext = Compilation .classifyFileExt (mem .sliceTo (it .only_arg , 0 ));
1463
- switch (file_ext ) {
1464
- .assembly , .c , .cpp , .ll , .bc , .h , .m , .mm , .cu = > {
1465
- try c_source_files .append (.{ .src_path = it .only_arg });
1466
- },
1467
- .unknown , .shared_library , .object , .static_library = > {
1468
- try link_objects .append (.{
1469
- .path = it .only_arg ,
1470
- .must_link = must_link ,
1471
- });
1472
- },
1473
- .zig = > {
1474
- if (root_src_file ) | other | {
1475
- fatal ("found another zig file '{s}' after root source file '{s}'" , .{ it .only_arg , other });
1476
- } else {
1477
- root_src_file = it .only_arg ;
1478
- }
1479
- },
1480
- }
1480
+ .positional = > switch (file_ext orelse
1481
+ Compilation .classifyFileExt (mem .sliceTo (it .only_arg , 0 ))) {
1482
+ .assembly , .assembly_with_cpp , .c , .cpp , .ll , .bc , .h , .m , .mm , .cu = > {
1483
+ try c_source_files .append (.{
1484
+ .src_path = it .only_arg ,
1485
+ .ext = file_ext , // duped while parsing the args.
1486
+ });
1487
+ },
1488
+ .unknown , .shared_library , .object , .static_library = > try link_objects .append (.{
1489
+ .path = it .only_arg ,
1490
+ .must_link = must_link ,
1491
+ }),
1492
+ .zig = > {
1493
+ if (root_src_file ) | other | {
1494
+ fatal ("found another zig file '{s}' after root source file '{s}'" , .{ it .only_arg , other });
1495
+ } else root_src_file = it .only_arg ;
1496
+ },
1481
1497
},
1482
1498
.l = > {
1483
1499
// -l
@@ -4743,6 +4759,7 @@ pub const ClangArgIterator = struct {
4743
4759
o ,
4744
4760
c ,
4745
4761
m ,
4762
+ x ,
4746
4763
other ,
4747
4764
positional ,
4748
4765
l ,
0 commit comments