diff options
| author | GalaxyShard <76917584+GalaxyShard@users.noreply.github.com> | 2025-01-30 13:04:47 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-01-30 14:04:47 +0100 |
| commit | a3ee5215bba9119d8ab645b0cefee1d026816e13 (patch) | |
| tree | 81a4fae5059f1df3e1bdcf032d2d9a7e79274297 /lib/std/Build/Module.zig | |
| parent | 3348478fc3882fa3627147e54eeafa83ab7f4b09 (diff) | |
| download | zig-a3ee5215bba9119d8ab645b0cefee1d026816e13.tar.gz zig-a3ee5215bba9119d8ab645b0cefee1d026816e13.zip | |
std.Build: Add option to specify language of CSourceFiles
Closes: #20655
Diffstat (limited to 'lib/std/Build/Module.zig')
| -rw-r--r-- | lib/std/Build/Module.zig | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/lib/std/Build/Module.zig b/lib/std/Build/Module.zig index 1f2b4f3fcb..f299946731 100644 --- a/lib/std/Build/Module.zig +++ b/lib/std/Build/Module.zig @@ -78,22 +78,51 @@ pub const SystemLib = struct { pub const SearchStrategy = enum { paths_first, mode_first, no_fallback }; }; +pub const CSourceLanguage = enum { + c, + cpp, + + objective_c, + objective_cpp, + + /// Standard assembly + assembly, + /// Assembly with the C preprocessor + assembly_with_preprocessor, + + pub fn internalIdentifier(self: CSourceLanguage) []const u8 { + return switch (self) { + .c => "c", + .cpp => "c++", + .objective_c => "objective-c", + .objective_cpp => "objective-c++", + .assembly => "assembler", + .assembly_with_preprocessor => "assembler-with-cpp", + }; + } +}; + pub const CSourceFiles = struct { root: LazyPath, /// `files` is relative to `root`, which is /// the build root by default files: []const []const u8, flags: []const []const u8, + /// By default, determines language of each file individually based on its file extension + language: ?CSourceLanguage, }; pub const CSourceFile = struct { file: LazyPath, flags: []const []const u8 = &.{}, + /// By default, determines language of each file individually based on its file extension + language: ?CSourceLanguage = null, pub fn dupe(file: CSourceFile, b: *std.Build) CSourceFile { return .{ .file = file.file.dupe(b), .flags = b.dupeStrings(file.flags), + .language = file.language, }; } }; @@ -378,9 +407,11 @@ pub const AddCSourceFilesOptions = struct { root: ?LazyPath = null, files: []const []const u8, flags: []const []const u8 = &.{}, + /// By default, determines language of each file individually based on its file extension + language: ?CSourceLanguage = null, }; -/// Handy when you have many C/C++ source files and want them all to have the same flags. +/// Handy when you have many non-Zig source files and want them all to have the same flags. pub fn addCSourceFiles(m: *Module, options: AddCSourceFilesOptions) void { const b = m.owner; const allocator = b.allocator; @@ -399,6 +430,7 @@ pub fn addCSourceFiles(m: *Module, options: AddCSourceFilesOptions) void { .root = options.root orelse b.path(""), .files = b.dupeStrings(options.files), .flags = b.dupeStrings(options.flags), + .language = options.language, }; m.link_objects.append(allocator, .{ .c_source_files = c_source_files }) catch @panic("OOM"); } |
