mirror of https://github.com/mamba-org/mamba.git
94 lines
3.1 KiB
Python
94 lines
3.1 KiB
Python
from setuptools import setup, Extension
|
|
from setuptools.command.build_ext import build_ext
|
|
import sys, os, platform
|
|
import setuptools
|
|
|
|
__version__ = '0.0.1'
|
|
|
|
class get_pybind_include(object):
|
|
"""Helper class to determine the pybind11 include path
|
|
The purpose of this class is to postpone importing pybind11
|
|
until it is actually installed, so that the ``get_include()``
|
|
method can be invoked. """
|
|
|
|
def __init__(self, user=False):
|
|
self.user = user
|
|
|
|
def __str__(self):
|
|
import pybind11
|
|
return pybind11.get_include(self.user)
|
|
|
|
print("Looking for libsolv in: ", sys.prefix)
|
|
|
|
ext_modules = [
|
|
Extension(
|
|
'mamba.mamba_api',
|
|
['include/py_interface.cpp', 'include/parsing.cpp', 'include/solver.cpp', 'include/thirdparty/simdjson/simdjson.cpp'],
|
|
include_dirs=[
|
|
os.path.join(sys.prefix, 'include/'),
|
|
get_pybind_include(),
|
|
get_pybind_include(user=True)
|
|
],
|
|
library_dirs=[os.path.join(sys.prefix, 'lib/')],
|
|
libraries=['solv'],
|
|
language='c++'
|
|
),
|
|
]
|
|
|
|
# As of Python 3.6, CCompiler has a `has_flag` method.
|
|
# cf http://bugs.python.org/issue26689
|
|
def has_flag(compiler, flagname):
|
|
"""Return a boolean indicating whether a flag name is supported on
|
|
the specified compiler.
|
|
"""
|
|
import tempfile
|
|
with tempfile.NamedTemporaryFile('w', suffix='.cpp') as f:
|
|
f.write('int main (int argc, char **argv) { return 0; }')
|
|
try:
|
|
compiler.compile([f.name], extra_postargs=[flagname])
|
|
except setuptools.distutils.errors.CompileError:
|
|
return False
|
|
return True
|
|
|
|
class BuildExt(build_ext):
|
|
"""A custom build extension for adding compiler-specific options."""
|
|
c_opts = {
|
|
'msvc': ['/EHsc', '/std:c++latest', '/arch:AVX2', '/Ox'],
|
|
'unix': ['-std=c++17', '-march=core-avx2', '-O3'],
|
|
}
|
|
|
|
if sys.platform == 'darwin':
|
|
c_opts['unix'] += ['-stdlib=libc++', '-mmacosx-version-min=10.7']
|
|
if not has_flag(self.compiler, '-std=c++17'):
|
|
c_opts.remove('-std=c++17')
|
|
c_opts.append('-std=c++1z')
|
|
|
|
def build_extensions(self):
|
|
ct = self.compiler.compiler_type
|
|
opts = self.c_opts.get(ct, [])
|
|
if ct == 'unix':
|
|
opts.append('-DVERSION_INFO="%s"' % self.distribution.get_version())
|
|
if has_flag(self.compiler, '-fvisibility=hidden'):
|
|
opts.append('-fvisibility=hidden')
|
|
elif ct == 'msvc':
|
|
opts.append('/DVERSION_INFO=\\"%s\\"' % self.distribution.get_version())
|
|
for ext in self.extensions:
|
|
ext.extra_compile_args = opts
|
|
build_ext.build_extensions(self)
|
|
|
|
setup(
|
|
name='mamba',
|
|
version=__version__,
|
|
author='Wolf Vollprecht',
|
|
author_email='w.vollprecht@gmail.com',
|
|
url='https://github.com/wolfv/mamba',
|
|
description='Faster than a conda?!',
|
|
packages=['mamba'],
|
|
scripts=['bin/mamba'],
|
|
long_description='A (hopefully faster) reimplementation of the slow bits of conda.',
|
|
ext_modules=ext_modules,
|
|
install_requires=['pybind11>=2.2'],
|
|
cmdclass={'build_ext': BuildExt},
|
|
zip_safe=False,
|
|
)
|