@@ -46,11 +46,36 @@ 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 getLangName (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
+ lang : ? AsmSourceLang = null ,
65
+
66
+ pub fn dupe (file : AsmSourceFile , b : * std.Build ) AsmSourceFile {
67
+ return .{
68
+ .file = file .file .dupe (b ),
69
+ .lang = file .lang ,
70
+ };
71
+ }
72
+ };
73
+
49
74
pub const LinkObject = union (enum ) {
50
75
static_path : LazyPath ,
51
76
other_step : * Step.Compile ,
52
77
system_lib : SystemLib ,
53
- assembly_file : LazyPath ,
78
+ assembly_file : * AsmSourceFile ,
54
79
c_source_file : * CSourceFile ,
55
80
c_source_files : * CSourceFiles ,
56
81
win32_resource_file : * RcSourceFile ,
@@ -78,21 +103,67 @@ pub const SystemLib = struct {
78
103
pub const SearchStrategy = enum { paths_first , mode_first , no_fallback };
79
104
};
80
105
106
+ /// Supported languages for "zig clang -x <lang>".
107
+ // subset of Compilation.FileExt
108
+ pub const CSourceLang = enum {
109
+ /// "c"
110
+ c ,
111
+ /// "c-header"
112
+ h ,
113
+ /// "c++"
114
+ cpp ,
115
+ /// "c++-header"
116
+ hpp ,
117
+ /// "objective-c"
118
+ m ,
119
+ /// "objective-c-header"
120
+ hm ,
121
+ /// "objective-c++"
122
+ mm ,
123
+ /// "objective-c++-header"
124
+ hmm ,
125
+ /// "assembler"
126
+ assembly ,
127
+ /// "assembler-with-cpp"
128
+ assembly_with_cpp ,
129
+ /// "cuda"
130
+ cu ,
131
+
132
+ pub fn getLangName (lang : @This ()) []const u8 {
133
+ return switch (lang ) {
134
+ .assembly = > "assembler" ,
135
+ .assembly_with_cpp = > "assembler-with-cpp" ,
136
+ .c = > "c" ,
137
+ .cpp = > "c++" ,
138
+ .h = > "c-header" ,
139
+ .hpp = > "c++-header" ,
140
+ .hm = > "objective-c-header" ,
141
+ .hmm = > "objective-c++-header" ,
142
+ .cu = > "cuda" ,
143
+ .m = > "objective-c" ,
144
+ .mm = > "objective-c++" ,
145
+ };
146
+ }
147
+ };
148
+
81
149
pub const CSourceFiles = struct {
82
150
root : LazyPath ,
83
151
/// `files` is relative to `root`, which is
84
152
/// the build root by default
85
153
files : []const []const u8 ,
154
+ lang : ? CSourceLang = null ,
86
155
flags : []const []const u8 ,
87
156
};
88
157
89
158
pub const CSourceFile = struct {
90
159
file : LazyPath ,
160
+ lang : ? CSourceLang = null ,
91
161
flags : []const []const u8 = &.{},
92
162
93
163
pub fn dupe (file : CSourceFile , b : * std.Build ) CSourceFile {
94
164
return .{
95
165
.file = file .file .dupe (b ),
166
+ .lang = file .lang ,
96
167
.flags = b .dupeStrings (file .flags ),
97
168
};
98
169
}
@@ -286,10 +357,9 @@ fn addShallowDependencies(m: *Module, dependee: *Module) void {
286
357
addLazyPathDependenciesOnly (m , compile .getEmittedIncludeTree ());
287
358
},
288
359
289
- .static_path ,
290
- .assembly_file ,
291
- = > | lp | addLazyPathDependencies (m , dependee , lp ),
360
+ .static_path = > | lp | addLazyPathDependencies (m , dependee , lp ),
292
361
362
+ .assembly_file = > | x | addLazyPathDependencies (m , dependee , x .file ),
293
363
.c_source_file = > | x | addLazyPathDependencies (m , dependee , x .file ),
294
364
.win32_resource_file = > | x | addLazyPathDependencies (m , dependee , x .file ),
295
365
@@ -485,6 +555,7 @@ pub const AddCSourceFilesOptions = struct {
485
555
/// package that owns the `Compile` step.
486
556
root : ? LazyPath = null ,
487
557
files : []const []const u8 ,
558
+ lang : ? CSourceLang = null ,
488
559
flags : []const []const u8 = &.{},
489
560
};
490
561
@@ -506,6 +577,7 @@ pub fn addCSourceFiles(m: *Module, options: AddCSourceFilesOptions) void {
506
577
c_source_files .* = .{
507
578
.root = options .root orelse b .path ("" ),
508
579
.files = b .dupeStrings (options .files ),
580
+ .lang = options .lang ,
509
581
.flags = b .dupeStrings (options .flags ),
510
582
};
511
583
m .link_objects .append (allocator , .{ .c_source_files = c_source_files }) catch @panic ("OOM" );
@@ -541,10 +613,12 @@ pub fn addWin32ResourceFile(m: *Module, source: RcSourceFile) void {
541
613
}
542
614
}
543
615
544
- pub fn addAssemblyFile (m : * Module , source : LazyPath ) void {
616
+ pub fn addAssemblyFile (m : * Module , source : AsmSourceFile ) void {
545
617
const b = m .owner ;
546
- m .link_objects .append (b .allocator , .{ .assembly_file = source .dupe (b ) }) catch @panic ("OOM" );
547
- addLazyPathDependenciesOnly (m , source );
618
+ const source_file = b .allocator .create (AsmSourceFile ) catch @panic ("OOM" );
619
+ source_file .* = source .dupe (b );
620
+ m .link_objects .append (b .allocator , .{ .assembly_file = source_file }) catch @panic ("OOM" );
621
+ addLazyPathDependenciesOnly (m , source .file );
548
622
}
549
623
550
624
pub fn addObjectFile (m : * Module , object : LazyPath ) void {
0 commit comments