Skip to content

Commit

Permalink
Recognize CUDA and OpenCL source file types (.cu, .cl) and compile t…
Browse files Browse the repository at this point in the history
…hem with the C++ compiler. This will allow CUDA and OpenCL files to be compiled with clang, which supports both natively.

    Change taken from bazelbuild/bazel#6578 (comment)

    RELNOTES: Treat .cu and .cl files as C++ source. CUDA or OpenCL are not natively supported and will require custom flags to compile with e.g. clang.
    PiperOrigin-RevId: 295733167
  • Loading branch information
Luca Di Grazia committed Sep 4, 2022
1 parent 952d580 commit 60dc14c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,15 @@ public ImmutableList<String> getExtensions() {
// Matches shared libraries with version names in the extension, i.e.
// libmylib.so.2 or libmylib.so.2.10 or libmylib.so.1a_b35.
private static final Pattern VERSIONED_SHARED_LIBRARY_PATTERN =
Pattern.compile("^.+\\.((so)|(dylib))(\\.\\d\\w*)+$");
Pattern.compile("^.+\\.so(\\.\\d\\w*)+$");
public static final FileType VERSIONED_SHARED_LIBRARY =
new FileType() {
@Override
public boolean apply(String path) {
// Because regex matching can be slow, we first do a quick check for ".so." and ".dylib."
// Because regex matching can be slow, we first do a quick check for ".so."
// substring before risking the full-on regex match. This should eliminate the performance
// hit on practically every non-qualifying file type.
if (!path.contains(".so.") && !path.contains(".dylib.")) {
if (!path.contains(".so.")) {
return false;
}
return VERSIONED_SHARED_LIBRARY_PATTERN.matcher(path).matches();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,6 @@ class Constants {
// Please keep in sync with the extensions in CppFileTypes.
static final ImmutableList<String> CC_EXTENSIONS =
ImmutableList.of(
".cc", ".cpp", ".cxx", ".c++", ".C", ".c", ".h", ".hh", ".hpp", ".ipp", ".hxx", ".inc");
".cc", ".cpp", ".cxx", ".c++", ".C", ".c", ".cu", ".cl", ".h", ".hh", ".hpp", ".ipp",
".hxx", ".inc", ".inl", ".tlh", ".tli", ".H");
}

0 comments on commit 60dc14c

Please sign in to comment.