Skip to content
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

Make MesonNinja respect the toolchainopts with buildtype as well as --debug and --optimization flags #3454

Merged
merged 7 commits into from
Oct 11, 2024
32 changes: 30 additions & 2 deletions easybuild/easyblocks/generic/mesonninja.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,28 @@ def extra_options(extra_vars=None):
extra_vars.update({
'build_dir': [None, "build_dir to pass to meson", CUSTOM],
'build_cmd': [DEFAULT_BUILD_CMD, "Build command to use", CUSTOM],
'build_type': [None, "Build type for meson, e.g. release."
"Replaces use of toolchain options debug, noopt, lowopt, opt", CUSTOM],
'ndebug': [True, "Sets -Db_ndebug which in turn defines NDEBUG for C/C++ builds."
"This disabled costly asserts in code, typical for production.", CUSTOM],
'configure_cmd': [DEFAULT_CONFIGURE_CMD, "Configure command to use", CUSTOM],
'install_cmd': [DEFAULT_INSTALL_CMD, "Install command to use", CUSTOM],
'separate_build_dir': [True, "Perform build in a separate directory", CUSTOM],
})
return extra_vars

@property
def optimization(self):
"""Optimization level"""
if self.toolchain.options.get('noopt', False):
return 0
elif self.toolchain.options.get('lowopt', False):
return 1
elif self.toolchain.options.get('opt', False):
return 3
else:
return 2

def configure_step(self, cmd_prefix=''):
"""
Configure with Meson.
Expand Down Expand Up @@ -92,11 +108,23 @@ def configure_step(self, cmd_prefix=''):

build_dir = self.cfg.get('build_dir') or self.start_dir

cmd = "%(preconfigopts)s %(configure_cmd)s --prefix %(installdir)s %(configopts)s %(source_dir)s" % {
# Build type is either specified directly or via --optimization and --debug flags.
if self.cfg['build_type'] is not None:
build_type = '--buildtype=' + self.cfg['build_type']
else:
build_type = '--optimization=%(optimization)s %(debug)s' % {
'optimization': self.optimization,
'debug': '--debug' if self.toolchain.options.get('debug', False) else '',
}

cmd = ("%(preconfigopts)s %(configure_cmd)s --prefix %(installdir)s %(build_type)s %(configopts)s "
"-Db_ndebug=%(ndebug)s %(source_dir)s") % {
'build_type': build_type,
'configopts': self.cfg['configopts'],
'configure_cmd': configure_cmd,
'installdir': self.installdir,
'preconfigopts': self.cfg['preconfigopts'],
'ndebug': str(self.cfg.get('ndebug')).lower(),
'source_dir': build_dir,
}
res = run_shell_cmd(cmd)
Expand All @@ -112,7 +140,7 @@ def build_step(self, verbose=False, path=None):
if self.cfg['parallel']:
parallel = "-j %s" % self.cfg['parallel']

cmd = "%(prebuildopts)s %(build_cmd)s %(parallel)s %(buildopts)s" % {
cmd = "%(prebuildopts)s %(build_cmd)s -v %(parallel)s %(buildopts)s" % {
'buildopts': self.cfg['buildopts'],
'build_cmd': build_cmd,
'parallel': parallel,
Expand Down
Loading