Classify .m as ObjC, compile using clang and link with zld

This commit is contained in:
Jakub Konka 2021-06-22 12:47:56 +02:00
parent 52a9d3f037
commit 3f57468c8b
2 changed files with 13 additions and 4 deletions

View File

@ -2857,7 +2857,7 @@ pub fn addCCArgs(
try argv.appendSlice(&[_][]const u8{ "-target", llvm_triple });
switch (ext) {
.c, .cpp, .h => {
.c, .cpp, .m, .h => {
try argv.appendSlice(&[_][]const u8{
"-nostdinc",
"-fno-spell-checking",
@ -3148,6 +3148,7 @@ pub const FileExt = enum {
c,
cpp,
h,
m,
ll,
bc,
assembly,
@ -3159,7 +3160,7 @@ pub const FileExt = enum {
pub fn clangSupportsDepFile(ext: FileExt) bool {
return switch (ext) {
.c, .cpp, .h => true,
.c, .cpp, .h, .m => true,
.ll,
.bc,
@ -3193,6 +3194,10 @@ pub fn hasCppExt(filename: []const u8) bool {
mem.endsWith(u8, filename, ".cxx");
}
pub fn hasObjCExt(filename: []const u8) bool {
return mem.endsWith(u8, filename, ".m");
}
pub fn hasAsmExt(filename: []const u8) bool {
return mem.endsWith(u8, filename, ".s") or mem.endsWith(u8, filename, ".S");
}
@ -3229,6 +3234,8 @@ pub fn classifyFileExt(filename: []const u8) FileExt {
return .c;
} else if (hasCppExt(filename)) {
return .cpp;
} else if (hasObjCExt(filename)) {
return .m;
} else if (mem.endsWith(u8, filename, ".ll")) {
return .ll;
} else if (mem.endsWith(u8, filename, ".bc")) {
@ -3252,6 +3259,7 @@ pub fn classifyFileExt(filename: []const u8) FileExt {
test "classifyFileExt" {
try std.testing.expectEqual(FileExt.cpp, classifyFileExt("foo.cc"));
try std.testing.expectEqual(FileExt.m, classifyFileExt("foo.m"));
try std.testing.expectEqual(FileExt.unknown, classifyFileExt("foo.nim"));
try std.testing.expectEqual(FileExt.shared_library, classifyFileExt("foo.so"));
try std.testing.expectEqual(FileExt.shared_library, classifyFileExt("foo.so.1"));

View File

@ -290,6 +290,7 @@ const usage_build_generic =
\\ .c C source code (requires LLVM extensions)
\\ .cpp C++ source code (requires LLVM extensions)
\\ Other C++ extensions: .C .cc .cxx
\\ .m Objective-C source code (requires LLVM extensions)
\\
\\General Options:
\\ -h, --help Print this help and exit
@ -1072,7 +1073,7 @@ fn buildOutputType(
.object, .static_library, .shared_library => {
try link_objects.append(arg);
},
.assembly, .c, .cpp, .h, .ll, .bc => {
.assembly, .c, .cpp, .h, .ll, .bc, .m => {
try c_source_files.append(.{
.src_path = arg,
.extra_flags = try arena.dupe([]const u8, extra_cflags.items),
@ -1135,7 +1136,7 @@ fn buildOutputType(
.positional => {
const file_ext = Compilation.classifyFileExt(mem.spanZ(it.only_arg));
switch (file_ext) {
.assembly, .c, .cpp, .ll, .bc, .h => try c_source_files.append(.{ .src_path = it.only_arg }),
.assembly, .c, .cpp, .ll, .bc, .h, .m => try c_source_files.append(.{ .src_path = it.only_arg }),
.unknown, .shared_library, .object, .static_library => {
try link_objects.append(it.only_arg);
},