spack/var/spack/repos/builtin/packages/clingo-bootstrap/package.py
Massimiliano Culpo d5fa509b07
clingo: modify recipe for bootstrapping (#22354)
* clingo: modify recipe for bootstrapping

Modifications:
- clingo builds with shared Python only if ^python+shared
- avoid building the clingo app for bootstrapping
- don't link to libpython when bootstrapping

* Remove option that breaks on linux

* Give more hints for the current Python

* Disable CLINGO_BUILD_PY_SHARED for bootstrapping

* bootstrapping: try to detect the current python from std library

This is much faster than calling external executables

* Fix compatibility with Python 2.6

* Give hints on which compiler and OS to use when bootstrapping

This change hints which compiler to use for bootstrapping clingo
(either GCC or Apple Clang on MacOS). On Cray platforms it also
hints to build for the frontend system, where software is meant
to be installed.

* Use spec_for_current_python to constrain module requirement
2021-03-26 12:43:41 -05:00

71 lines
2.5 KiB
Python

# Copyright 2013-2020 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
from spack.pkg.builtin.clingo import Clingo
import spack.compilers
class ClingoBootstrap(Clingo):
"""Clingo with some options used for bootstrapping"""
maintainers = ['alalazo']
variant('build_type', default='Release', values=('Release',),
description='CMake build type')
# CMake at version 3.16.0 or higher has the possibility to force the
# Python interpreter, which is crucial to build against external Python
# in environment where more than one interpreter is in the same prefix
depends_on('cmake@3.16.0:', type='build')
# On Linux we bootstrap with GCC
for compiler_spec in [
c for c in spack.compilers.supported_compilers()
if c != 'gcc'
]:
conflicts('%{0}'.format(compiler_spec), when='platform=linux',
msg='GCC is required to bootstrap clingo on Linux')
conflicts('%{0}'.format(compiler_spec), when='platform=cray',
msg='GCC is required to bootstrap clingo on Cray')
conflicts(
'%gcc@:5.99.99', msg='C++14 support is required to bootstrap clingo'
)
# On Darwin we bootstrap with Apple Clang
for compiler_spec in [
c for c in spack.compilers.supported_compilers()
if c != 'apple-clang'
]:
conflicts('%{0}'.format(compiler_spec), when='platform=darwin',
msg='Apple-clang is required to bootstrap clingo on MacOS')
# Clingo needs the Python module to be usable by Spack
conflicts('~python', msg='Python support is required to bootstrap Spack')
@property
def cmake_py_shared(self):
return self.define('CLINGO_BUILD_PY_SHARED', 'OFF')
def cmake_args(self):
args = super(ClingoBootstrap, self).cmake_args()
args.extend([
# Avoid building the clingo executable
self.define('CLINGO_BUILD_APPS', 'OFF'),
])
return args
def setup_build_environment(self, env):
if '%apple-clang platform=darwin' in self.spec:
opts = '-mmacosx-version-min=10.13'
elif '%gcc' in self.spec:
# This is either linux or cray
opts = '-static-libstdc++ -static-libgcc -Wl,--exclude-libs,ALL'
else:
msg = 'unexpected compiler for spec "{0}"'.format(self.spec)
raise RuntimeError(msg)
env.set('CXXFLAGS', opts)
env.set('LDFLAGS', opts)