@@ -46,11 +46,39 @@ pub const RPath = union(enum) {
46
46
special : []const u8 ,
47
47
};
48
48
49
+ // subset of Compilation.FileExt
50
+ pub const AsmSourceLang = enum {
51
+ assembly ,
52
+ assembly_with_cpp ,
53
+
54
+ pub fn getName (lang : @This ()) []const u8 {
55
+ return switch (lang ) {
56
+ .assembly = > "assembler" ,
57
+ .assembly_with_cpp = > "assembler-with-cpp" ,
58
+ };
59
+ }
60
+ };
61
+
62
+ pub const AsmSourceFile = struct {
63
+ file : LazyPath ,
64
+ /// if null, deduce the language from the file extension
65
+ lang : ? AsmSourceLang = null ,
66
+ flags : []const []const u8 = &.{},
67
+
68
+ pub fn dupe (file : AsmSourceFile , b : * std.Build ) AsmSourceFile {
69
+ return .{
70
+ .file = file .file .dupe (b ),
71
+ .flags = b .dupeStrings (file .flags ),
72
+ .lang = file .lang ,
73
+ };
74
+ }
75
+ };
76
+
49
77
pub const LinkObject = union (enum ) {
50
78
static_path : LazyPath ,
51
79
other_step : * Step.Compile ,
52
80
system_lib : SystemLib ,
53
- assembly_file : LazyPath ,
81
+ assembly_file : * AsmSourceFile ,
54
82
c_source_file : * CSourceFile ,
55
83
c_source_files : * CSourceFiles ,
56
84
win32_resource_file : * RcSourceFile ,
@@ -78,21 +106,68 @@ pub const SystemLib = struct {
78
106
pub const SearchStrategy = enum { paths_first , mode_first , no_fallback };
79
107
};
80
108
109
+ /// Supported languages for "zig clang -x <lang>".
110
+ // subset of Compilation.FileExt
111
+ pub const CSourceLang = enum {
112
+ /// "c"
113
+ c ,
114
+ /// "c-header"
115
+ h ,
116
+ /// "c++"
117
+ cpp ,
118
+ /// "c++-header"
119
+ hpp ,
120
+ /// "objective-c"
121
+ m ,
122
+ /// "objective-c-header"
123
+ hm ,
124
+ /// "objective-c++"
125
+ mm ,
126
+ /// "objective-c++-header"
127
+ hmm ,
128
+ /// "assembler"
129
+ assembly ,
130
+ /// "assembler-with-cpp"
131
+ assembly_with_cpp ,
132
+ /// "cuda"
133
+ cu ,
134
+
135
+ pub fn getName (lang : @This ()) []const u8 {
136
+ return switch (lang ) {
137
+ .assembly = > "assembler" ,
138
+ .assembly_with_cpp = > "assembler-with-cpp" ,
139
+ .c = > "c" ,
140
+ .cpp = > "c++" ,
141
+ .h = > "c-header" ,
142
+ .hpp = > "c++-header" ,
143
+ .hm = > "objective-c-header" ,
144
+ .hmm = > "objective-c++-header" ,
145
+ .cu = > "cuda" ,
146
+ .m = > "objective-c" ,
147
+ .mm = > "objective-c++" ,
148
+ };
149
+ }
150
+ };
151
+
81
152
pub const CSourceFiles = struct {
82
153
root : LazyPath ,
83
154
/// `files` is relative to `root`, which is
84
155
/// the build root by default
85
156
files : []const []const u8 ,
157
+ /// if null, deduce the language from the file extension
158
+ lang : ? CSourceLang = null ,
86
159
flags : []const []const u8 ,
87
160
};
88
161
89
162
pub const CSourceFile = struct {
90
163
file : LazyPath ,
164
+ lang : ? CSourceLang = null ,
91
165
flags : []const []const u8 = &.{},
92
166
93
167
pub fn dupe (file : CSourceFile , b : * std.Build ) CSourceFile {
94
168
return .{
95
169
.file = file .file .dupe (b ),
170
+ .lang = file .lang ,
96
171
.flags = b .dupeStrings (file .flags ),
97
172
};
98
173
}
@@ -377,6 +452,7 @@ pub const AddCSourceFilesOptions = struct {
377
452
/// package that owns the `Compile` step.
378
453
root : ? LazyPath = null ,
379
454
files : []const []const u8 ,
455
+ lang : ? CSourceLang = null ,
380
456
flags : []const []const u8 = &.{},
381
457
};
382
458
@@ -398,6 +474,7 @@ pub fn addCSourceFiles(m: *Module, options: AddCSourceFilesOptions) void {
398
474
c_source_files .* = .{
399
475
.root = options .root orelse b .path ("" ),
400
476
.files = b .dupeStrings (options .files ),
477
+ .lang = options .lang ,
401
478
.flags = b .dupeStrings (options .flags ),
402
479
};
403
480
m .link_objects .append (allocator , .{ .c_source_files = c_source_files }) catch @panic ("OOM" );
@@ -427,9 +504,11 @@ pub fn addWin32ResourceFile(m: *Module, source: RcSourceFile) void {
427
504
m .link_objects .append (allocator , .{ .win32_resource_file = rc_source_file }) catch @panic ("OOM" );
428
505
}
429
506
430
- pub fn addAssemblyFile (m : * Module , source : LazyPath ) void {
507
+ pub fn addAssemblyFile (m : * Module , source : AsmSourceFile ) void {
431
508
const b = m .owner ;
432
- m .link_objects .append (b .allocator , .{ .assembly_file = source .dupe (b ) }) catch @panic ("OOM" );
509
+ const source_file = b .allocator .create (AsmSourceFile ) catch @panic ("OOM" );
510
+ source_file .* = source .dupe (b );
511
+ m .link_objects .append (b .allocator , .{ .assembly_file = source_file }) catch @panic ("OOM" );
433
512
}
434
513
435
514
pub fn addObjectFile (m : * Module , object : LazyPath ) void {
0 commit comments