rocm.eclass: add rocm_use_clang and strip flags in a better way

In recent releases some ROCm packages switched from hipcc to clang++
(as hipcc is now mostly a simple wrapper that calls clang++).
New rocm_use_clang function allows to switch compiler to HIP-compatible clang.

Both hipcc and clang reject some flags when compiling *.hip files;
to clean incompatible CXXFLAGS new test-flags-HIPCXX function is used.

Bug: https://bugs.gentoo.org/957893
Signed-off-by: Sv. Lockal <lockalsash@gmail.com>
Part-of: https://github.com/gentoo/gentoo/pull/42691
Signed-off-by: Sam James <sam@gentoo.org>
This commit is contained in:
Sv. Lockal
2025-06-22 14:54:15 +00:00
committed by Sam James
parent 74d25eedd9
commit 2acae82ecc

View File

@@ -246,6 +246,18 @@ check_amdgpu() {
fi
# @FUNCTION: _rocm_strip_unsupported_flags
# @INTERNAL
# @DESCRIPTION:
# Clean flags that are not compatible with 'amdgcn-amd-amdhsa' target.
_rocm_strip_unsupported_flags() {
strip-unsupported-flags
# FLAGS like -mtls-dialect=* pass test-flags-CXX check, but are not supported
# bug #957893
export CXXFLAGS=$(test-flags-HIPCXX ${CXXFLAGS})
}
# @FUNCTION: rocm_use_hipcc
# @USAGE: rocm_use_hipcc
# @DESCRIPTION:
@@ -267,5 +279,20 @@ rocm_use_hipcc() {
# Export updated CC and CXX. Note that CC is needed even if no C code used,
# as CMake checks that C compiler can compile a simple test program.
export CC=hipcc CXX=hipcc
strip-unsupported-flags
_rocm_strip_unsupported_flags
}
# @FUNCTION: rocm_use_clang
# @USAGE: rocm_use_clang
# @DESCRIPTION:
# switch active C and C++ compilers to clang/clang++, clean unsupported flags
rocm_use_clang() {
local hipclangpath
if ! hipclangpath=$(hipconfig --hipclangpath); then
die "Error: \"hipconfig --hipclangpath\" failed"
fi
export CC="${hipclangpath}/${CHOST}-clang"
export CXX="${hipclangpath}/${CHOST}-clang++"
_rocm_strip_unsupported_flags
}