Skip to content

use property for gcc_prefix/gcc_root in LLVM easyblock #3793

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 31 additions & 24 deletions easybuild/easyblocks/l/llvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@ def __init__(self, *args, **kwargs):
# Bypass the .mod file check for GCCcore installs
self.cfg['skip_mod_files_sanity_check'] = True
self.final_runtimes = []
self.gcc_prefix = None
self._gcc_prefix = None
self._gcc_root = None
self.runtimes_cmake_args = {
'CMAKE_C_COMPILER': [],
'CMAKE_C_FLAGS': [],
Expand Down Expand Up @@ -376,6 +377,24 @@ def __init__(self, *args, **kwargs):
self._cmakeopts = {}
self._cfgopts = list(filter(None, self.cfg.get('configopts', '').split()))

@property
def gcc_prefix(self):
"""Return the GCC prefix (versioned folder in <gcc_root>/lib)."""
self._set_gcc_prefix_probs()
return self._gcc_prefix

@property
def gcc_root(self):
"""Return the GCC root folder from dependencies/toolchain."""
self._set_gcc_prefix_probs()
return self._gcc_root

def _set_gcc_prefix_probs(self):
"""Set properties of currently loaded GCC installation"""
if self._gcc_root is None:
self._gcc_root, self._gcc_prefix = self._get_gcc_prefix()
self.log.debug("Using %s as the gcc install location", self._gcc_prefix)

@property
def llvm_src_dir(self):
"""Return root source directory of LLVM (containing all components)"""
Expand Down Expand Up @@ -589,26 +608,6 @@ def _get_gcc_libpath(strict=False):
return ''
return os.path.join(gcc_root, 'lib64')

def _set_gcc_prefix(self):
"""Set the GCC prefix for the build."""
if self.gcc_prefix is None:
gcc_root, gcc_prefix = self._get_gcc_prefix()

# For LLVM 18+ config files should be used and this option is deprecated and causes an error in 19
# But the --gcc-toolchain and --gcc-install-dir for flang are not supported before LLVM 19
# https://github.com/llvm/llvm-project/pull/87360
if LooseVersion(self.version) < '19':
self.log.debug("Using GCC_INSTALL_PREFIX")
self.general_opts['GCC_INSTALL_PREFIX'] = gcc_root
else:
# See https://github.com/llvm/llvm-project/pull/85891#issuecomment-2021370667
self.log.debug("Using '--gcc-install-dir' in CMAKE_C_FLAGS and CMAKE_CXX_FLAGS")
self.runtimes_cmake_args['CMAKE_C_FLAGS'].append(f'--gcc-install-dir={gcc_prefix}')
self.runtimes_cmake_args['CMAKE_CXX_FLAGS'].append(f'--gcc-install-dir={gcc_prefix}')

self.gcc_prefix = gcc_prefix
self.log.debug("Using %s as the gcc install location", self.gcc_prefix)

def _set_dynamic_linker(self):
"""Set the dynamic linker for the build if not the default one."""
if self.sysroot:
Expand Down Expand Up @@ -792,7 +791,17 @@ def configure_step(self):
]
apply_regex_substitutions(lit_cfg_file, regex_subs)

self._set_gcc_prefix()
# For LLVM 18+ config files should be used and this option is deprecated and causes an error in 19
# But the --gcc-toolchain and --gcc-install-dir for flang are not supported before LLVM 19
# https://github.com/llvm/llvm-project/pull/87360
if LooseVersion(self.version) < '19':
self.log.debug("Using GCC_INSTALL_PREFIX")
self.general_opts['GCC_INSTALL_PREFIX'] = self.gcc_root
else:
# See https://github.com/llvm/llvm-project/pull/85891#issuecomment-2021370667
self.log.debug("Using '--gcc-install-dir' in CMAKE_C_FLAGS and CMAKE_CXX_FLAGS")
self.runtimes_cmake_args['CMAKE_C_FLAGS'] += [f'--gcc-install-dir={self.gcc_prefix}']
self.runtimes_cmake_args['CMAKE_CXX_FLAGS'] += [f'--gcc-install-dir={self.gcc_prefix}']

# If we don't want to build with CUDA (not in dependencies) trick CMakes FindCUDA module into not finding it by
# using the environment variable which is used as-is and later checked for a falsy value when determining
Expand Down Expand Up @@ -874,7 +883,6 @@ def configure_step3(self):

def _create_compiler_config_file(self, installdir):
"""Create a config file for the compiler to point to the correct GCC installation."""
self._set_gcc_prefix()

# This is only needed for LLVM >= 19, as the --gcc-install-dir option was introduced then
if LooseVersion(self.version) < '19':
Expand Down Expand Up @@ -1502,7 +1510,6 @@ def sanity_check_step(self, custom_paths=None, custom_commands=None, *args, **kw
'dirs': check_dirs,
}

self._set_gcc_prefix()
if lib_dir_runtime:
# Required for 'clang -v' to work if linked to LLVM runtimes
with _wrap_env(ld_path=os.path.join(self.installdir, lib_dir_runtime)):
Expand Down