@@ -78,21 +78,67 @@ pub const SystemLib = struct {
78
78
pub const SearchStrategy = enum { paths_first , mode_first , no_fallback };
79
79
};
80
80
81
+ /// Supported languages for "zig clang -x <lang>".
82
+ pub const CSourceLang = enum {
83
+ /// "c"
84
+ c ,
85
+ /// "c-header"
86
+ h ,
87
+ /// "c++"
88
+ cpp ,
89
+ /// "c++-header"
90
+ hpp ,
91
+ /// "objective-c"
92
+ m ,
93
+ /// "objective-c-header"
94
+ hm ,
95
+ /// "objective-c++"
96
+ mm ,
97
+ /// "objective-c++-header"
98
+ hmm ,
99
+ /// "assembler"
100
+ assembly ,
101
+ /// "assembler-with-cpp"
102
+ assembly_with_cpp ,
103
+ /// "cuda"
104
+ cu ,
105
+
106
+ pub fn getLangName (lang : @This ()) []const u8 {
107
+ return switch (lang ) {
108
+ .assembly = > "assembler" ,
109
+ .assembly_with_cpp = > "assembler-with-cpp" ,
110
+ .c = > "c" ,
111
+ .cpp = > "c++" ,
112
+ .h = > "c-header" ,
113
+ .hpp = > "c++-header" ,
114
+ .hm = > "objective-c-header" ,
115
+ .hmm = > "objective-c++-header" ,
116
+ .cu = > "cuda" ,
117
+ .m = > "objective-c" ,
118
+ .mm = > "objective-c++" ,
119
+ };
120
+ }
121
+ };
122
+
81
123
pub const CSourceFiles = struct {
82
124
dependency : ? * std.Build.Dependency ,
83
125
/// If `dependency` is not null relative to it,
84
126
/// else relative to the build root.
85
127
files : []const []const u8 ,
128
+ lang : ? CSourceLang = null ,
86
129
flags : []const []const u8 ,
87
130
};
88
131
89
132
pub const CSourceFile = struct {
90
133
file : LazyPath ,
134
+ /// `lang` optionally overrides the language detection.
135
+ lang : ? CSourceLang = null ,
91
136
flags : []const []const u8 = &.{},
92
137
93
138
pub fn dupe (self : CSourceFile , b : * std.Build ) CSourceFile {
94
139
return .{
95
140
.file = self .file .dupe (b ),
141
+ .lang = self .lang ,
96
142
.flags = b .dupeStrings (self .flags ),
97
143
};
98
144
}
@@ -457,6 +503,7 @@ pub const AddCSourceFilesOptions = struct {
457
503
/// package that owns the `Compile` step.
458
504
dependency : ? * std.Build.Dependency = null ,
459
505
files : []const []const u8 ,
506
+ lang : ? CSourceLang = null ,
460
507
flags : []const []const u8 = &.{},
461
508
};
462
509
@@ -468,6 +515,7 @@ pub fn addCSourceFiles(m: *Module, options: AddCSourceFilesOptions) void {
468
515
c_source_files .* = .{
469
516
.dependency = options .dependency ,
470
517
.files = b .dupeStrings (options .files ),
518
+ .lang = options .lang ,
471
519
.flags = b .dupeStrings (options .flags ),
472
520
};
473
521
m .link_objects .append (allocator , .{ .c_source_files = c_source_files }) catch @panic ("OOM" );
0 commit comments