@@ -50,8 +50,8 @@ pub const LinkObject = union(enum) {
50
50
other_step : * Step.Compile ,
51
51
system_lib : SystemLib ,
52
52
assembly_file : LazyPath ,
53
- c_source_file : * CSourceFile ,
54
- c_source_files : * CSourceFiles ,
53
+ foreign_source_file : * ForeignSourceFile ,
54
+ foreign_source_files : * ForeignSourceFiles ,
55
55
win32_resource_file : * RcSourceFile ,
56
56
};
57
57
@@ -77,22 +77,49 @@ pub const SystemLib = struct {
77
77
pub const SearchStrategy = enum { paths_first , mode_first , no_fallback };
78
78
};
79
79
80
- pub const CSourceFiles = struct {
80
+ pub const ForeignSourceLanguage = enum {
81
+ c ,
82
+ cpp ,
83
+ assembly ,
84
+ assembly_with_cpp ,
85
+ objc ,
86
+ objcpp ,
87
+
88
+ find_by_file_extension ,
89
+ };
90
+
91
+ pub const ForeignSourceFiles = struct {
81
92
root : LazyPath ,
82
93
/// `files` is relative to `root`, which is
83
94
/// the build root by default
84
95
files : []const []const u8 ,
85
96
flags : []const []const u8 ,
97
+ language : ForeignSourceLanguage ,
86
98
};
87
99
100
+ pub const ForeignSourceFile = struct {
101
+ file : LazyPath ,
102
+ flags : []const []const u8 = &.{},
103
+ language : ForeignSourceLanguage ,
104
+
105
+ pub fn dupe (file : ForeignSourceFile , b : * std.Build ) ForeignSourceFile {
106
+ return .{
107
+ .file = file .file .dupe (b ),
108
+ .flags = b .dupeStrings (file .flags ),
109
+ .language = file .language ,
110
+ };
111
+ }
112
+ };
88
113
pub const CSourceFile = struct {
89
114
file : LazyPath ,
90
115
flags : []const []const u8 = &.{},
116
+ language : ForeignSourceLanguage = .find_by_file_extension ,
91
117
92
118
pub fn dupe (file : CSourceFile , b : * std.Build ) CSourceFile {
93
119
return .{
94
120
.file = file .file .dupe (b ),
95
121
.flags = b .dupeStrings (file .flags ),
122
+ .language = file .language ,
96
123
};
97
124
}
98
125
};
@@ -287,10 +314,10 @@ fn addShallowDependencies(m: *Module, dependee: *Module) void {
287
314
.assembly_file ,
288
315
= > | lp | addLazyPathDependencies (m , dependee , lp ),
289
316
290
- .c_source_file = > | x | addLazyPathDependencies (m , dependee , x .file ),
317
+ .foreign_source_file = > | x | addLazyPathDependencies (m , dependee , x .file ),
291
318
.win32_resource_file = > | x | addLazyPathDependencies (m , dependee , x .file ),
292
319
293
- .c_source_files ,
320
+ .foreign_source_files ,
294
321
.system_lib ,
295
322
= > {},
296
323
};
@@ -477,47 +504,75 @@ pub fn linkFramework(m: *Module, name: []const u8, options: LinkFrameworkOptions
477
504
m .frameworks .put (b .allocator , b .dupe (name ), options ) catch @panic ("OOM" );
478
505
}
479
506
507
+ pub const AddForeignSourceFilesOptions = struct {
508
+ /// When provided, `files` are relative to `root` rather than the
509
+ /// package that owns the `Compile` step.
510
+ root : ? LazyPath = null ,
511
+ files : []const []const u8 ,
512
+ flags : []const []const u8 = &.{},
513
+ language : ForeignSourceLanguage ,
514
+ };
480
515
pub const AddCSourceFilesOptions = struct {
481
516
/// When provided, `files` are relative to `root` rather than the
482
517
/// package that owns the `Compile` step.
483
518
root : ? LazyPath = null ,
484
519
files : []const []const u8 ,
485
520
flags : []const []const u8 = &.{},
521
+ language : ForeignSourceLanguage = .find_by_file_extension ,
486
522
};
487
523
488
- /// Handy when you have many C/C++ source files and want them all to have the same flags.
489
- pub fn addCSourceFiles (m : * Module , options : AddCSourceFilesOptions ) void {
524
+ /// Handy when you have many non-Zig source files and want them all to have the same flags.
525
+ pub fn addForeignSourceFiles (m : * Module , options : AddForeignSourceFilesOptions ) void {
490
526
const b = m .owner ;
491
527
const allocator = b .allocator ;
492
528
493
529
for (options .files ) | path | {
494
530
if (std .fs .path .isAbsolute (path )) {
495
531
std .debug .panic (
496
- "file paths added with 'addCSourceFiles ' must be relative, found absolute path '{s}'" ,
532
+ "file paths added with 'addForeignSourceFiles ' must be relative, found absolute path '{s}'" ,
497
533
.{path },
498
534
);
499
535
}
500
536
}
501
537
502
- const c_source_files = allocator .create (CSourceFiles ) catch @panic ("OOM" );
503
- c_source_files .* = .{
538
+ const source_files = allocator .create (ForeignSourceFiles ) catch @panic ("OOM" );
539
+ source_files .* = .{
504
540
.root = options .root orelse b .path ("" ),
505
541
.files = b .dupeStrings (options .files ),
506
542
.flags = b .dupeStrings (options .flags ),
543
+ .language = options .language ,
507
544
};
508
- m .link_objects .append (allocator , .{ .c_source_files = c_source_files }) catch @panic ("OOM" );
509
- addLazyPathDependenciesOnly (m , c_source_files .root );
545
+ m .link_objects .append (allocator , .{ .foreign_source_files = source_files }) catch @panic ("OOM" );
546
+ addLazyPathDependenciesOnly (m , source_files .root );
510
547
}
511
548
512
- pub fn addCSourceFile (m : * Module , source : CSourceFile ) void {
549
+ /// Handy when you have many C/C++ source files and want them all to have the same flags.
550
+ pub fn addCSourceFiles (m : * Module , options : AddCSourceFilesOptions ) void {
551
+ addForeignSourceFiles (m , .{
552
+ .root = options .root ,
553
+ .files = options .files ,
554
+ .flags = options .flags ,
555
+ .language = options .language ,
556
+ });
557
+ }
558
+
559
+ pub fn addForeignSourceFile (m : * Module , source : ForeignSourceFile ) void {
513
560
const b = m .owner ;
514
561
const allocator = b .allocator ;
515
- const c_source_file = allocator .create (CSourceFile ) catch @panic ("OOM" );
516
- c_source_file .* = source .dupe (b );
517
- m .link_objects .append (allocator , .{ .c_source_file = c_source_file }) catch @panic ("OOM" );
562
+ const source_file = allocator .create (ForeignSourceFile ) catch @panic ("OOM" );
563
+ source_file .* = source .dupe (b );
564
+ m .link_objects .append (allocator , .{ .foreign_source_file = source_file }) catch @panic ("OOM" );
518
565
addLazyPathDependenciesOnly (m , source .file );
519
566
}
520
567
568
+ pub fn addCSourceFile (m : * Module , source : CSourceFile ) void {
569
+ addForeignSourceFile (m , .{
570
+ .file = source .file ,
571
+ .flags = source .flags ,
572
+ .language = source .language ,
573
+ });
574
+ }
575
+
521
576
/// Resource files must have the extension `.rc`.
522
577
/// Can be called regardless of target. The .rc file will be ignored
523
578
/// if the target object format does not support embedded resources.
0 commit comments