@@ -20,10 +20,12 @@ load(
2020 "get_python_bin" ,
2121 "raw_exec" ,
2222 "realpath" ,
23+ "relative_to" ,
2324 "which" ,
2425)
2526load (
2627 ":compiler_common_tools.bzl" ,
28+ "get_cxx_inc_directories" ,
2729 "to_list_of_strings" ,
2830)
2931load (
@@ -101,68 +103,6 @@ def find_cc(repository_ctx):
101103 " environment variable" ).format (target_cc_name , cc_path_envvar ))
102104 return cc
103105
104- _INC_DIR_MARKER_BEGIN = "#include <...>"
105-
106- def _cxx_inc_convert (path ):
107- """Convert path returned by cc -E xc++ in a complete path."""
108- path = path .strip ()
109- return path
110-
111- def _get_cxx_inc_directories_impl (repository_ctx , cc , lang_is_cpp ):
112- """Compute the list of default C or C++ include directories."""
113- if lang_is_cpp :
114- lang = "c++"
115- else :
116- lang = "c"
117-
118- # TODO: We pass -no-canonical-prefixes here to match the compiler flags,
119- # but in rocm_clang CROSSTOOL file that is a `feature` and we should
120- # handle the case when it's disabled and no flag is passed
121- result = raw_exec (repository_ctx , [
122- cc ,
123- "-no-canonical-prefixes" ,
124- "-E" ,
125- "-x" + lang ,
126- "-" ,
127- "-v" ,
128- ])
129- stderr = err_out (result )
130- index1 = stderr .find (_INC_DIR_MARKER_BEGIN )
131- if index1 == - 1 :
132- return []
133- index1 = stderr .find ("\n " , index1 )
134- if index1 == - 1 :
135- return []
136- index2 = stderr .rfind ("\n " )
137- if index2 == - 1 or index2 < index1 :
138- return []
139- index2 = stderr .find ("\n " , index2 + 1 )
140- if index2 == - 1 :
141- inc_dirs = stderr [index1 + 1 :]
142- else :
143- inc_dirs = stderr [index1 + 1 :index2 ].strip ()
144-
145- return [
146- str (repository_ctx .path (_cxx_inc_convert (p )))
147- for p in inc_dirs .split ("\n " )
148- ]
149-
150- def get_cxx_inc_directories (repository_ctx , cc ):
151- """Compute the list of default C and C++ include directories."""
152-
153- # For some reason `clang -xc` sometimes returns include paths that are
154- # different from the ones from `clang -xc++`. (Symlink and a dir)
155- # So we run the compiler with both `-xc` and `-xc++` and merge resulting lists
156- includes_cpp = _get_cxx_inc_directories_impl (repository_ctx , cc , True )
157- includes_c = _get_cxx_inc_directories_impl (repository_ctx , cc , False )
158-
159- includes_cpp_set = depset (includes_cpp )
160- return includes_cpp + [
161- inc
162- for inc in includes_c
163- if inc not in includes_cpp_set .to_list ()
164- ]
165-
166106def auto_configure_fail (msg ):
167107 """Output failure message when rocm configuration fails."""
168108 red = "\033 [0;31m"
@@ -178,54 +118,36 @@ def auto_configure_warning(msg):
178118# END cc_configure common functions (see TODO above).
179119
180120def _rocm_include_path (repository_ctx , rocm_config , bash_bin ):
181- """Generates the cxx_builtin_include_directory entries for rocm inc dirs.
121+ """Generates the entries for rocm inc dirs based on rocm_config .
182122
183123 Args:
184124 repository_ctx: The repository context.
185125 rocm_config: The path to the gcc host compiler.
126+ bash_bin: path to the bash interpreter.
186127
187128 Returns:
188- A string containing the Starlark string for each of the gcc
189- host compiler include directories, which can be added to the CROSSTOOL
129+ A string containing the Starlark string for each of the hipcc
130+ compiler include directories, which can be added to the CROSSTOOL
190131 file.
191132 """
192133 inc_dirs = []
193134
194- # Add HSA headers (needs to match $HSA_PATH)
195- inc_dirs .append (rocm_config .rocm_toolkit_path + "/hsa/include" )
196-
197- # Add HIP headers (needs to match $HIP_PATH)
198- inc_dirs .append (rocm_config .rocm_toolkit_path + "/hip/include" )
199- if int (rocm_config .rocm_version_number ) >= 50200 :
200- inc_dirs .append (rocm_config .rocm_toolkit_path + "/include" )
201- inc_dirs .append (rocm_config .rocm_toolkit_path + "/include/hip" )
202- inc_dirs .append (rocm_config .rocm_paths ["ROCPRIM" ] + "/include/rocprim" )
203- inc_dirs .append (rocm_config .rocm_paths ["ROCSOLVER" ] + "/include/rocsolver" )
204- inc_dirs .append (rocm_config .rocm_paths ["ROCBLAS" ] + "/include/rocblas" )
205-
206- # Add HIP-Clang headers (realpath relative to compiler binary)
207- inc_dirs .append (rocm_config .llvm_path + "/lib/clang/12.0.0/include" )
208- inc_dirs .append (rocm_config .llvm_path + "/lib/clang/13.0.0/include" )
209- inc_dirs .append (rocm_config .llvm_path + "/lib/clang/14.0.0/include" )
210- inc_dirs .append (rocm_config .llvm_path + "/lib/clang/15.0.0/include" )
211- inc_dirs .append (rocm_config .llvm_path + "/lib/clang/16.0.0/include" )
212- inc_dirs .append (rocm_config .llvm_path + "/lib/clang/17.0.0/include/" )
213- inc_dirs .append (rocm_config .llvm_path + "/lib/clang/17/include" )
214- inc_dirs .append (rocm_config .llvm_path + "/lib/clang/18/include" )
215- inc_dirs .append (rocm_config .llvm_path + "/lib/clang/19/include" )
216- rocm_toolkit_path = realpath (repository_ctx , rocm_config .rocm_toolkit_path , bash_bin )
217- if int (rocm_config .rocm_version_number ) >= 60200 :
218- inc_dirs .append (rocm_toolkit_path + "/lib/llvm/lib/clang/17/include" )
219- inc_dirs .append (rocm_toolkit_path + "/lib/llvm/lib/clang/18/include" )
220- inc_dirs .append (rocm_toolkit_path + "/lib/llvm/lib/clang/19/include" )
221- inc_dirs .append (rocm_toolkit_path + "/lib/llvm/lib/clang/20/include" )
222-
223- # Support hcc based off clang 10.0.0 (for ROCm 3.3)
224- inc_dirs .append (rocm_toolkit_path + "/hcc/compiler/lib/clang/10.0.0/include/" )
225- inc_dirs .append (rocm_toolkit_path + "/hcc/lib/clang/10.0.0/include" )
226-
227- # Add hcc headers
228- inc_dirs .append (rocm_toolkit_path + "/hcc/include" )
135+ # Add HIP-Clang headers (relative to rocm root)
136+ rocm_path = repository_ctx .path (rocm_config .rocm_toolkit_path )
137+ clang_path = rocm_path .get_child ("llvm/bin/clang" )
138+ resource_dir_result = execute (repository_ctx , [str (clang_path ), "-print-resource-dir" ])
139+
140+ if resource_dir_result .return_code :
141+ auto_configure_fail ("Failed to run hipcc -print-resource-dir: %s" % err_out (resource_dir_result ))
142+
143+ resource_dir_abs = resource_dir_result .stdout .strip ()
144+
145+ resource_dir_rel = relative_to (repository_ctx , str (rocm_path .realpath ), resource_dir_abs , bash_bin )
146+
147+ resource_dir = str (rocm_path .get_child (resource_dir_rel ))
148+
149+ inc_dirs .append (resource_dir + "/include" )
150+ inc_dirs .append (resource_dir + "/share" )
229151
230152 return inc_dirs
231153
0 commit comments