Skip to content

Commit 37996a3

Browse files
[ROCm] Support clang19 as host compiler
Pass --no-canonical-prefixes to clang19 to get old InstalledDir behavior.
1 parent 0db44cc commit 37996a3

File tree

4 files changed

+18
-128
lines changed

4 files changed

+18
-128
lines changed

third_party/gpus/compiler_common_tools.bzl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,14 @@ def _get_cxx_inc_directories_impl(repository_ctx, cc, lang_is_cpp, tf_sys_root):
7272
sysroot = []
7373
if tf_sys_root:
7474
sysroot += ["--sysroot", tf_sys_root]
75+
no_canonical_prefixes_supported = _is_compiler_option_supported(
76+
repository_ctx,
77+
cc,
78+
"-no-canonical-prefixes",
79+
)
80+
no_canonical_prefixes = (["-no-canonical-prefixes"] if no_canonical_prefixes_supported else [])
7581
result = raw_exec(repository_ctx, [cc, "-E", "-x" + lang, "-", "-v"] +
76-
sysroot)
82+
sysroot + no_canonical_prefixes)
7783
stderr = err_out(result)
7884
index1 = stderr.find(_INC_DIR_MARKER_BEGIN)
7985
if index1 == -1:
@@ -148,7 +154,7 @@ def _get_cxx_inc_directories_impl(repository_ctx, cc, lang_is_cpp, tf_sys_root):
148154
compiler_includes = compiler_includes + unresolved_compiler_includes
149155
return compiler_includes
150156

151-
def get_cxx_inc_directories(repository_ctx, cc, tf_sys_root):
157+
def get_cxx_inc_directories(repository_ctx, cc, tf_sys_root = None):
152158
"""Compute the list of default C and C++ include directories."""
153159

154160
# For some reason `clang -xc` sometimes returns include paths that are

third_party/gpus/rocm_configure.bzl

Lines changed: 1 addition & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ load(
2525
)
2626
load(
2727
":compiler_common_tools.bzl",
28+
"get_cxx_inc_directories",
2829
"to_list_of_strings",
2930
)
3031
load(
@@ -102,68 +103,6 @@ def find_cc(repository_ctx):
102103
" environment variable").format(target_cc_name, cc_path_envvar))
103104
return cc
104105

105-
_INC_DIR_MARKER_BEGIN = "#include <...>"
106-
107-
def _cxx_inc_convert(path):
108-
"""Convert path returned by cc -E xc++ in a complete path."""
109-
path = path.strip()
110-
return path
111-
112-
def _get_cxx_inc_directories_impl(repository_ctx, cc, lang_is_cpp):
113-
"""Compute the list of default C or C++ include directories."""
114-
if lang_is_cpp:
115-
lang = "c++"
116-
else:
117-
lang = "c"
118-
119-
# TODO: We pass -no-canonical-prefixes here to match the compiler flags,
120-
# but in rocm_clang CROSSTOOL file that is a `feature` and we should
121-
# handle the case when it's disabled and no flag is passed
122-
result = raw_exec(repository_ctx, [
123-
cc,
124-
"-no-canonical-prefixes",
125-
"-E",
126-
"-x" + lang,
127-
"-",
128-
"-v",
129-
])
130-
stderr = err_out(result)
131-
index1 = stderr.find(_INC_DIR_MARKER_BEGIN)
132-
if index1 == -1:
133-
return []
134-
index1 = stderr.find("\n", index1)
135-
if index1 == -1:
136-
return []
137-
index2 = stderr.rfind("\n ")
138-
if index2 == -1 or index2 < index1:
139-
return []
140-
index2 = stderr.find("\n", index2 + 1)
141-
if index2 == -1:
142-
inc_dirs = stderr[index1 + 1:]
143-
else:
144-
inc_dirs = stderr[index1 + 1:index2].strip()
145-
146-
return [
147-
str(repository_ctx.path(_cxx_inc_convert(p)))
148-
for p in inc_dirs.split("\n")
149-
]
150-
151-
def get_cxx_inc_directories(repository_ctx, cc):
152-
"""Compute the list of default C and C++ include directories."""
153-
154-
# For some reason `clang -xc` sometimes returns include paths that are
155-
# different from the ones from `clang -xc++`. (Symlink and a dir)
156-
# So we run the compiler with both `-xc` and `-xc++` and merge resulting lists
157-
includes_cpp = _get_cxx_inc_directories_impl(repository_ctx, cc, True)
158-
includes_c = _get_cxx_inc_directories_impl(repository_ctx, cc, False)
159-
160-
includes_cpp_set = depset(includes_cpp)
161-
return includes_cpp + [
162-
inc
163-
for inc in includes_c
164-
if inc not in includes_cpp_set.to_list()
165-
]
166-
167106
def auto_configure_fail(msg):
168107
"""Output failure message when rocm configuration fails."""
169108
red = "\033[0;31m"

