From 2acae82eccef3486ca64d4dd2121be8fd92518ea Mon Sep 17 00:00:00 2001 From: "Sv. Lockal" Date: Sun, 22 Jun 2025 14:54:15 +0000 Subject: [PATCH] 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 Part-of: https://github.com/gentoo/gentoo/pull/42691 Signed-off-by: Sam James --- eclass/rocm.eclass | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/eclass/rocm.eclass b/eclass/rocm.eclass index 65726a0bc6213..a7601bf43f2d2 100644 --- a/eclass/rocm.eclass +++ b/eclass/rocm.eclass @@ -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 }