diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0047755fcbc3ec26d86b3c24075354534c00ef13..1687d1680d5fd95015501c139160743e5a1dd980 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,7 +2,7 @@ script: - export PY_EXE=python2.7 - export PYOPENCL_TEST=amd:pu - - export EXTRA_INSTALL="numpy mako scipy pyfmmlib" + - export EXTRA_INSTALL="pybind11 numpy mako scipy pyfmmlib" - echo "CL_ENABLE_GL = True" > siteconf.py - curl -L -O -k https://gitlab.tiker.net/inducer/ci-support/raw/master/build-and-test-py-project.sh - ". ./build-and-test-py-project.sh" @@ -18,7 +18,7 @@ Python 3.6 Intel CPU: script: - export PY_EXE=python3.6 - export PYOPENCL_TEST="intel(r):pu" - - export EXTRA_INSTALL="numpy mako" + - export EXTRA_INSTALL="pybind11 numpy mako" - curl -L -O -k https://gitlab.tiker.net/inducer/ci-support/raw/master/build-and-test-py-project.sh - ". ./build-and-test-py-project.sh" allow_failure: true @@ -32,7 +32,7 @@ Python 3.6 AMD CPU: script: - export PY_EXE=python3.6 - export PYOPENCL_TEST=amd:pu - - export EXTRA_INSTALL="numpy mako" + - export EXTRA_INSTALL="pybind11 numpy mako" - curl -L -O -k https://gitlab.tiker.net/inducer/ci-support/raw/master/build-and-test-py-project.sh - ". ./build-and-test-py-project.sh" allow_failure: true @@ -46,7 +46,7 @@ Python 3.6 Titan X: script: - export PY_EXE=python3.5 - export PYOPENCL_TEST=nvi:titan - - export EXTRA_INSTALL="numpy mako" + - export EXTRA_INSTALL="pybind11 numpy mako" - curl -L -O -k https://gitlab.tiker.net/inducer/ci-support/raw/master/build-and-test-py-project.sh - ". ./build-and-test-py-project.sh" tags: @@ -59,7 +59,7 @@ Python 3.6 K40: script: - export PY_EXE=python3.6 - export PYOPENCL_TEST=nvi:k40 - - export EXTRA_INSTALL="numpy mako" + - export EXTRA_INSTALL="pybind11 numpy mako" - curl -L -O -k https://gitlab.tiker.net/inducer/ci-support/raw/master/build-and-test-py-project.sh - ". ./build-and-test-py-project.sh" tags: @@ -72,7 +72,7 @@ Python 3.6 AMD GPU: script: - export PY_EXE=python3.6 - export PYOPENCL_TEST=amd:fiji - - export EXTRA_INSTALL="numpy mako" + - export EXTRA_INSTALL="pybind11 numpy mako" - curl -L -O -k https://gitlab.tiker.net/inducer/ci-support/raw/master/build-and-test-py-project.sh - ". ./build-and-test-py-project.sh" allow_failure: true @@ -86,7 +86,7 @@ Python 2.6 POCL CPU: script: - export PY_EXE=python2.6 - export PYOPENCL_TEST=portable - - export EXTRA_INSTALL="numpy mako" + - export EXTRA_INSTALL="pybind11 numpy mako" - export NO_DOCTESTS=1 - curl -L -O -k https://gitlab.tiker.net/inducer/ci-support/raw/master/build-and-test-py-project.sh - ". ./build-and-test-py-project.sh" @@ -100,7 +100,7 @@ Python 2.7 POCL: script: - export PY_EXE=python2.7 - export PYOPENCL_TEST=portable - - export EXTRA_INSTALL="numpy mako" + - export EXTRA_INSTALL="pybind11 numpy mako" - curl -L -O -k https://gitlab.tiker.net/inducer/ci-support/raw/master/build-and-test-py-project.sh - ". ./build-and-test-py-project.sh" tags: @@ -113,7 +113,7 @@ Python 3.7 POCL: script: - export PY_EXE=python3.7 - export PYOPENCL_TEST=portable - - export EXTRA_INSTALL="numpy mako" + - export EXTRA_INSTALL="pybind11 numpy mako" - curl -L -O -k https://gitlab.tiker.net/inducer/ci-support/raw/master/build-and-test-py-project.sh - ". ./build-and-test-py-project.sh" tags: @@ -126,7 +126,7 @@ Python 3.6 POCL CL 1.1: script: - export PY_EXE=python3.5 - export PYOPENCL_TEST=portable - - export EXTRA_INSTALL="numpy mako" + - export EXTRA_INSTALL="pybind11 numpy mako" - curl -L -O -k https://gitlab.tiker.net/inducer/ci-support/raw/master/build-and-test-py-project.sh - echo "CL_PRETEND_VERSION = '1.1'" > siteconf.py - ". ./build-and-test-py-project.sh" @@ -140,7 +140,7 @@ Python 3.6 POCL: script: - export PY_EXE=python3.6 - export PYOPENCL_TEST=portable - - export EXTRA_INSTALL="numpy mako" + - export EXTRA_INSTALL="pybind11 numpy mako" - curl -L -O -k https://gitlab.tiker.net/inducer/ci-support/raw/master/build-and-test-py-project.sh - ". ./build-and-test-py-project.sh" tags: @@ -153,7 +153,7 @@ Python 2.7 Apple: script: - export PY_EXE=python2.7 - export PYOPENCL_TEST=app:cpu - - export EXTRA_INSTALL="numpy mako" + - export EXTRA_INSTALL="pybind11 numpy mako" - export PKG_CONFIG_PATH=/usr/local/opt/libffi/lib/pkgconfig - curl -L -O -k https://gitlab.tiker.net/inducer/ci-support/raw/master/build-and-test-py-project.sh - ". ./build-and-test-py-project.sh" @@ -178,7 +178,7 @@ PyPy POCL: script: - export PY_EXE=pypy - export PYOPENCL_TEST=portable - - export EXTRA_INSTALL="numpy mako" + - export EXTRA_INSTALL="pybind11 numpy mako" - export NO_DOCTESTS=1 - curl -L -O -k https://gitlab.tiker.net/inducer/ci-support/raw/master/build-and-test-py-project.sh - ". ./build-and-test-py-project.sh" @@ -190,7 +190,7 @@ PyPy POCL: Documentation: script: - - EXTRA_INSTALL="numpy mako" + - EXTRA_INSTALL="pybind11 numpy mako" - curl -L -O -k https://gitlab.tiker.net/inducer/ci-support/raw/master/build-docs.sh - ". ./build-docs.sh" tags: diff --git a/.gitmodules b/.gitmodules index b675a6cc8ef4e8a8517472ba700137cc1de1cd0c..779ec4875e9d74d3b4eef45f6349e551c3258339 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ [submodule "pyopencl/compyte"] path = pyopencl/compyte url = https://github.com/inducer/compyte -[submodule "pybind11"] - path = pybind11 - url = https://github.com/pybind/pybind11.git diff --git a/pybind11 b/pybind11 deleted file mode 160000 index f7bc18f528bb35cd06c93d0a58c17e6eea3fa68c..0000000000000000000000000000000000000000 --- a/pybind11 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit f7bc18f528bb35cd06c93d0a58c17e6eea3fa68c diff --git a/setup.py b/setup.py index 0e6aaf803fff57242c91908fd68c5d1455eccd26..092ac92869af2236de6a7709d7b44aff5601d4ae 100644 --- a/setup.py +++ b/setup.py @@ -31,6 +31,82 @@ THE SOFTWARE. import sys from os.path import exists +import setuptools +from setuptools.command.build_ext import build_ext + + +# {{{ boilerplate from https://github.com/pybind/python_example/blob/2ed5a68759cd6ff5d2e5992a91f08616ef457b5c/setup.py # noqa + +class get_pybind_include(object): # noqa: N801 + """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) + + +# 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 + + +def cpp_flag(compiler): + """Return the -std=c++[11/14] compiler flag. + + The c++14 is prefered over c++11 (when it is available). + """ + if has_flag(compiler, '-std=c++14'): + return '-std=c++14' + elif has_flag(compiler, '-std=c++11'): + return '-std=c++11' + else: + raise RuntimeError('Unsupported compiler -- at least C++11 support ' + 'is needed!') + + +class BuildExt(build_ext): + """A custom build extension for adding compiler-specific options.""" + c_opts = { + 'msvc': ['/EHsc'], + 'unix': [], + } + + if sys.platform == 'darwin': + c_opts['unix'] += ['-stdlib=libc++', '-mmacosx-version-min=10.7'] + + 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()) + opts.append(cpp_flag(self.compiler)) + 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) + +# }}} def get_config_schema(): @@ -230,12 +306,16 @@ def main(): "src/wrap_mempool.cpp", "src/bitlog.cpp", ], - include_dirs=INCLUDE_DIRS, + include_dirs=INCLUDE_DIRS + [ + get_pybind_include(), + get_pybind_include(user=True) + ], library_dirs=conf["CL_LIB_DIR"], libraries=conf["CL_LIBNAME"], define_macros=list(conf["EXTRA_DEFINES"].items()), extra_compile_args=conf["CXXFLAGS"], extra_link_args=conf["LDFLAGS"], + language='c++', ), ], @@ -263,8 +343,11 @@ def main(): ] }, + cmdclass={'build_ext': BuildExt}, zip_safe=False) if __name__ == '__main__': main() + +# vim: foldmethod=marker