Skip to content

Commit

Permalink
Merge pull request #2626 from zarybnicky/20211125150126_new_pr_tbb
Browse files Browse the repository at this point in the history
enhance tbb easyblock by adding option to build Python bindings
  • Loading branch information
boegel authored Nov 25, 2021
2 parents 582f0fe + 97f47db commit f15070e
Showing 1 changed file with 44 additions and 18 deletions.
62 changes: 44 additions & 18 deletions easybuild/easyblocks/t/tbb.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
from easybuild.easyblocks.generic.configuremake import ConfigureMake
from easybuild.easyblocks.generic.intelbase import INSTALL_MODE_NAME_2015, INSTALL_MODE_2015
from easybuild.easyblocks.generic.intelbase import IntelBase, ACTIVATION_NAME_2012, LICENSE_FILE_NAME_2012
from easybuild.framework.easyconfig import CUSTOM
from easybuild.tools.filetools import move_file, symlink
from easybuild.tools.build_log import EasyBuildError
from easybuild.tools.modules import get_software_version
Expand Down Expand Up @@ -75,6 +76,15 @@ def get_tbb_gccprefix(libpath):
class EB_tbb(IntelBase, ConfigureMake):
"""EasyBlock for tbb, threading building blocks"""

@staticmethod
def extra_options():
extra_vars = IntelBase.extra_options()
extra_vars.update(ConfigureMake.extra_options())
extra_vars.update({
'with_python': [False, "Should the TBB4Python bindings be built as well?", CUSTOM],
})
return extra_vars

def __init__(self, *args, **kwargs):
"""Initialisation of custom class variables for tbb"""
super(EB_tbb, self).__init__(*args, **kwargs)
Expand All @@ -95,6 +105,11 @@ def __init__(self, *args, **kwargs):
self.build_in_installdir = True
self.cfg['requires_runtime_license'] = False

if self.toolchain.is_system_toolchain():
self.tbb_subdir = 'tbb'
else:
self.tbb_subdir = ''

def extract_step(self):
"""Extract sources."""
if not self.toolchain.is_system_toolchain():
Expand All @@ -119,6 +134,11 @@ def build_step(self):
self.cfg.update('buildopts', 'compiler="%s"' % os.getenv('CC'))
ConfigureMake.build_step(self)

if self.cfg['with_python']:
# Uses the Makefile target `python`
self.cfg.update('buildopts', 'python')
ConfigureMake.build_step(self)

def _has_cmake(self):
"""Check if CMake is included in the build deps"""
build_deps = self.cfg.dependencies(build_only=True)
Expand Down Expand Up @@ -188,16 +208,15 @@ def install_step(self):
symlink(os.path.relpath(root_lib_path, os.path.join(libpath)), libpath, use_abspath_source=False)

# Install CMake config files if possible
if self._has_cmake():
if LooseVersion(self.version) >= LooseVersion('2020.0'):
cmake_install_dir = os.path.join(root_lib_path, 'cmake', 'TBB')
cmd = [
'cmake',
'-DINSTALL_DIR=' + cmake_install_dir,
'-DSYSTEM_NAME=Linux',
'-P tbb_config_installer.cmake',
]
run_cmd(' '.join(cmd), path=os.path.join(self.builddir, 'cmake'))
if self._has_cmake() and LooseVersion(self.version) >= LooseVersion('2020.0'):
cmake_install_dir = os.path.join(root_lib_path, 'cmake', 'TBB')
cmd = [
'cmake',
'-DINSTALL_DIR=' + cmake_install_dir,
'-DSYSTEM_NAME=Linux',
'-P tbb_config_installer.cmake',
]
run_cmd(' '.join(cmd), path=os.path.join(self.builddir, 'cmake'))

def sanity_check_step(self):
"""Custom sanity check for TBB"""
Expand All @@ -208,6 +227,8 @@ def sanity_check_step(self):
],
'dirs': [],
}
custom_commands = []

if self.toolchain.is_system_toolchain():
custom_paths['dirs'].extend(os.path.join('tbb', p) for p in
('bin', 'lib', 'libs', os.path.join('include', 'tbb')))
Expand All @@ -224,21 +245,26 @@ def sanity_check_step(self):
os.path.join('lib', 'cmake', 'TBB', 'TBBConfigVersion.cmake'),
])

super(EB_tbb, self).sanity_check_step(custom_paths=custom_paths)
if self.cfg['with_python']:
custom_paths['dirs'].append(os.path.join(self.tbb_subdir, 'python'))
custom_commands.extend(['python -c "import tbb"'])

super(EB_tbb, self).sanity_check_step(custom_paths=custom_paths, custom_commands=custom_commands)

def make_module_extra(self):
"""Add correct path to lib to LD_LIBRARY_PATH. and intel license file"""
txt = super(EB_tbb, self).make_module_extra()

if self.toolchain.is_system_toolchain():
tbb_subdir = 'tbb'
txt += self.module_generator.prepend_paths('CPATH', [os.path.join(tbb_subdir, 'include')])
else:
tbb_subdir = ''
txt += self.module_generator.prepend_paths('CPATH', [os.path.join(self.tbb_subdir, 'include')])

root_dir = os.path.join(self.installdir, self.tbb_subdir)
txt += self.module_generator.set_environment('TBBROOT', root_dir)
# TBB_ROOT used e.g. by FindTBB.cmake
txt += self.module_generator.set_environment('TBB_ROOT', root_dir)

txt += self.module_generator.set_environment('TBBROOT', os.path.join(self.installdir, tbb_subdir))
# Used e.g. by FindTBB.cmake
txt += self.module_generator.set_environment('TBB_ROOT', os.path.join(self.installdir, tbb_subdir))
if self.cfg['with_python']:
txt += self.module_generator.prepend_paths('PYTHONPATH', [os.path.join(self.tbb_subdir, 'python')])

return txt

Expand Down

0 comments on commit f15070e

Please sign in to comment.