aboutsummaryrefslogtreecommitdiff
path: root/src/Compilation.zig
diff options
context:
space:
mode:
authorAlex Rønne Petersen <alex@alexrp.com>2024-12-13 04:56:35 +0100
committerAlex Rønne Petersen <alex@alexrp.com>2024-12-13 06:48:32 +0100
commit88f324ebe7a7fe088903ebaeb0c49f31c10ae9a6 (patch)
tree76bbc436f7a23dad393c2567808ae19fb5c8bada /src/Compilation.zig
parentb6ece854c93e3ff6d6f20cd31133174b34b02fb0 (diff)
downloadzig-88f324ebe7a7fe088903ebaeb0c49f31c10ae9a6.tar.gz
zig-88f324ebe7a7fe088903ebaeb0c49f31c10ae9a6.zip
Compilation: Override Clang's language type for header files.
Clang seems to treat them as linker input without this.
Diffstat (limited to 'src/Compilation.zig')
-rw-r--r--src/Compilation.zig38
1 files changed, 34 insertions, 4 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig
index 6f0952b9bf..ffbf5dd487 100644
--- a/src/Compilation.zig
+++ b/src/Compilation.zig
@@ -4687,19 +4687,19 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: std.Pr
try argv.appendSlice(&[_][]const u8{ self_exe_path, "clang" });
// if "ext" is explicit, add "-x <lang>". Otherwise let clang do its thing.
- if (c_object.src.ext != null) {
+ if (c_object.src.ext != null or ext.clangNeedsLanguageOverride()) {
try argv.appendSlice(&[_][]const u8{ "-x", switch (ext) {
.assembly => "assembler",
.assembly_with_cpp => "assembler-with-cpp",
.c => "c",
- .cpp => "c++",
.h => "c-header",
+ .cpp => "c++",
.hpp => "c++-header",
+ .m => "objective-c",
.hm => "objective-c-header",
+ .mm => "objective-c++",
.hmm => "objective-c++-header",
.cu => "cuda",
- .m => "objective-c",
- .mm => "objective-c++",
else => fatal("language '{s}' is unsupported in this context", .{@tagName(ext)}),
} });
}
@@ -5840,6 +5840,36 @@ pub const FileExt = enum {
manifest,
unknown,
+ pub fn clangNeedsLanguageOverride(ext: FileExt) bool {
+ return switch (ext) {
+ .h,
+ .hpp,
+ .hm,
+ .hmm,
+ => true,
+
+ .c,
+ .cpp,
+ .cu,
+ .m,
+ .mm,
+ .ll,
+ .bc,
+ .assembly,
+ .assembly_with_cpp,
+ .shared_library,
+ .object,
+ .static_library,
+ .zig,
+ .def,
+ .rc,
+ .res,
+ .manifest,
+ .unknown,
+ => false,
+ };
+ }
+
pub fn clangSupportsDiagnostics(ext: FileExt) bool {
return switch (ext) {
.c, .cpp, .h, .hpp, .hm, .hmm, .m, .mm, .cu, .ll, .bc => true,