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(
34483448 try argv.appendSlice(&[_][]const u8{ "-target", llvm_triple });
34493449
34503450 switch (ext) {
3451 .c, .cpp, .m, .mm, .h => {
3451 .c, .cpp, .m, .mm, .h, .cuda => {
34523452 try argv.appendSlice(&[_][]const u8{
34533453 "-nostdinc",
34543454 "-fno-spell-checking",
......@@ -3747,6 +3747,7 @@ fn failCObjWithOwnedErrorMsg(
37473747pub const FileExt = enum {
37483748 c,
37493749 cpp,
3750 cuda,
37503751 h,
37513752 m,
37523753 mm,
......@@ -3761,7 +3762,7 @@ pub const FileExt = enum {
37613762
37623763 pub fn clangSupportsDepFile(ext: FileExt) bool {
37633764 return switch (ext) {
3764 .c, .cpp, .h, .m, .mm => true,
3765 .c, .cpp, .h, .m, .mm, .cuda => true,
37653766
37663767 .ll,
37673768 .bc,
......@@ -3792,10 +3793,11 @@ pub fn hasCppExt(filename: []const u8) bool {
37923793 return mem.endsWith(u8, filename, ".C") or
37933794 mem.endsWith(u8, filename, ".cc") or
37943795 mem.endsWith(u8, filename, ".cpp") or
3795 mem.endsWith(u8, filename, ".cxx") or
3796 mem.endsWith(u8, filename, ".cu") or
3797 // .stub files are compiled by nvcc when using `zig c++` as the host compiler. They contain C++ code.
3798 mem.endsWith(u8, filename, ".stub");
3796 mem.endsWith(u8, filename, ".cxx");
3797}
3798
3799pub fn hasCudaExt(filename: []const u8) bool {
3800 return mem.endsWith(u8, filename, ".cu") or mem.endsWith(u8, filename, ".stub");
37993801}
38003802
38013803pub fn hasObjCExt(filename: []const u8) bool {
......@@ -3862,6 +3864,8 @@ pub fn classifyFileExt(filename: []const u8) FileExt {
38623864 return .static_library;
38633865 } else if (hasObjectExt(filename)) {
38643866 return .object;
3867 } else if (hasCudaExt(filename)) {
3868 return .cuda;
38653869 } else {
38663870 return .unknown;
38673871 }
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
......@@ -1239,7 +1240,7 @@ fn buildOutputType(
12391240 .object, .static_library, .shared_library => {
12401241 try link_objects.append(.{ .path = arg });
12411242 },
1242 .assembly, .c, .cpp, .h, .ll, .bc, .m, .mm => {
1243 .assembly, .c, .cpp, .h, .ll, .bc, .m, .mm, .cuda => {
12431244 try c_source_files.append(.{
12441245 .src_path = arg,
12451246 .extra_flags = try arena.dupe([]const u8, extra_cflags.items),
......@@ -1307,7 +1308,9 @@ fn buildOutputType(
13071308 .positional => {
13081309 const file_ext = Compilation.classifyFileExt(mem.sliceTo(it.only_arg, 0));
13091310 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 },
13111314 .unknown, .shared_library, .object, .static_library => {
13121315 try link_objects.append(.{
13131316 .path = it.only_arg,