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(...@@ -2857,7 +2857,7 @@ pub fn addCCArgs(
2857 try argv.appendSlice(&[_][]const u8{ "-target", llvm_triple });2857 try argv.appendSlice(&[_][]const u8{ "-target", llvm_triple });
28582858
2859 switch (ext) {2859 switch (ext) {
2860 .c, .cpp, .h => {2860 .c, .cpp, .m, .h => {
2861 try argv.appendSlice(&[_][]const u8{2861 try argv.appendSlice(&[_][]const u8{
2862 "-nostdinc",2862 "-nostdinc",
2863 "-fno-spell-checking",2863 "-fno-spell-checking",
...@@ -3148,6 +3148,7 @@ pub const FileExt = enum {...@@ -3148,6 +3148,7 @@ pub const FileExt = enum {
3148 c,3148 c,
3149 cpp,3149 cpp,
3150 h,3150 h,
3151 m,
3151 ll,3152 ll,
3152 bc,3153 bc,
3153 assembly,3154 assembly,
...@@ -3159,7 +3160,7 @@ pub const FileExt = enum {...@@ -3159,7 +3160,7 @@ pub const FileExt = enum {
31593160
3160 pub fn clangSupportsDepFile(ext: FileExt) bool {3161 pub fn clangSupportsDepFile(ext: FileExt) bool {
3161 return switch (ext) {3162 return switch (ext) {
3162 .c, .cpp, .h => true,3163 .c, .cpp, .h, .m => true,
31633164
3164 .ll,3165 .ll,
3165 .bc,3166 .bc,
...@@ -3193,6 +3194,10 @@ pub fn hasCppExt(filename: []const u8) bool {...@@ -3193,6 +3194,10 @@ pub fn hasCppExt(filename: []const u8) bool {
3193 mem.endsWith(u8, filename, ".cxx");3194 mem.endsWith(u8, filename, ".cxx");
3194}3195}
31953196
3197pub fn hasObjCExt(filename: []const u8) bool {
3198 return mem.endsWith(u8, filename, ".m");
3199}
3200
3196pub fn hasAsmExt(filename: []const u8) bool {3201pub fn hasAsmExt(filename: []const u8) bool {
3197 return mem.endsWith(u8, filename, ".s") or mem.endsWith(u8, filename, ".S");3202 return mem.endsWith(u8, filename, ".s") or mem.endsWith(u8, filename, ".S");
3198}3203}
...@@ -3229,6 +3234,8 @@ pub fn classifyFileExt(filename: []const u8) FileExt {...@@ -3229,6 +3234,8 @@ pub fn classifyFileExt(filename: []const u8) FileExt {
3229 return .c;3234 return .c;
3230 } else if (hasCppExt(filename)) {3235 } else if (hasCppExt(filename)) {
3231 return .cpp;3236 return .cpp;
3237 } else if (hasObjCExt(filename)) {
3238 return .m;
3232 } else if (mem.endsWith(u8, filename, ".ll")) {3239 } else if (mem.endsWith(u8, filename, ".ll")) {
3233 return .ll;3240 return .ll;
3234 } else if (mem.endsWith(u8, filename, ".bc")) {3241 } else if (mem.endsWith(u8, filename, ".bc")) {
...@@ -3252,6 +3259,7 @@ pub fn classifyFileExt(filename: []const u8) FileExt {...@@ -3252,6 +3259,7 @@ pub fn classifyFileExt(filename: []const u8) FileExt {
32523259
3253test "classifyFileExt" {3260test "classifyFileExt" {
3254 try std.testing.expectEqual(FileExt.cpp, classifyFileExt("foo.cc"));3261 try std.testing.expectEqual(FileExt.cpp, classifyFileExt("foo.cc"));
3262 try std.testing.expectEqual(FileExt.m, classifyFileExt("foo.m"));
3255 try std.testing.expectEqual(FileExt.unknown, classifyFileExt("foo.nim"));3263 try std.testing.expectEqual(FileExt.unknown, classifyFileExt("foo.nim"));
3256 try std.testing.expectEqual(FileExt.shared_library, classifyFileExt("foo.so"));3264 try std.testing.expectEqual(FileExt.shared_library, classifyFileExt("foo.so"));
3257 try std.testing.expectEqual(FileExt.shared_library, classifyFileExt("foo.so.1"));3265 try std.testing.expectEqual(FileExt.shared_library, classifyFileExt("foo.so.1"));
src/main.zig+3-2
...@@ -290,6 +290,7 @@ const usage_build_generic =...@@ -290,6 +290,7 @@ const usage_build_generic =
290 \\ .c C source code (requires LLVM extensions)290 \\ .c C source code (requires LLVM extensions)
291 \\ .cpp C++ source code (requires LLVM extensions)291 \\ .cpp C++ source code (requires LLVM extensions)
292 \\ Other C++ extensions: .C .cc .cxx292 \\ Other C++ extensions: .C .cc .cxx
293 \\ .m Objective-C source code (requires LLVM extensions)
293 \\294 \\
294 \\General Options:295 \\General Options:
295 \\ -h, --help Print this help and exit296 \\ -h, --help Print this help and exit
...@@ -1072,7 +1073,7 @@ fn buildOutputType(...@@ -1072,7 +1073,7 @@ fn buildOutputType(
1072 .object, .static_library, .shared_library => {1073 .object, .static_library, .shared_library => {
1073 try link_objects.append(arg);1074 try link_objects.append(arg);
1074 },1075 },
1075 .assembly, .c, .cpp, .h, .ll, .bc => {1076 .assembly, .c, .cpp, .h, .ll, .bc, .m => {
1076 try c_source_files.append(.{1077 try c_source_files.append(.{
1077 .src_path = arg,1078 .src_path = arg,
1078 .extra_flags = try arena.dupe([]const u8, extra_cflags.items),1079 .extra_flags = try arena.dupe([]const u8, extra_cflags.items),
...@@ -1135,7 +1136,7 @@ fn buildOutputType(...@@ -1135,7 +1136,7 @@ fn buildOutputType(
1135 .positional => {1136 .positional => {
1136 const file_ext = Compilation.classifyFileExt(mem.spanZ(it.only_arg));1137 const file_ext = Compilation.classifyFileExt(mem.spanZ(it.only_arg));
1137 switch (file_ext) {1138 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 }),
1139 .unknown, .shared_library, .object, .static_library => {1140 .unknown, .shared_library, .object, .static_library => {
1140 try link_objects.append(it.only_arg);1141 try link_objects.append(it.only_arg);
1141 },1142 },