Skip to content

Commit fce4ceb

Browse files
committed
Use property for gcc_prefix/gcc_root in LLVM easyblock
1 parent 34bf48e commit fce4ceb

File tree

1 file changed

+32
-27
lines changed

1 file changed

+32
-27
lines changed

easybuild/easyblocks/l/llvm.py

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,8 @@ def __init__(self, *args, **kwargs):
249249
else:
250250
self.final_projects = ['llvm']
251251
self.final_runtimes = []
252-
self.gcc_prefix = None
252+
self._gcc_prefix = None
253+
self._gcc_root = None
253254
self.runtimes_cmake_args = {
254255
'CMAKE_C_COMPILER': [],
255256
'CMAKE_C_FLAGS': [],
@@ -326,9 +327,8 @@ def __init__(self, *args, **kwargs):
326327
else:
327328
self.log.warning("OpenMP offloading is included with the OpenMP runtime for LLVM < 19")
328329

329-
if self.cfg['build_openmp_tools']:
330-
if not self.cfg['build_openmp']:
331-
raise EasyBuildError("Building OpenMP tools requires building OpenMP runtime")
330+
if self.cfg['build_openmp_tools'] and not self.cfg['build_openmp']:
331+
raise EasyBuildError("Building OpenMP tools requires building OpenMP runtime")
332332

333333
if self.cfg['usepolly']:
334334
self.final_projects.append('polly')
@@ -467,6 +467,23 @@ def __init__(self, *args, **kwargs):
467467
self._cmakeopts = {}
468468
self._cfgopts = list(filter(None, self.cfg.get('configopts', '').split()))
469469

470+
@property
471+
def gcc_prefix(self):
472+
"""Return the GCC prefix (versioned folder in <gcc_root>/lib)."""
473+
self._set_gcc_prefix_probs()
474+
return self._gcc_prefix
475+
476+
@property
477+
def gcc_root(self):
478+
"""Return the GCC root folder from dependencies/toolchain."""
479+
self._set_gcc_prefix_probs()
480+
return self._gcc_root
481+
482+
def _set_gcc_prefix_probs(self):
483+
"""Set properties of currently loaded GCC installation"""
484+
self._gcc_root, self._gcc_prefix = self._get_gcc_prefix()
485+
self.log.debug("Using %s as the gcc install location", self._gcc_prefix)
486+
470487
@property
471488
def llvm_src_dir(self):
472489
"""Return root source directory of LLVM (containing all components)"""
@@ -587,25 +604,6 @@ def _get_gcc_libpath(strict=False):
587604
return ''
588605
return os.path.join(gcc_root, 'lib64')
589606

590-
def _set_gcc_prefix(self):
591-
"""Set the GCC prefix for the build."""
592-
if self.gcc_prefix is None:
593-
gcc_root, gcc_prefix = self._get_gcc_prefix()
594-
595-
# --gcc-toolchain and --gcc-install-dir for flang are not supported before LLVM 19
596-
# https://github.com/llvm/llvm-project/pull/87360
597-
if LooseVersion(self.version) < LooseVersion('19'):
598-
self.log.debug("Using GCC_INSTALL_PREFIX")
599-
general_opts['GCC_INSTALL_PREFIX'] = gcc_root
600-
else:
601-
# See https://github.com/llvm/llvm-project/pull/85891#issuecomment-2021370667
602-
self.log.debug("Using '--gcc-install-dir' in CMAKE_C_FLAGS and CMAKE_CXX_FLAGS")
603-
self.runtimes_cmake_args['CMAKE_C_FLAGS'] += ['--gcc-install-dir=%s' % gcc_prefix]
604-
self.runtimes_cmake_args['CMAKE_CXX_FLAGS'] += ['--gcc-install-dir=%s' % gcc_prefix]
605-
606-
self.gcc_prefix = gcc_prefix
607-
self.log.debug("Using %s as the gcc install location", self.gcc_prefix)
608-
609607
def _set_dynamic_linker(self):
610608
"""Set the dynamic linker for the build if not the default one."""
611609
if self.sysroot:
@@ -776,15 +774,24 @@ def configure_step(self):
776774
]
777775
apply_regex_substitutions(lit_cfg_file, regex_subs)
778776

779-
self._set_gcc_prefix()
777+
# --gcc-toolchain and --gcc-install-dir for flang are not supported before LLVM 19
778+
# https://github.com/llvm/llvm-project/pull/87360
779+
if LooseVersion(self.version) < '19':
780+
self.log.debug("Using GCC_INSTALL_PREFIX")
781+
general_opts['GCC_INSTALL_PREFIX'] = self.gcc_root
782+
else:
783+
# See https://github.com/llvm/llvm-project/pull/85891#issuecomment-2021370667
784+
self.log.debug("Using '--gcc-install-dir' in CMAKE_C_FLAGS and CMAKE_CXX_FLAGS")
785+
self.runtimes_cmake_args['CMAKE_C_FLAGS'] += [f'--gcc-install-dir={self.gcc_prefix}']
786+
self.runtimes_cmake_args['CMAKE_CXX_FLAGS'] += [f'--gcc-install-dir={self.gcc_prefix}']
780787

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

787-
if self.cfg['build_openmp_offload'] and LooseVersion('19') <= LooseVersion(self.version) < LooseVersion('20'):
794+
if self.cfg['build_openmp_offload'] and '19' <= LooseVersion(self.version) < '20':
788795
gpu_archs = []
789796
gpu_archs += ['sm_%s' % cc for cc in self.cuda_cc]
790797
gpu_archs += self.amd_gfx
@@ -858,7 +865,6 @@ def configure_step3(self):
858865

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

863869
# This is only needed for LLVM >= 19, as the --gcc-install-dir option was introduced then
864870
if LooseVersion(self.version) < LooseVersion('19'):
@@ -1491,7 +1497,6 @@ def sanity_check_step(self, custom_paths=None, custom_commands=None, extension=F
14911497
'dirs': check_dirs,
14921498
}
14931499

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

0 commit comments

Comments
 (0)