authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-01-27 13:29:32-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-01-27 13:29:32-07:00
logf589a66062fb99c737ab84dc5106add596cc03d4
tree200f4ed748dd89b0d126b41de742736f54eaadab
parent8c90b05add807bdceb659aed6edba7e591f4e952

stage2: make cuda file extensions a separate enum tag than c++

follow-up to 2f41bd3be438dae2a188cfae3295dc28f4e9d434.

2 files changed, 15 insertions(+), 8 deletions(-)

src/Compilation.zig+10-6
......@@ -3854,7 +3854,7 @@ pub fn addCCArgs(
38543854 try argv.appendSlice(&[_][]const u8{ "-target", llvm_triple });
38553855
38563856 switch (ext) {
3857 .c, .cpp, .m, .mm, .h => {
3857 .c, .cpp, .m, .mm, .h, .cuda => {
38583858 try argv.appendSlice(&[_][]const u8{
38593859 "-nostdinc",
38603860 "-fno-spell-checking",
......@@ -4153,6 +4153,7 @@ fn failCObjWithOwnedErrorMsg(
41534153pub const FileExt = enum {
41544154 c,
41554155 cpp,
4156 cuda,
41564157 h,
41574158 m,
41584159 mm,
......@@ -4167,7 +4168,7 @@ pub const FileExt = enum {
41674168
41684169 pub fn clangSupportsDepFile(ext: FileExt) bool {
41694170 return switch (ext) {
4170 .c, .cpp, .h, .m, .mm => true,
4171 .c, .cpp, .h, .m, .mm, .cuda => true,
41714172
41724173 .ll,
41734174 .bc,
......@@ -4198,10 +4199,11 @@ pub fn hasCppExt(filename: []const u8) bool {
41984199 return mem.endsWith(u8, filename, ".C") or
41994200 mem.endsWith(u8, filename, ".cc") or
42004201 mem.endsWith(u8, filename, ".cpp") or
4201 mem.endsWith(u8, filename, ".cxx") or
4202 mem.endsWith(u8, filename, ".cu") or
4203 // .stub files are compiled by nvcc when using `zig c++` as the host compiler. They contain C++ code.
4204 mem.endsWith(u8, filename, ".stub");
4202 mem.endsWith(u8, filename, ".cxx");
4203}
4204
4205pub fn hasCudaExt(filename: []const u8) bool {
4206 return mem.endsWith(u8, filename, ".cu") or mem.endsWith(u8, filename, ".stub");
42054207}
42064208
42074209pub fn hasObjCExt(filename: []const u8) bool {
......@@ -4268,6 +4270,8 @@ pub fn classifyFileExt(filename: []const u8) FileExt {
42684270 return .static_library;
42694271 } else if (hasObjectExt(filename)) {
42704272 return .object;
4273 } else if (hasCudaExt(filename)) {
4274 return .cuda;
42714275 } else {
42724276 return .unknown;
42734277 }
src/main.zig+5-2
......@@ -298,6 +298,7 @@ const usage_build_generic =
298298 \\ .m Objective-C source code (requires LLVM extensions)
299299 \\ .mm Objective-C++ source code (requires LLVM extensions)
300300 \\ .bc LLVM IR Module (requires LLVM extensions)
301 \\ .cu .stub Cuda source code (requires LLVM extensions)
301302 \\
302303 \\General Options:
303304 \\ -h, --help Print this help and exit
......@@ -1247,7 +1248,7 @@ fn buildOutputType(
12471248 .object, .static_library, .shared_library => {
12481249 try link_objects.append(.{ .path = arg });
12491250 },
1250 .assembly, .c, .cpp, .h, .ll, .bc, .m, .mm => {
1251 .assembly, .c, .cpp, .h, .ll, .bc, .m, .mm, .cuda => {
12511252 try c_source_files.append(.{
12521253 .src_path = arg,
12531254 .extra_flags = try arena.dupe([]const u8, extra_cflags.items),
......@@ -1315,7 +1316,9 @@ fn buildOutputType(
13151316 .positional => {
13161317 const file_ext = Compilation.classifyFileExt(mem.sliceTo(it.only_arg, 0));
13171318 switch (file_ext) {
1318 .assembly, .c, .cpp, .ll, .bc, .h, .m, .mm => try c_source_files.append(.{ .src_path = it.only_arg }),
1319 .assembly, .c, .cpp, .ll, .bc, .h, .m, .mm, .cuda => {
1320 try c_source_files.append(.{ .src_path = it.only_arg });
1321 },
13191322 .unknown, .shared_library, .object, .static_library => {
13201323 try link_objects.append(.{
13211324 .path = it.only_arg,