-
Notifications
You must be signed in to change notification settings - Fork 5
/
setup.py
212 lines (184 loc) · 7.26 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
203
204
205
206
207
208
209
210
211
212
#
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from setuptools import find_packages
from sys import platform as _platform
import sys
import glob
import os
from distutils.core import setup
from distutils.extension import Extension
from distutils.util import get_platform
from glob import glob
# monkey-patch for parallel compilation
import multiprocessing
import multiprocessing.pool
def parallelCCompile(self,
sources,
output_dir=None,
macros=None,
include_dirs=None,
debug=0,
extra_preargs=None,
extra_postargs=None,
depends=None):
# those lines are copied from distutils.ccompiler.CCompiler directly
macros, objects, extra_postargs, pp_opts, build = self._setup_compile(
output_dir, macros, include_dirs, sources, depends, extra_postargs)
cc_args = self._get_cc_args(pp_opts, debug, extra_preargs)
# parallel code
N = 2 * multiprocessing.cpu_count() # number of parallel compilations
try:
# On Unix-like platforms attempt to obtain the total memory in the
# machine and limit the number of parallel jobs to the number of Gbs
# of RAM (to avoid killing smaller platforms like the Pi)
mem = os.sysconf('SC_PHYS_PAGES') * os.sysconf('SC_PAGE_SIZE') # bytes
except (AttributeError, ValueError):
# Couldn't query RAM; don't limit parallelism (it's probably a well
# equipped Windows / Mac OS X box)
pass
else:
mem = max(1, int(round(mem / 1024 ** 3))) # convert to Gb
N = min(mem, N)
def _single_compile(obj):
try:
src, ext = build[obj]
except KeyError:
return
newcc_args = cc_args
if _platform == "darwin":
if src.endswith('.cpp'):
newcc_args = cc_args + ["-mmacosx-version-min=10.7", "-stdlib=libc++"]
self._compile(obj, src, ext, newcc_args, extra_postargs, pp_opts)
# convert to list, imap is evaluated on-demand
pool = multiprocessing.pool.ThreadPool(N)
list(pool.imap(_single_compile, objects))
return objects
import distutils.ccompiler
distutils.ccompiler.CCompiler.compile = parallelCCompile
# see http://stackoverflow.com/a/8719066/295157
import os
platform = get_platform()
print(platform)
CXX_FLAGS = ''
CXX_FLAGS += '-fpermissive '
libraries = []
include_dirs = ['.','python', 'third_party/tinyxml2/include', 'third_party/pybind11/include',
'third_party/cpp_base64/include', 'third_party/zeromq/include', 'third_party/crossguid',
'third_party/nlohmann/include']
sources = ["python/pydiffarti.cc"]
if _platform == "linux" or _platform == "linux2":
print("linux")
libraries = ['dl', 'pthread', 'crossguid', 'uuid', 'zmq', 'tinyxml2']
# libraries = ['dl', 'pthread', 'uuid']
CXX_FLAGS += '-D_LINUX '
CXX_FLAGS += '-DGLEW_STATIC '
CXX_FLAGS += '-DGLEW_INIT_OPENGL11_FUNCTIONS=1 '
CXX_FLAGS += '-DGLEW_DYNAMIC_LOAD_ALL_GLX_FUNCTIONS=1 '
CXX_FLAGS += '-DDYNAMIC_LOAD_X11_FUNCTIONS '
CXX_FLAGS += '-DHAS_SOCKLEN_T '
CXX_FLAGS += '-fno-inline-functions-called-once '
CXX_FLAGS += '-fvisibility=hidden '
CXX_FLAGS += '-fvisibility-inlines-hidden '
CXX_FLAGS += '-std=c++1z '
CXX_FLAGS += '-Wno-sign-compare '
CXX_FLAGS += '-Wno-reorder '
CXX_FLAGS += '-Wno-unused-local-typedefs '
CXX_FLAGS += '-Wno-unused-variable '
CXX_FLAGS += '-Wno-unused-but-set-variable '
elif _platform == "win32":
print("win32!")
libraries = ['User32', 'kernel32']
CXX_FLAGS += '-DWIN32 '
CXX_FLAGS += '-DGLEW_STATIC '
CXX_FLAGS += '/std:c++17 '
elif _platform == "darwin":
print("darwin!")
os.environ['LDFLAGS'] = '-framework Cocoa -mmacosx-version-min=10.7 -stdlib=libc++ -framework OpenGL'
CXX_FLAGS += '-DB3_NO_PYTHON_FRAMEWORK '
CXX_FLAGS += '-DHAS_SOCKLEN_T '
CXX_FLAGS += '-D_DARWIN '
CXX_FLAGS += '-std=c++17 '
CXX_FLAGS += '-stdlib=libc++ '
CXX_FLAGS += '-mmacosx-version-min=10.7 '
# CXX_FLAGS += '-framework Cocoa '
else:
print("bsd!")
libraries = ['GL', 'GLEW', 'pthread']
os.environ['LDFLAGS'] = '-L/usr/X11R6/lib'
CXX_FLAGS += '-D_BSD '
CXX_FLAGS += '-I/usr/X11R6/include '
CXX_FLAGS += '-DHAS_SOCKLEN_T '
CXX_FLAGS += '-fno-inline-functions-called-once'
setup_py_dir = os.path.dirname(os.path.realpath(__file__))
need_files = []
datadir = "diffphys_data"
hh = setup_py_dir + "/" + datadir
for root, dirs, files in os.walk(hh):
for fn in files:
ext = os.path.splitext(fn)[1][1:]
if ext and ext in 'yaml index meta data-00000-of-00001 png gif jpg urdf sdf obj txt mtl dae off stl STL xml '.split(
):
fn = root + "/" + fn
need_files.append(fn[1 + len(hh):])
print("found resource files: %i" % len(need_files))
for n in need_files:
print("-- %s" % n)
extensions = []
pydiffarti_ext = Extension(
"pydiffarti",
sources=sources,
libraries=libraries,
library_dirs=['/usr/lib', '/usr/local/lib/',
'./build/third_party/zeromq/',
'./build/third_party/tinyxml2/',
'./build/third_party/crossguid/'],
extra_compile_args=CXX_FLAGS.split(),
include_dirs=include_dirs + ["."])
extensions.append(pydiffarti_ext)
setup(
name='pydiffarti',
version='0.0.1',
description=
'Tiny Differentiable Physics Library for Robotics Simulation and Reinforcement Learning',
long_description=
'tbd',
url='https://github.com/bulletphysics/bullet3',
author='Eric Heiden, Erwin Coumans',
author_email='[email protected]',
license='zlib',
platforms='any',
keywords=[
'game development', 'virtual reality', 'physics simulation', 'robotics',
'collision detection', 'opengl'
],
install_requires=[
'numpy',
],
ext_modules=extensions,
classifiers=[
'Development Status :: 5 - Production/Stable',
'License :: OSI Approved :: zlib/libpng License',
'Operating System :: Microsoft :: Windows', 'Operating System :: POSIX :: Linux',
'Operating System :: MacOS', 'Intended Audience :: Science/Research',
"Programming Language :: Python", 'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8', 'Topic :: Games/Entertainment :: Simulation',
'Topic :: Scientific/Engineering :: Artificial Intelligence',
'Framework :: Robot Framework'
],
package_dir={'': 'python'},
packages=[x for x in find_packages('python')],
package_data={'pydiffarti_data': need_files})