-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathsetup.py
executable file
·202 lines (167 loc) · 6.55 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
import codecs, glob, os, sys, subprocess
from setuptools import setup, find_packages, Extension
from distutils import log
from setuptools.command.install import install as _install
from distutils.command.build_ext import build_ext as _build_ext
from distutils.command.clean import clean as _clean
from distutils.dir_util import remove_tree
try:
from wheel.bdist_wheel import bdist_wheel as _bdist_wheel
has_wheel = True
except ImportError:
has_wheel = False
from distutils.errors import DistutilsSetupError
requirements = ['cppyy-cling==6.32.8']
setup_requirements = ['wheel']
if 'build' in sys.argv or 'install' in sys.argv:
setup_requirements += requirements
here = os.path.abspath(os.path.dirname(__file__))
with codecs.open(os.path.join(here, 'README.rst'), encoding='utf-8') as f:
long_description = f.read()
if 'win32' in sys.platform:
soext = '.dll'
else:
soext = '.so'
#
# platform-dependent helpers
#
def is_manylinux():
try:
for line in open('/etc/redhat-release').readlines():
if 'CentOS release 6.10 (Final)' in line:
return True
except (OSError, IOError):
pass
return False
def _get_linker_options():
if 'win32' in sys.platform:
link_libraries = ['libCoreLegacy', 'libThreadLegacy', 'libRIOLegacy', 'libCling']
import cppyy_backend
link_dirs = [os.path.join(os.path.dirname(cppyy_backend.__file__), 'lib')]
else:
link_libraries = None
link_dirs = None
return link_libraries, link_dirs
def _get_config_exec():
return [sys.executable, '-m', 'cppyy_backend._cling_config']
def get_include_path():
config_exec_args = _get_config_exec()
config_exec_args.append('--incdir')
cli_arg = subprocess.check_output(config_exec_args)
return cli_arg.decode("utf-8").strip()
def get_cflags():
config_exec_args = _get_config_exec()
config_exec_args.append('--auxcflags')
cli_arg = subprocess.check_output(config_exec_args)
return cli_arg.decode("utf-8").strip()
#
# customized commands
#
class my_build_cpplib(_build_ext):
def build_extension(self, ext):
include_dirs = ext.include_dirs + [get_include_path()]
log.info('checking for %s', self.build_temp)
if not os.path.exists(self.build_temp):
log.info('creating %s', self.build_temp)
os.makedirs(self.build_temp)
extra_postargs = ['-O2']+get_cflags().split()
if 'win32' in sys.platform:
# /EHsc and sometimes /MT are hardwired in distutils, but the compiler/linker will
# let the last argument take precedence
extra_postargs += ['/GR', '/EHsc-', '/MD']
objects = self.compiler.compile(
ext.sources,
output_dir=self.build_temp,
include_dirs=include_dirs,
debug=self.debug,
extra_postargs=extra_postargs)
ext_path = self.get_ext_fullpath(ext.name)
output_dir = os.path.dirname(ext_path)
libname_base = 'libcppyy_backend'
libname = libname_base+soext # not: self.compiler.shared_lib_extension
extra_postargs = list()
if 'linux' in sys.platform:
extra_postargs.append('-Wl,-Bsymbolic-functions')
elif 'win32' in sys.platform:
# force the export results in the proper directory.
extra_postargs.append('/IMPLIB:'+os.path.join(output_dir, libname_base+'.lib'))
import platform
if '64' in platform.architecture()[0]:
extra_postargs.append('/EXPORT:?__type_info_root_node@@3U__type_info_node@@A')
log.info("now building %s", libname)
link_libraries, link_dirs = _get_linker_options()
self.compiler.link_shared_object(
objects, libname,
libraries=link_libraries, library_dirs=link_dirs,
# export_symbols=[], # ie. all (hum, that puts the output in the wrong directory)
build_temp=self.build_temp,
output_dir=output_dir,
debug=self.debug,
target_lang='c++',
extra_postargs=extra_postargs)
class my_clean(_clean):
def run(self):
# Custom clean. Clean everything except that which the base clean
# (see below) or create_src_directory.py is responsible for.
topdir = os.getcwd()
if self.all:
# remove build directories
for directory in (os.path.join(topdir, "dist"),
os.path.join(topdir, "python", "cppyy_backend.egg-info")):
if os.path.exists(directory):
remove_tree(directory, dry_run=self.dry_run)
else:
log.warn("'%s' does not exist -- can't clean it",
directory)
# Base clean.
_clean.run(self)
class my_install(_install):
def run(self):
return _install.run(self)
cmdclass = {
'build_ext': my_build_cpplib,
#'clean': my_clean,
'install': my_install }
if has_wheel:
class my_bdist_wheel(_bdist_wheel):
def finalize_options(self):
# this is a universal, but platform-specific package; a combination
# that wheel does not recognize, thus simply fool it
from distutils.util import get_platform
self.plat_name = get_platform()
self.universal = True
_bdist_wheel.finalize_options(self)
self.root_is_pure = True
cmdclass['bdist_wheel'] = my_bdist_wheel
setup(
name='cppyy-backend',
description='C/C++ wrapper for Cling',
long_description=long_description,
url='http://pypy.org',
# Author details
author='Wim Lavrijsen',
author_email='WLavrijsen@lbl.gov',
version='1.15.3',
license='LBNL BSD',
classifiers=[
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'Intended Audience :: Science/Research',
'Topic :: Software Development',
'Topic :: Software Development :: Interpreters',
'License :: OSI Approved :: BSD License',
'Operating System :: POSIX',
'Operating System :: POSIX :: Linux',
'Operating System :: MacOS :: MacOS X',
'Programming Language :: C',
'Programming Language :: C++',
'Natural Language :: English'
],
keywords='C++ bindings data science',
setup_requires=setup_requirements,
install_requires=requirements,
ext_modules=[Extension(os.path.join('cppyy_backend', 'lib', 'libcppyy_backend'),
sources=glob.glob(os.path.join('src', 'clingwrapper.cxx')))],
cmdclass=cmdclass,
zip_safe=False,
)