authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-06-22 12:47:56+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-06-24 18:56:56+02:00
log3f57468c8bd16f33b5ac21cf8eaea2fdb948b999
tree05e56ffe8ab7654813388507c9034564d80527b6
parent52a9d3f03797f1cd387ec5f2c2a1714e1121cdab

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


2 files changed, 13 insertions(+), 4 deletions(-)

src/Compilation.zig+10-2
......@@ -2857,7 +2857,7 @@ pub fn addCCArgs(
28572857 try argv.appendSlice(&[_][]const u8{ "-target", llvm_triple });
28582858
28592859 switch (ext) {
2860 .c, .cpp, .h => {
2860 .c, .cpp, .m, .h => {
28612861 try argv.appendSlice(&[_][]const u8{
28622862 "-nostdinc",
28632863 "-fno-spell-checking",
......@@ -3148,6 +3148,7 @@ pub const FileExt = enum {
31483148 c,
31493149 cpp,
31503150 h,
3151 m,
31513152 ll,
31523153 bc,
31533154 assembly,
......@@ -3159,7 +3160,7 @@ pub const FileExt = enum {
31593160
31603161 pub fn clangSupportsDepFile(ext: FileExt) bool {
31613162 return switch (ext) {
3162 .c, .cpp, .h => true,
3163 .c, .cpp, .h, .m => true,
31633164
31643165 .ll,
31653166 .bc,
......@@ -3193,6 +3194,10 @@ pub fn hasCppExt(filename: []const u8) bool {
31933194 mem.endsWith(u8, filename, ".cxx");
31943195}
31953196
3197pub fn hasObjCExt(filename: []const u8) bool {
3198 return mem.endsWith(u8, filename, ".m");
3199}
3200
31963201pub fn hasAsmExt(filename: []const u8) bool {
31973202 return mem.endsWith(u8, filename, ".s") or mem.endsWith(u8, filename, ".S");
31983203}
......@@ -3229,6 +3234,8 @@ pub fn classifyFileExt(filename: []const u8) FileExt {
32293234 return .c;
32303235 } else if (hasCppExt(filename)) {
32313236 return .cpp;
3237 } else if (hasObjCExt(filename)) {
3238 return .m;
32323239 } else if (mem.endsWith(u8, filename, ".ll")) {
32333240 return .ll;
32343241 } else if (mem.endsWith(u8, filename, ".bc")) {
......@@ -3252,6 +3259,7 @@ pub fn classifyFileExt(filename: []const u8) FileExt {
32523259
32533260test "classifyFileExt" {
32543261 try std.testing.expectEqual(FileExt.cpp, classifyFileExt("foo.cc"));
3262 try std.testing.expectEqual(FileExt.m, classifyFileExt("foo.m"));
32553263 try std.testing.expectEqual(FileExt.unknown, classifyFileExt("foo.nim"));
32563264 try std.testing.expectEqual(FileExt.shared_library, classifyFileExt("foo.so"));
32573265 try std.testing.expectEqual(FileExt.shared_library, classifyFileExt("foo.so.1"));
src/main.zig+3-2
......@@ -290,6 +290,7 @@ const usage_build_generic =
290290 \\ .c C source code (requires LLVM extensions)
291291 \\ .cpp C++ source code (requires LLVM extensions)
292292 \\ Other C++ extensions: .C .cc .cxx
293 \\ .m Objective-C source code (requires LLVM extensions)
293294 \\
294295 \\General Options:
295296 \\ -h, --help Print this help and exit
......@@ -1072,7 +1073,7 @@ fn buildOutputType(
10721073 .object, .static_library, .shared_library => {
10731074 try link_objects.append(arg);
10741075 },
1075 .assembly, .c, .cpp, .h, .ll, .bc => {
1076 .assembly, .c, .cpp, .h, .ll, .bc, .m => {
10761077 try c_source_files.append(.{
10771078 .src_path = arg,
10781079 .extra_flags = try arena.dupe([]const u8, extra_cflags.items),
......@@ -1135,7 +1136,7 @@ fn buildOutputType(
11351136 .positional => {
11361137 const file_ext = Compilation.classifyFileExt(mem.spanZ(it.only_arg));
11371138 switch (file_ext) {
1138 .assembly, .c, .cpp, .ll, .bc, .h => try c_source_files.append(.{ .src_path = it.only_arg }),
1139 .assembly, .c, .cpp, .ll, .bc, .h, .m => try c_source_files.append(.{ .src_path = it.only_arg }),
11391140 .unknown, .shared_library, .object, .static_library => {
11401141 try link_objects.append(it.only_arg);
11411142 },