Skip to content

Commit dc7c566

Browse files
committed
Use property for gcc_prefix/gcc_root in LLVM easyblock
1 parent 39b68fa commit dc7c566

File tree

1 file changed

+32
-26
lines changed

1 file changed

+32
-26
lines changed

easybuild/easyblocks/l/llvm.py

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,8 @@ def __init__(self, *args, **kwargs):
244244
else:
245245
self.final_projects = ['llvm']
246246
self.final_runtimes = []
247-
self.gcc_prefix = None
247+
self._gcc_prefix = None
248+
self._gcc_root = None
248249
self.runtimes_cmake_args = {
249250
'CMAKE_C_COMPILER': [],
250251
'CMAKE_C_FLAGS': [],
@@ -321,9 +322,8 @@ def __init__(self, *args, **kwargs):
321322
else:
322323
self.log.warning("OpenMP offloading is included with the OpenMP runtime for LLVM < 19")
323324

324-
if self.cfg['build_openmp_tools']:
325-
if not self.cfg['build_openmp']:
326-
raise EasyBuildError("Building OpenMP tools requires building OpenMP runtime")
325+
if self.cfg['build_openmp_tools'] and not self.cfg['build_openmp']:
326+
raise EasyBuildError("Building OpenMP tools requires building OpenMP runtime")
327327

328328
if self.cfg['usepolly']:
329329
self.final_projects.append('polly')
@@ -462,6 +462,23 @@ def __init__(self, *args, **kwargs):
462462
self._cmakeopts = {}
463463
self._cfgopts = list(filter(None, self.cfg.get('configopts', '').split()))
464464

465+
@property
466+
def gcc_prefix(self):
467+
"""Return the GCC prefix (versioned folder in <gcc_root>/lib)."""
468+
self._set_gcc_prefix_probs()
469+
return self._gcc_prefix
470+
471+
@property
472+
def gcc_root(self):
473+
"""Return the GCC root folder from dependencies/toolchain."""
474+
self._set_gcc_prefix_probs()
475+
return self._gcc_root
476+
477+
def _set_gcc_prefix_probs(self):
478+
"""Set properties of currently loaded GCC installation"""
479+
self._gcc_root, self._gcc_prefix = self._get_gcc_prefix()
480+
self.log.debug("Using %s as the gcc install location", self._gcc_prefix)
481+
465482
@property
466483
def llvm_src_dir(self):
467484
"""Return root source directory of LLVM (containing all components)"""
@@ -572,24 +589,6 @@ def _get_gcc_libpath(strict=False):
572589
return ''
573590
return os.path.join(gcc_root, 'lib64')
574591

575-
def _set_gcc_prefix(self):
576-
"""Set the GCC prefix for the build."""
577-
if self.gcc_prefix is None:
578-
gcc_root, gcc_prefix = self._get_gcc_prefix()
579-
580-
# --gcc-toolchain and --gcc-install-dir for flang are not supported before LLVM 19
581-
# https://github.com/llvm/llvm-project/pull/87360
582-
if LooseVersion(self.version) < LooseVersion('19'):
583-
self.log.debug("Using GCC_INSTALL_PREFIX")
584-
general_opts['GCC_INSTALL_PREFIX'] = gcc_root
585-
else:
586-
# See https://github.com/llvm/llvm-project/pull/85891#issuecomment-2021370667
587-
self.log.debug("Using '--gcc-install-dir' in CMAKE_C_FLAGS and CMAKE_CXX_FLAGS")
588-
self.runtimes_cmake_args['CMAKE_C_FLAGS'] += ['--gcc-install-dir=%s' % gcc_prefix]
589-
self.runtimes_cmake_args['CMAKE_CXX_FLAGS'] += ['--gcc-install-dir=%s' % gcc_prefix]
590-
591-
self.gcc_prefix = gcc_prefix
592-
self.log.debug("Using %s as the gcc install location", self.gcc_prefix)
593592

594593
def _set_dynamic_linker(self):
595594
"""Set the dynamic linker for the build if not the default one."""
@@ -761,15 +760,24 @@ def configure_step(self):
761760
]
762761
apply_regex_substitutions(lit_cfg_file, regex_subs)
763762

764-
self._set_gcc_prefix()
763+
# --gcc-toolchain and --gcc-install-dir for flang are not supported before LLVM 19
764+
# https://github.com/llvm/llvm-project/pull/87360
765+
if LooseVersion(self.version) < '19':
766+
self.log.debug("Using GCC_INSTALL_PREFIX")
767+
general_opts['GCC_INSTALL_PREFIX'] = self.gcc_root
768+
else:
769+
# See https://github.com/llvm/llvm-project/pull/85891#issuecomment-2021370667
770+
self.log.debug("Using '--gcc-install-dir' in CMAKE_C_FLAGS and CMAKE_CXX_FLAGS")
771+
self.runtimes_cmake_args['CMAKE_C_FLAGS'] += [f'--gcc-install-dir={self.gcc_prefix}']
772+
self.runtimes_cmake_args['CMAKE_CXX_FLAGS'] += [f'--gcc-install-dir={self.gcc_prefix}']
765773

766774
# If we don't want to build with CUDA (not in dependencies) trick CMakes FindCUDA module into not finding it by
767775
# using the environment variable which is used as-is and later checked for a falsy value when determining
768776
# whether CUDA was found
769777
if not get_software_root('CUDA'):
770778
setvar('CUDA_NVCC_EXECUTABLE', 'IGNORE')
771779

772-
if self.cfg['build_openmp_offload'] and LooseVersion('19') <= LooseVersion(self.version) < LooseVersion('20'):
780+
if self.cfg['build_openmp_offload'] and '19' <= LooseVersion(self.version) < '20':
773781
gpu_archs = []
774782
gpu_archs += ['sm_%s' % cc for cc in self.cuda_cc]
775783
gpu_archs += self.amd_gfx
@@ -843,7 +851,6 @@ def configure_step3(self):
843851

844852
def _create_compiler_config_file(self, installdir):
845853
"""Create a config file for the compiler to point to the correct GCC installation."""
846-
self._set_gcc_prefix()
847854
bin_dir = os.path.join(installdir, 'bin')
848855
opts = [f'--gcc-install-dir={self.gcc_prefix}']
849856

@@ -1475,7 +1482,6 @@ def sanity_check_step(self, custom_paths=None, custom_commands=None, extension=F
14751482
'dirs': check_dirs,
14761483
}
14771484

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

0 commit comments

Comments
 (0)