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(...@@ -3854,7 +3854,7 @@ pub fn addCCArgs(
3854 try argv.appendSlice(&[_][]const u8{ "-target", llvm_triple });3854 try argv.appendSlice(&[_][]const u8{ "-target", llvm_triple });
38553855
3856 switch (ext) {3856 switch (ext) {
3857 .c, .cpp, .m, .mm, .h => {3857 .c, .cpp, .m, .mm, .h, .cuda => {
3858 try argv.appendSlice(&[_][]const u8{3858 try argv.appendSlice(&[_][]const u8{
3859 "-nostdinc",3859 "-nostdinc",
3860 "-fno-spell-checking",3860 "-fno-spell-checking",
...@@ -4153,6 +4153,7 @@ fn failCObjWithOwnedErrorMsg(...@@ -4153,6 +4153,7 @@ fn failCObjWithOwnedErrorMsg(
4153pub const FileExt = enum {4153pub const FileExt = enum {
4154 c,4154 c,
4155 cpp,4155 cpp,
4156 cuda,
4156 h,4157 h,
4157 m,4158 m,
4158 mm,4159 mm,
...@@ -4167,7 +4168,7 @@ pub const FileExt = enum {...@@ -4167,7 +4168,7 @@ pub const FileExt = enum {
41674168
4168 pub fn clangSupportsDepFile(ext: FileExt) bool {4169 pub fn clangSupportsDepFile(ext: FileExt) bool {
4169 return switch (ext) {4170 return switch (ext) {
4170 .c, .cpp, .h, .m, .mm => true,4171 .c, .cpp, .h, .m, .mm, .cuda => true,
41714172
4172 .ll,4173 .ll,
4173 .bc,4174 .bc,
...@@ -4198,10 +4199,11 @@ pub fn hasCppExt(filename: []const u8) bool {...@@ -4198,10 +4199,11 @@ pub fn hasCppExt(filename: []const u8) bool {
4198 return mem.endsWith(u8, filename, ".C") or4199 return mem.endsWith(u8, filename, ".C") or
4199 mem.endsWith(u8, filename, ".cc") or4200 mem.endsWith(u8, filename, ".cc") or
4200 mem.endsWith(u8, filename, ".cpp") or4201 mem.endsWith(u8, filename, ".cpp") or
4201 mem.endsWith(u8, filename, ".cxx") or4202 mem.endsWith(u8, filename, ".cxx");
4202 mem.endsWith(u8, filename, ".cu") or4203}
4203 // .stub files are compiled by nvcc when using `zig c++` as the host compiler. They contain C++ code.4204
4204 mem.endsWith(u8, filename, ".stub");4205pub fn hasCudaExt(filename: []const u8) bool {
4206 return mem.endsWith(u8, filename, ".cu") or mem.endsWith(u8, filename, ".stub");
4205}4207}
42064208
4207pub fn hasObjCExt(filename: []const u8) bool {4209pub fn hasObjCExt(filename: []const u8) bool {
...@@ -4268,6 +4270,8 @@ pub fn classifyFileExt(filename: []const u8) FileExt {...@@ -4268,6 +4270,8 @@ pub fn classifyFileExt(filename: []const u8) FileExt {
4268 return .static_library;4270 return .static_library;
4269 } else if (hasObjectExt(filename)) {4271 } else if (hasObjectExt(filename)) {
4270 return .object;4272 return .object;
4273 } else if (hasCudaExt(filename)) {
4274 return .cuda;
4271 } else {4275 } else {
4272 return .unknown;4276 return .unknown;
4273 }4277 }
src/main.zig+5-2
...@@ -298,6 +298,7 @@ const usage_build_generic =...@@ -298,6 +298,7 @@ const usage_build_generic =
298 \\ .m Objective-C source code (requires LLVM extensions)298 \\ .m Objective-C source code (requires LLVM extensions)
299 \\ .mm Objective-C++ source code (requires LLVM extensions)299 \\ .mm Objective-C++ source code (requires LLVM extensions)
300 \\ .bc LLVM IR Module (requires LLVM extensions)300 \\ .bc LLVM IR Module (requires LLVM extensions)
301 \\ .cu .stub Cuda source code (requires LLVM extensions)
301 \\302 \\
302 \\General Options:303 \\General Options:
303 \\ -h, --help Print this help and exit304 \\ -h, --help Print this help and exit
...@@ -1247,7 +1248,7 @@ fn buildOutputType(...@@ -1247,7 +1248,7 @@ fn buildOutputType(
1247 .object, .static_library, .shared_library => {1248 .object, .static_library, .shared_library => {
1248 try link_objects.append(.{ .path = arg });1249 try link_objects.append(.{ .path = arg });
1249 },1250 },
1250 .assembly, .c, .cpp, .h, .ll, .bc, .m, .mm => {1251 .assembly, .c, .cpp, .h, .ll, .bc, .m, .mm, .cuda => {
1251 try c_source_files.append(.{1252 try c_source_files.append(.{
1252 .src_path = arg,1253 .src_path = arg,
1253 .extra_flags = try arena.dupe([]const u8, extra_cflags.items),1254 .extra_flags = try arena.dupe([]const u8, extra_cflags.items),
...@@ -1315,7 +1316,9 @@ fn buildOutputType(...@@ -1315,7 +1316,9 @@ fn buildOutputType(
1315 .positional => {1316 .positional => {
1316 const file_ext = Compilation.classifyFileExt(mem.sliceTo(it.only_arg, 0));1317 const file_ext = Compilation.classifyFileExt(mem.sliceTo(it.only_arg, 0));
1317 switch (file_ext) {1318 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 },
1319 .unknown, .shared_library, .object, .static_library => {1322 .unknown, .shared_library, .object, .static_library => {
1320 try link_objects.append(.{1323 try link_objects.append(.{
1321 .path = it.only_arg,1324 .path = it.only_arg,