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-02-02 22:00:12-07:00
log45cd1114f76b80bae1513f10d29b8d09261ae632
treea1542a2bb1a63d5382c02a8f37c289d26bcdc93d
parentd7feeaaa2cb36ec05c70275a30afe17b1b9c9bfc

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
...@@ -3448,7 +3448,7 @@ pub fn addCCArgs(...@@ -3448,7 +3448,7 @@ pub fn addCCArgs(
3448 try argv.appendSlice(&[_][]const u8{ "-target", llvm_triple });3448 try argv.appendSlice(&[_][]const u8{ "-target", llvm_triple });
34493449
3450 switch (ext) {3450 switch (ext) {
3451 .c, .cpp, .m, .mm, .h => {3451 .c, .cpp, .m, .mm, .h, .cuda => {
3452 try argv.appendSlice(&[_][]const u8{3452 try argv.appendSlice(&[_][]const u8{
3453 "-nostdinc",3453 "-nostdinc",
3454 "-fno-spell-checking",3454 "-fno-spell-checking",
...@@ -3747,6 +3747,7 @@ fn failCObjWithOwnedErrorMsg(...@@ -3747,6 +3747,7 @@ fn failCObjWithOwnedErrorMsg(
3747pub const FileExt = enum {3747pub const FileExt = enum {
3748 c,3748 c,
3749 cpp,3749 cpp,
3750 cuda,
3750 h,3751 h,
3751 m,3752 m,
3752 mm,3753 mm,
...@@ -3761,7 +3762,7 @@ pub const FileExt = enum {...@@ -3761,7 +3762,7 @@ pub const FileExt = enum {
37613762
3762 pub fn clangSupportsDepFile(ext: FileExt) bool {3763 pub fn clangSupportsDepFile(ext: FileExt) bool {
3763 return switch (ext) {3764 return switch (ext) {
3764 .c, .cpp, .h, .m, .mm => true,3765 .c, .cpp, .h, .m, .mm, .cuda => true,
37653766
3766 .ll,3767 .ll,
3767 .bc,3768 .bc,
...@@ -3792,10 +3793,11 @@ pub fn hasCppExt(filename: []const u8) bool {...@@ -3792,10 +3793,11 @@ pub fn hasCppExt(filename: []const u8) bool {
3792 return mem.endsWith(u8, filename, ".C") or3793 return mem.endsWith(u8, filename, ".C") or
3793 mem.endsWith(u8, filename, ".cc") or3794 mem.endsWith(u8, filename, ".cc") or
3794 mem.endsWith(u8, filename, ".cpp") or3795 mem.endsWith(u8, filename, ".cpp") or
3795 mem.endsWith(u8, filename, ".cxx") or3796 mem.endsWith(u8, filename, ".cxx");
3796 mem.endsWith(u8, filename, ".cu") or3797}
3797 // .stub files are compiled by nvcc when using `zig c++` as the host compiler. They contain C++ code.3798
3798 mem.endsWith(u8, filename, ".stub");3799pub fn hasCudaExt(filename: []const u8) bool {
3800 return mem.endsWith(u8, filename, ".cu") or mem.endsWith(u8, filename, ".stub");
3799}3801}
38003802
3801pub fn hasObjCExt(filename: []const u8) bool {3803pub fn hasObjCExt(filename: []const u8) bool {
...@@ -3862,6 +3864,8 @@ pub fn classifyFileExt(filename: []const u8) FileExt {...@@ -3862,6 +3864,8 @@ pub fn classifyFileExt(filename: []const u8) FileExt {
3862 return .static_library;3864 return .static_library;
3863 } else if (hasObjectExt(filename)) {3865 } else if (hasObjectExt(filename)) {
3864 return .object;3866 return .object;
3867 } else if (hasCudaExt(filename)) {
3868 return .cuda;
3865 } else {3869 } else {
3866 return .unknown;3870 return .unknown;
3867 }3871 }
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
...@@ -1239,7 +1240,7 @@ fn buildOutputType(...@@ -1239,7 +1240,7 @@ fn buildOutputType(
1239 .object, .static_library, .shared_library => {1240 .object, .static_library, .shared_library => {
1240 try link_objects.append(.{ .path = arg });1241 try link_objects.append(.{ .path = arg });
1241 },1242 },
1242 .assembly, .c, .cpp, .h, .ll, .bc, .m, .mm => {1243 .assembly, .c, .cpp, .h, .ll, .bc, .m, .mm, .cuda => {
1243 try c_source_files.append(.{1244 try c_source_files.append(.{
1244 .src_path = arg,1245 .src_path = arg,
1245 .extra_flags = try arena.dupe([]const u8, extra_cflags.items),1246 .extra_flags = try arena.dupe([]const u8, extra_cflags.items),
...@@ -1307,7 +1308,9 @@ fn buildOutputType(...@@ -1307,7 +1308,9 @@ fn buildOutputType(
1307 .positional => {1308 .positional => {
1308 const file_ext = Compilation.classifyFileExt(mem.sliceTo(it.only_arg, 0));1309 const file_ext = Compilation.classifyFileExt(mem.sliceTo(it.only_arg, 0));
1309 switch (file_ext) {1310 switch (file_ext) {
1310 .assembly, .c, .cpp, .ll, .bc, .h, .m, .mm => try c_source_files.append(.{ .src_path = it.only_arg }),1311 .assembly, .c, .cpp, .ll, .bc, .h, .m, .mm, .cuda => {
1312 try c_source_files.append(.{ .src_path = it.only_arg });
1313 },
1311 .unknown, .shared_library, .object, .static_library => {1314 .unknown, .shared_library, .object, .static_library => {
1312 try link_objects.append(.{1315 try link_objects.append(.{
1313 .path = it.only_arg,1316 .path = it.only_arg,