third_party/xla/third_party/tsl/third_party/gpus/compiler_common_tools.bzl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,14 @@ def _get_cxx_inc_directories_impl(repository_ctx, cc, lang_is_cpp, tf_sys_root):
7272
sysroot = []
7373
if tf_sys_root:
7474
sysroot += ["--sysroot", tf_sys_root]
75+
no_canonical_prefixes_supported = _is_compiler_option_supported(
76+
repository_ctx,
77+
cc,
78+
"-no-canonical-prefixes",
79+
)
80+
no_canonical_prefixes = (["-no-canonical-prefixes"] if no_canonical_prefixes_supported else [])
7581
result = raw_exec(repository_ctx, [cc, "-E", "-x" + lang, "-", "-v"] +
76-
sysroot)
82+
sysroot + no_canonical_prefixes)
7783
stderr = err_out(result)
7884
index1 = stderr.find(_INC_DIR_MARKER_BEGIN)
7985
if index1 == -1:
@@ -148,7 +154,7 @@ def _get_cxx_inc_directories_impl(repository_ctx, cc, lang_is_cpp, tf_sys_root):
148154
compiler_includes = compiler_includes + unresolved_compiler_includes
149155
return compiler_includes
150156

151-
def get_cxx_inc_directories(repository_ctx, cc, tf_sys_root):
157+
def get_cxx_inc_directories(repository_ctx, cc, tf_sys_root = None):
152158
"""Compute the list of default C and C++ include directories."""
153159

154160
# For some reason `clang -xc` sometimes returns include paths that are

third_party/xla/third_party/tsl/third_party/gpus/rocm_configure.bzl

Lines changed: 1 addition & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ load(
2525
)
2626
load(
2727
":compiler_common_tools.bzl",
28+
"get_cxx_inc_directories",
2829
"to_list_of_strings",
2930
)
3031
load(
@@ -93,68 +94,6 @@ def find_cc(repository_ctx):
9394
" environment variable").format(target_cc_name, cc_path_envvar))
9495
return cc
9596

96-
_INC_DIR_MARKER_BEGIN = "#include <...>"
97-
98-
def _cxx_inc_convert(path):
99-
"""Convert path returned by cc -E xc++ in a complete path."""
100-
path = path.strip()
101-
return path
102-
103-
def _get_cxx_inc_directories_impl(repository_ctx, cc, lang_is_cpp):
104-
"""Compute the list of default C or C++ include directories."""
105-
if lang_is_cpp:
106-
lang = "c++"
107-
else:
108-
lang = "c"
109-
110-
# TODO: We pass -no-canonical-prefixes here to match the compiler flags,
111-
# but in rocm_clang CROSSTOOL file that is a `feature` and we should
112-
# handle the case when it's disabled and no flag is passed
113-
result = raw_exec(repository_ctx, [
114-
cc,
115-
"-no-canonical-prefixes",
116-
"-E",
117-
"-x" + lang,
118-
"-",
119-
"-v",
120-
])
121-
stderr = err_out(result)
122-
index1 = stderr.find(_INC_DIR_MARKER_BEGIN)
123-
if index1 == -1:
124-
return []
125-
index1 = stderr.find("\n", index1)
126-
if index1 == -1:
127-
return []
128-
index2 = stderr.rfind("\n ")
129-
if index2 == -1 or index2 < index1:
130-
return []
131-
index2 = stderr.find("\n", index2 + 1)
132-
if index2 == -1:
133-
inc_dirs = stderr[index1 + 1:]
134-
else:
135-
inc_dirs = stderr[index1 + 1:index2].strip()
136-
137-
return [
138-
str(repository_ctx.path(_cxx_inc_convert(p)))
139-
for p in inc_dirs.split("\n")
140-
]
141-
142-
def get_cxx_inc_directories(repository_ctx, cc):
143-
"""Compute the list of default C and C++ include directories."""
144-
145-
# For some reason `clang -xc` sometimes returns include paths that are
146-
# different from the ones from `clang -xc++`. (Symlink and a dir)
147-
# So we run the compiler with both `-xc` and `-xc++` and merge resulting lists
148-
includes_cpp = _get_cxx_inc_directories_impl(repository_ctx, cc, True)
149-
includes_c = _get_cxx_inc_directories_impl(repository_ctx, cc, False)
150-
151-
includes_cpp_set = depset(includes_cpp)
152-
return includes_cpp + [
153-
inc
154-
for inc in includes_c
155-
if inc not in includes_cpp_set.to_list()
156-
]
157-
15897
def auto_configure_fail(msg):
15998
"""Output failure message when rocm configuration fails."""
16099
red = "\033[0;31m"

0 commit comments

Comments
 (0)