@@ -391,6 +391,7 @@ const usage_build_generic =
391
391
\\ -mcmodel=[default|tiny| Limit range of code and data virtual addresses
392
392
\\ small|kernel|
393
393
\\ medium|large]
394
+ \\ -x language Treat subsequent input files as having type <language>
394
395
\\ -mred-zone Force-enable the "red-zone"
395
396
\\ -mno-red-zone Force-disable the "red-zone"
396
397
\\ -fomit-frame-pointer Omit the stack frame pointer
@@ -913,6 +914,7 @@ fn buildOutputType(
913
914
var cssan = ClangSearchSanitizer .init (gpa , & clang_argv );
914
915
defer cssan .map .deinit ();
915
916
917
+ var file_ext : ? Compilation.FileExt = null ;
916
918
args_loop : while (args_iter .next ()) | arg | {
917
919
if (mem .startsWith (u8 , arg , "@" )) {
918
920
// This is a "compiler response file". We must parse the file and treat its
@@ -1401,29 +1403,37 @@ fn buildOutputType(
1401
1403
try clang_argv .append (arg );
1402
1404
} else if (mem .startsWith (u8 , arg , "-I" )) {
1403
1405
try cssan .addIncludePath (.I , arg , arg [2.. ], true );
1406
+ } else if (mem .eql (u8 , arg , "-x" )) {
1407
+ const lang = args_iter .nextOrFatal ();
1408
+ if (mem .eql (u8 , lang , "none" )) {
1409
+ file_ext = null ;
1410
+ } else if (Compilation .LangToExt .get (lang )) | got_ext | {
1411
+ file_ext = got_ext ;
1412
+ } else {
1413
+ fatal ("language not recognized: '{s}'" , .{lang });
1414
+ }
1404
1415
} else if (mem .startsWith (u8 , arg , "-mexec-model=" )) {
1405
1416
wasi_exec_model = std .meta .stringToEnum (std .builtin .WasiExecModel , arg ["-mexec-model=" .len .. ]) orelse {
1406
1417
fatal ("expected [command|reactor] for -mexec-mode=[value], found '{s}'" , .{arg ["-mexec-model=" .len .. ]});
1407
1418
};
1408
1419
} else {
1409
1420
fatal ("unrecognized parameter: '{s}'" , .{arg });
1410
1421
}
1411
- } else switch (Compilation .classifyFileExt (arg )) {
1412
- .object , .static_library , .shared_library = > {
1413
- try link_objects .append (.{ .path = arg });
1414
- },
1415
- .assembly , .c , .cpp , .h , .ll , .bc , .m , .mm , .cu = > {
1422
+ } else switch (file_ext orelse
1423
+ Compilation .classifyFileExt (arg )) {
1424
+ .object , .static_library , .shared_library = > try link_objects .append (.{ .path = arg }),
1425
+ .assembly , .assembly_with_cpp , .c , .cpp , .h , .ll , .bc , .m , .mm , .cu = > {
1416
1426
try c_source_files .append (.{
1417
1427
.src_path = arg ,
1418
1428
.extra_flags = try arena .dupe ([]const u8 , extra_cflags .items ),
1429
+ // duped when parsing the args.
1430
+ .ext = file_ext ,
1419
1431
});
1420
1432
},
1421
1433
.zig = > {
1422
1434
if (root_src_file ) | other | {
1423
1435
fatal ("found another zig file '{s}' after root source file '{s}'" , .{ arg , other });
1424
- } else {
1425
- root_src_file = arg ;
1426
- }
1436
+ } else root_src_file = arg ;
1427
1437
},
1428
1438
.def , .unknown = > {
1429
1439
fatal ("unrecognized file extension of parameter '{s}'" , .{arg });
@@ -1464,6 +1474,7 @@ fn buildOutputType(
1464
1474
var needed = false ;
1465
1475
var must_link = false ;
1466
1476
var force_static_libs = false ;
1477
+ var file_ext : ? Compilation.FileExt = null ;
1467
1478
while (it .has_next ) {
1468
1479
it .next () catch | err | {
1469
1480
fatal ("unable to parse command line parameters: {s}" , .{@errorName (err )});
@@ -1484,32 +1495,39 @@ fn buildOutputType(
1484
1495
.asm_only = > c_out_mode = .assembly , // -S
1485
1496
.preprocess_only = > c_out_mode = .preprocessor , // -E
1486
1497
.emit_llvm = > emit_llvm = true ,
1498
+ .x = > {
1499
+ const lang = mem .sliceTo (it .only_arg , 0 );
1500
+ if (mem .eql (u8 , lang , "none" )) {
1501
+ file_ext = null ;
1502
+ } else if (Compilation .LangToExt .get (lang )) | got_ext | {
1503
+ file_ext = got_ext ;
1504
+ } else {
1505
+ fatal ("language not recognized: '{s}'" , .{lang });
1506
+ }
1507
+ },
1487
1508
.other = > {
1488
1509
try clang_argv .appendSlice (it .other_args );
1489
1510
},
1490
- .positional = > {
1491
- const file_ext = Compilation .classifyFileExt (mem .sliceTo (it .only_arg , 0 ));
1492
- switch (file_ext ) {
1493
- .assembly , .c , .cpp , .ll , .bc , .h , .m , .mm , .cu = > {
1494
- try c_source_files .append (.{ .src_path = it .only_arg });
1495
- },
1496
- .unknown , .shared_library , .object , .static_library = > {
1497
- try link_objects .append (.{
1498
- .path = it .only_arg ,
1499
- .must_link = must_link ,
1500
- });
1501
- },
1502
- .def = > {
1503
- linker_module_definition_file = it .only_arg ;
1504
- },
1505
- .zig = > {
1506
- if (root_src_file ) | other | {
1507
- fatal ("found another zig file '{s}' after root source file '{s}'" , .{ it .only_arg , other });
1508
- } else {
1509
- root_src_file = it .only_arg ;
1510
- }
1511
- },
1512
- }
1511
+ .positional = > switch (file_ext orelse
1512
+ Compilation .classifyFileExt (mem .sliceTo (it .only_arg , 0 ))) {
1513
+ .assembly , .assembly_with_cpp , .c , .cpp , .ll , .bc , .h , .m , .mm , .cu = > {
1514
+ try c_source_files .append (.{
1515
+ .src_path = it .only_arg ,
1516
+ .ext = file_ext , // duped while parsing the args.
1517
+ });
1518
+ },
1519
+ .unknown , .shared_library , .object , .static_library = > try link_objects .append (.{
1520
+ .path = it .only_arg ,
1521
+ .must_link = must_link ,
1522
+ }),
1523
+ .def = > {
1524
+ linker_module_definition_file = it .only_arg ;
1525
+ },
1526
+ .zig = > {
1527
+ if (root_src_file ) | other | {
1528
+ fatal ("found another zig file '{s}' after root source file '{s}'" , .{ it .only_arg , other });
1529
+ } else root_src_file = it .only_arg ;
1530
+ },
1513
1531
},
1514
1532
.l = > {
1515
1533
// -l
@@ -4860,6 +4878,7 @@ pub const ClangArgIterator = struct {
4860
4878
o ,
4861
4879
c ,
4862
4880
m ,
4881
+ x ,
4863
4882
other ,
4864
4883
positional ,
4865
4884
l ,
0 commit comments