]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Support source code language “cuda”, used by Clang
authorJoel Rosdahl <joel@rosdahl.net>
Sat, 16 Jan 2021 19:09:03 +0000 (20:09 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Sat, 16 Jan 2021 19:22:26 +0000 (20:22 +0100)
See also 2728c68bba9f8b4bb5c8812cd1b50402b81ebfd9.

Closes #772.

src/argprocessing.cpp
src/language.cpp
src/language.hpp

index 42ca43d72ef84e6a9a1f6aaa613c570d312b2afe..612eadd7e54319ec0ccc3a8a3e559ccf4520ee5b 100644 (file)
@@ -999,7 +999,8 @@ process_args(Context& ctx)
     }
     args_info.actual_language = state.explicit_language;
   } else {
-    args_info.actual_language = language_for_file(args_info.input_file);
+    args_info.actual_language =
+      language_for_file(args_info.input_file, config.compiler_type());
   }
 
   args_info.output_is_precompiled_header =
@@ -1032,8 +1033,11 @@ process_args(Context& ctx)
     return Statistic::unsupported_source_language;
   }
 
-  if (!config.run_second_cpp() && args_info.actual_language == "cu") {
-    LOG_RAW("Using CUDA compiler; not compiling preprocessed code");
+  if (!config.run_second_cpp()
+      && (args_info.actual_language == "cu"
+          || args_info.actual_language == "cuda")) {
+    LOG("Source language is \"{}\"; not compiling preprocessed code",
+        args_info.actual_language);
     config.set_run_second_cpp(true);
   }
 
index 3dced4e2c3fe3fa8cb172cd861b4b049ba79aa28..aa1a2cac7a6d900f965e97349582ff802f57dbee 100644 (file)
@@ -67,7 +67,7 @@ const struct
   {".HXX", "c++-header"},
   {".tcc", "c++-header"},
   {".TCC", "c++-header"},
-  {".cu", "cu"},
+  {".cu", "cu"}, // Special case in language_for_file: "cuda" for Clang
   {".hip", "hip"},
   {nullptr, nullptr},
 };
@@ -84,7 +84,8 @@ const struct
   {"c++", "c++-cpp-output"},
   {"c++-cpp-output", "c++-cpp-output"},
   {"c++-header", "c++-cpp-output"},
-  {"cu", "cpp-output"},
+  {"cu", "cpp-output"},   // NVCC
+  {"cuda", "cpp-output"}, // Clang
   {"hip", "cpp-output"},
   {"objective-c", "objective-c-cpp-output"},
   {"objective-c-header", "objective-c-cpp-output"},
@@ -114,9 +115,13 @@ supported_source_extension(const std::string& fname)
 }
 
 std::string
-language_for_file(const std::string& fname)
+language_for_file(const std::string& fname, CompilerType compiler_type)
 {
   auto ext = Util::get_extension(fname);
+  if (ext == ".cu" && compiler_type == CompilerType::clang) {
+    // Special case: Clang maps .cu to cuda.
+    return "cuda";
+  }
   for (size_t i = 0; k_ext_lang_table[i].extension; ++i) {
     if (k_ext_lang_table[i].extension == ext) {
       return k_ext_lang_table[i].language;
index b90afdf54959aa2f819e8bf874c47fed93c23f80..99bf386e04665ee51816c6fe4043f202cc6beb2c 100644 (file)
 
 #include "system.hpp"
 
+#include "Config.hpp"
+
 #include <string>
 
 // Return whether a filename has a supported source code extension.
 bool supported_source_extension(const std::string& fname);
 
-// Guess the language of `fname` based on its extension. Returns the empty
-// string if the extension is unknown.
-std::string language_for_file(const std::string& fname);
+// Guess the language of `fname` based on its extension and a compiler type.
+// Returns the empty string if the extension is unknown.
+std::string language_for_file(const std::string& fname,
+                              CompilerType compiler_type);
 
 // Return the preprocessed language for `language`, or the empty string if
 // unknown.