aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2021-06-22 12:47:56 +0200
committerJakub Konka <kubkon@jakubkonka.com>2021-06-24 18:56:56 +0200
commit3f57468c8bd16f33b5ac21cf8eaea2fdb948b999 (patch)
tree05e56ffe8ab7654813388507c9034564d80527b6 /src
parent52a9d3f03797f1cd387ec5f2c2a1714e1121cdab (diff)
downloadzig-3f57468c8bd16f33b5ac21cf8eaea2fdb948b999.tar.gz
zig-3f57468c8bd16f33b5ac21cf8eaea2fdb948b999.zip
Classify .m as ObjC, compile using clang and link with zld
Diffstat (limited to 'src')
-rw-r--r--src/Compilation.zig12
-rw-r--r--src/main.zig5
2 files changed, 13 insertions, 4 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig
index ea878056ae..eea4d930c4 100644
--- a/src/Compilation.zig
+++ b/src/Compilation.zig
@@ -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"));
diff --git a/src/main.zig b/src/main.zig
index f2d00c47bb..1cf62c011b 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -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);
},