Skip to content

Commit 0c8258f

Browse files
authored
Merge pull request #2402 from Flamefire/20210427141216_new_pr_lhmgfcewOI
use explicit build toolset and compiler path in Boost easyblock
2 parents e073d84 + 043fcff commit 0c8258f

File tree

1 file changed

+33
-10
lines changed

1 file changed

+33
-10
lines changed

easybuild/easyblocks/b/boost.py

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@
4949
from easybuild.framework.easyblock import EasyBlock
5050
from easybuild.framework.easyconfig import CUSTOM
5151
from easybuild.tools.build_log import EasyBuildError
52-
from easybuild.tools.filetools import copy, mkdir, write_file
52+
from easybuild.tools.config import ERROR
53+
from easybuild.tools.filetools import apply_regex_substitutions, copy, mkdir, which, write_file
5354
from easybuild.tools.modules import get_software_root, get_software_version
5455
from easybuild.tools.run import run_cmd
5556
from easybuild.tools.systemtools import AARCH64, POWER, UNKNOWN
@@ -78,7 +79,9 @@ def extra_options():
7879
extra_vars = {
7980
'boost_mpi': [False, "Build mpi boost module", CUSTOM],
8081
'boost_multi_thread': [False, "Build boost with multi-thread option", CUSTOM],
81-
'toolset': [None, "Toolset to use for Boost configuration ('--with-toolset for bootstrap.sh')", CUSTOM],
82+
'toolset': [None, "Toolset to use for Boost configuration ('--with-toolset' for bootstrap.sh)", CUSTOM],
83+
'build_toolset': [None, "Toolset to use for Boost compilation "
84+
"('toolset' for b2, default calculated from toolset)", CUSTOM],
8285
'mpi_launcher': [None, "Launcher to use when running MPI regression tests", CUSTOM],
8386
'only_python_bindings': [False, "Only install Boost.Python library providing Python bindings", CUSTOM],
8487
'use_glibcxx11_abi': [None, "Use the GLIBCXX11 ABI", CUSTOM],
@@ -139,20 +142,38 @@ def configure_step(self):
139142
tup = (self.cfg['preconfigopts'], toolset, self.objdir, self.cfg['configopts'])
140143
run_cmd(cmd % tup, log_all=True, simple=True)
141144

145+
# Use build_toolset if specified or the bootstrap toolset without the OS suffix
146+
self.toolset = self.cfg['build_toolset'] or re.sub('-linux$', '', toolset)
147+
148+
user_config = []
149+
150+
# Explicitely set the compiler path to avoid B2 checking some standard paths like /opt
151+
cxx = os.getenv('CXX')
152+
if cxx:
153+
cxx = which(cxx, on_error=ERROR)
154+
# Remove default toolset config which may lead to duplicate toolsets (e.g. for intel-linux)
155+
apply_regex_substitutions('project-config.jam', [('using %s ;' % toolset, '')])
156+
# Add our toolset config with no version and full path to compiler
157+
user_config.append("using %s : : %s ;" % (self.toolset, cxx))
158+
142159
if self.cfg['boost_mpi']:
143160

144161
self.toolchain.options['usempi'] = True
145162
# configure the boost mpi module
146163
# http://www.boost.org/doc/libs/1_47_0/doc/html/mpi/getting_started.html
147164
# let Boost.Build know to look here for the config file
148165

149-
txt = ''
150166
# Check if using a Cray toolchain and configure MPI accordingly
151167
if self.toolchain.toolchain_family() == toolchain.CRAYPE:
152168
if self.toolchain.PRGENV_MODULE_NAME_SUFFIX == 'gnu':
153169
craympichdir = os.getenv('CRAY_MPICH2_DIR')
154170
craygccversion = os.getenv('GCC_VERSION')
155-
txt = '\n'.join([
171+
# We configure the gcc toolchain below, so make sure the EC doesn't use another toolset
172+
if self.toolset != 'gcc':
173+
raise EasyBuildError("For the cray toolchain the 'gcc' toolset must be used.")
174+
# Remove the previous "using gcc" line add above (via self.toolset) if present
175+
user_config = [x for x in user_config if not x.startswith('using gcc :')]
176+
user_config.extend([
156177
'local CRAY_MPICH2_DIR = %s ;' % craympichdir,
157178
'using gcc ',
158179
': %s' % craygccversion,
@@ -170,9 +191,9 @@ def configure_step(self):
170191
else:
171192
raise EasyBuildError("Bailing out: only PrgEnv-gnu supported for now")
172193
else:
173-
txt = "using mpi : %s ;" % os.getenv("MPICXX")
194+
user_config.append("using mpi : %s ;" % os.getenv("MPICXX"))
174195

175-
write_file('user-config.jam', txt, append=True)
196+
write_file('user-config.jam', '\n'.join(user_config), append=True)
176197

177198
def build_boost_variant(self, bjamoptions, paracmd):
178199
"""Build Boost library with specified options for bjam."""
@@ -184,12 +205,14 @@ def build_boost_variant(self, bjamoptions, paracmd):
184205
self.cfg['preinstallopts'], self.bjamcmd, bjamoptions, paracmd, self.cfg['installopts'])
185206
run_cmd(cmd, log_all=True, simple=True)
186207
# clean up before proceeding with next build
187-
run_cmd("./%s --clean-all" % self.bjamcmd, log_all=True, simple=True)
208+
run_cmd("./%s %s --clean-all" % (self.bjamcmd, bjamoptions), log_all=True, simple=True)
188209

189210
def build_step(self):
190211
"""Build Boost with bjam tool."""
191212

192-
bjamoptions = " --prefix=%s" % self.objdir
213+
bjamoptions = " --prefix=%s --user-config=user-config.jam" % self.objdir
214+
if 'toolset=' not in self.cfg['buildopts']:
215+
bjamoptions += " toolset=" + self.toolset
193216

194217
cxxflags = os.getenv('CXXFLAGS')
195218
# only disable -D_GLIBCXX_USE_CXX11_ABI if use_glibcxx11_abi was explicitly set to False
@@ -224,7 +247,7 @@ def build_step(self):
224247

225248
if self.cfg['boost_mpi']:
226249
self.log.info("Building boost_mpi library")
227-
self.build_boost_variant(bjamoptions + " --user-config=user-config.jam --with-mpi", paracmd)
250+
self.build_boost_variant(bjamoptions + " --with-mpi", paracmd)
228251

229252
if self.cfg['boost_multi_thread']:
230253
self.log.info("Building boost with multi threading")
@@ -233,7 +256,7 @@ def build_step(self):
233256
# if both boost_mpi and boost_multi_thread are enabled, build boost mpi with multi-thread support
234257
if self.cfg['boost_multi_thread'] and self.cfg['boost_mpi']:
235258
self.log.info("Building boost_mpi with multi threading")
236-
extra_bjamoptions = " --user-config=user-config.jam --with-mpi threading=multi --layout=tagged"
259+
extra_bjamoptions = " --with-mpi threading=multi --layout=tagged"
237260
self.build_boost_variant(bjamoptions + extra_bjamoptions, paracmd)
238261

239262
# install remainder of boost libraries

0 commit comments

Comments
 (0)