-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
325 lines (290 loc) · 12.1 KB
/
setup.py
File metadata and controls
325 lines (290 loc) · 12.1 KB
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
from setuptools import setup, Extension
import multiprocessing
try:
from setuptools.command.build import build # Python 3.7+
except ImportError:
from distutils.command.build import build # Fallback for older Python (<3.7)
from setuptools.command.egg_info import egg_info
import subprocess
import os
import sys
import shutil
import sysconfig
import platform
import distutils.ccompiler
from distutils.command.build_ext import build_ext
from wheel.bdist_wheel import bdist_wheel
from os import path
# Work around for CPython 3.6 on Windows
if sys.platform.startswith("win") and sys.version_info[:2] == (3, 6):
import distutils.cygwinccompiler
distutils.cygwinccompiler.get_msvcr = lambda: [] # ["msvcr140"] -- we're building with MinGW-w64
pkg_version = '0.0.7rc1'
env = os.environ.copy()
cc_override = None
# print("sys.platform is: ", sys.platform)
if sys.platform.startswith('win'):
# NOTE: PyPy builds are failing due to a .def file containing a PyInit_ symbol which is specific to CPython
# See generated build/temp.win-amd64-pypy38/Release/build/temp.win-amd64-pypy38/release/_pyecrt.pypy38-pp73-win_amd64.def
# and https://github.com/python-cffi/cffi/issues/170
# This approach works with Python 3.8
def get_mingw(plat=None):
return 'mingw32'
distutils.ccompiler.get_default_compiler = get_mingw
# This approach works with Python 3.9+
class CustomBuildExt(build_ext):
def initialize_options(self):
super().initialize_options()
self.compiler = 'mingw32'
def get_gcc_target():
try:
output = subprocess.check_output(['gcc', '-dumpmachine'], universal_newlines=True)
return output.strip()
except Exception:
return None
def check_gcc_multilib():
try:
output = subprocess.check_output(['gcc', '-v'], stderr=subprocess.STDOUT, universal_newlines=True)
return '--enable-multilib' in output
except Exception:
return False
def is_gcc_good_for(archBits):
target = get_gcc_target()
if target is None:
return True
supports_multilib = check_gcc_multilib()
if target.startswith('x86_64'):
return archBits == 64
elif target.startswith('i686') or target.startswith('i386'):
return archBits == 32
else:
return True # Unknown
def check_i686_w64_available():
try:
result = subprocess.run(
['i686-w64-mingw32-gcc', '--version'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
check=True,
universal_newlines=True
)
return True
except (subprocess.CalledProcessError, FileNotFoundError):
return False
if platform.architecture()[0] == '64bit':
# Ensure ProgramFiles(x86) is set
if 'ProgramFiles(x86)' not in env:
env['ProgramFiles(x86)'] = r"C:\Program Files (x86)"
else:
if 'ProgramFiles(x86)' in env:
del os.environ['ProgramFiles(x86)']
if is_gcc_good_for(32) == False:
if check_i686_w64_available():
cc_override = ['GCC_PREFIX=i686-w64-mingw32-']
dir = os.path.dirname(__file__)
if dir == '':
rwd = os.path.abspath('.')
else:
rwd = os.path.abspath(dir)
with open(os.path.join(rwd, 'README.md'), encoding='u8') as f:
long_description = f.read()
cpu_count = multiprocessing.cpu_count()
eC_dir = os.path.join(rwd, 'eC')
eC_c_dir = os.path.join(rwd, 'eC', 'bindings', 'c')
eC_py_dir = os.path.join(rwd, 'eC', 'bindings', 'py')
platform_str = 'win32' if sys.platform.startswith('win') else ('apple' if sys.platform.startswith('darwin') else 'linux')
dll_prefix = '' if platform_str == 'win32' else 'lib'
dll_dir = 'bin' if platform_str == 'win32' else 'lib'
dll_ext = '.dll' if platform_str == 'win32' else '.dylib' if platform_str == 'apple' else '.so'
exe_ext = '.exe' if platform_str == 'win32' else ''
pymodule = '_pyecrt' + sysconfig.get_config_var('EXT_SUFFIX')
artifacts_dir = os.path.join('artifacts', platform_str)
lib_dir = os.path.join(eC_dir, 'obj', platform_str, dll_dir)
bin_dir = os.path.join(eC_dir, 'obj', platform_str, 'bin')
make_cmd = 'mingw32-make' if platform == 'win32' else 'make'
def prepare_package_dir(src_files, dest_dir):
os.makedirs(dest_dir, exist_ok=True)
for src, rel_dest in src_files:
dest_path = os.path.join(dest_dir, rel_dest)
os.makedirs(os.path.dirname(dest_path), exist_ok=True)
#print("Copying ", src, " to ", dest_path);
shutil.copy(src, dest_path)
def build_package():
try:
if not os.path.exists(artifacts_dir):
archflags = env.get("ARCHFLAGS", None)
make_and_args = [make_cmd, f'-j{cpu_count}', 'SKIP_SONAME=y', 'ENABLE_PYTHON_RPATHS=y', 'V=1']
if archflags is not None:
# This will add arm64 architecture flags for macos-latest
make_and_args.append('CFLAGS=' + archflags)
make_and_args.append('LDFLAGS=' + archflags)
if cc_override is not None:
make_and_args.extend(cc_override)
subprocess.check_call(make_and_args, cwd=eC_dir, env=env)
prepare_package_dir([
(os.path.join(lib_dir, dll_prefix + 'ecrt' + dll_ext), os.path.join(dll_dir, dll_prefix + 'ecrt' + dll_ext)),
(os.path.join(lib_dir, dll_prefix + 'ectp' + dll_ext), os.path.join(dll_dir, dll_prefix + 'ectp' + dll_ext)),
(os.path.join(eC_dir, 'obj', platform_str, 'lib', 'libecrtStatic.a'), os.path.join('lib', 'libecrtStatic.a')),
(os.path.join(bin_dir, 'ecp' + exe_ext), os.path.join('bin', 'ecp' + exe_ext)),
(os.path.join(bin_dir, 'ecc' + exe_ext), os.path.join('bin', 'ecc' + exe_ext)),
(os.path.join(bin_dir, 'ecs' + exe_ext), os.path.join('bin', 'ecs' + exe_ext)),
(os.path.join(bin_dir, 'ear' + exe_ext), os.path.join('bin', 'ear' + exe_ext)),
(os.path.join(eC_py_dir, 'cffi-ecrt.h'), os.path.join('include', 'cffi-ecrt.h')),
(os.path.join(eC_c_dir, 'ecrt.h'), os.path.join('include', 'ecrt.h')),
(os.path.join(eC_dir, 'crossplatform.mk'), 'crossplatform.mk'),
(os.path.join(eC_dir, 'default.cf'), 'default.cf'),
(os.path.join(eC_dir, 'extras', 'testing', 'testingFramework.ec'), os.path.join('extras', 'testing', 'testingFramework.ec')),
(os.path.join(eC_dir, 'extras', 'base64.ec'), os.path.join('extras', 'base64.ec')),
(os.path.join(eC_dir, 'extras', 'BinaryTriangle.ec'), os.path.join('extras', 'BinaryTriangle.ec')),
(os.path.join(eC_dir, 'extras', 'FileSystemAPI.ec'), os.path.join('extras', 'FileSystemAPI.ec')),
(os.path.join(eC_dir, 'extras', 'iso8601.ec'), os.path.join('extras', 'iso8601.ec')),
(os.path.join(eC_dir, 'extras', 'JSONSchema.ec'), os.path.join('extras', 'JSONSchema.ec')),
(os.path.join(eC_dir, 'extras', 'md5.ec'), os.path.join('extras', 'md5.ec')),
(os.path.join(eC_dir, 'extras', 'protocolBuffer.ec'), os.path.join('extras', 'protocolBuffer.ec')),
(os.path.join(eC_dir, 'extras', 'stringTools.ec'), os.path.join('extras', 'stringTools.ec')),
(os.path.join(eC_dir, 'extras', 'stringUtils.ec'), os.path.join('extras', 'stringUtils.ec')),
(os.path.join(eC_dir, 'extras', 'threadedProcessing.ec'), os.path.join('extras', 'threadedProcessing.ec')),
(os.path.join(eC_dir, 'extras', 'XMLParser.ec'), os.path.join('extras', 'XMLParser.ec'))
], artifacts_dir)
except subprocess.CalledProcessError as e:
print(f"Error during make: {e}")
sys.exit(1)
class build_with_make(build):
def initialize_options(self):
super().initialize_options()
def run(self):
build_package()
super().run()
class egg_info_with_build(egg_info):
def initialize_options(self):
super().initialize_options()
def run(self):
build_package()
super().run()
class setplatname_bdist_wheel(bdist_wheel):
def finalize_options(self):
super().finalize_options()
system = sys.platform
machine = platform.machine().lower()
if system.startswith('win'):
self.plat_name = 'win_amd64' if 'amd64' in machine or 'x86_64' in machine else 'win32'
elif system.startswith('darwin'):
arch = 'arm64' if 'arm' in machine else 'x86_64'
self.plat_name = f'macosx_10_15_{arch}'
elif system.startswith('linux'):
env_plat = os.environ.get('AUDITWHEEL_PLAT')
if env_plat:
self.plat_name = env_plat
else:
arch = 'x86_64' if 'x86_64' in machine or 'amd64' in machine else machine
self.plat_name = f'manylinux2014_{arch}' # f'manylinux1_{arch}'
elif system.startswith('freebsd'):
arch = 'x86_64' if 'x86_64' in machine or 'amd64' in machine else machine
self.plat_name = f'freebsd_{arch}'
else:
print("WARNING: platform not detected")
self.plat_name = None
def get_tag(self):
# This package is not specific to a particular Python version
python_tag = 'py3' # 'py2.py3'
abi_tag = 'none'
plat_name = getattr(self, 'plat_name', None)
return (python_tag, abi_tag, plat_name)
lib_files = [
'libecrtStatic.a'
]
include_files = [
'cffi-ecrt.h',
'ecrt.h'
]
bin_files = [
'ecp' + exe_ext,
'ecc' + exe_ext,
'ecs' + exe_ext,
'ear' + exe_ext,
]
if platform_str == 'win32':
bin_files.extend([
'libecrtStatic.a',
os.path.join('ecrt' + dll_ext),
os.path.join('ectp' + dll_ext),
])
else:
lib_files.extend([
'libecrtStatic.a',
os.path.join('libecrt' + dll_ext),
os.path.join('libectp' + dll_ext),
])
extras_files = [
'testing/testingFramework.ec',
'base64.ec',
'BinaryTriangle.ec',
'FileSystemAPI.ec',
'iso8601.ec',
'JSONSchema.ec',
'md5.ec',
'protocolBuffer.ec',
'stringTools.ec',
'stringUtils.ec',
'threadedProcessing.ec',
'XMLParser.ec'
]
commands = set(sys.argv)
if 'sdist' in commands:
packages=['ecdev']
package_dir = { 'ecdev': 'eC' }
package_data = {'ecdev': [] }
cmdclass = {}
else:
packages=['ecdev', 'ecdev.lib', 'ecdev.bin', 'ecdev.include', 'ecdev.extras']
package_dir={
'ecdev': artifacts_dir,
'ecdev.lib': os.path.join(artifacts_dir, 'lib'),
'ecdev.bin': os.path.join(artifacts_dir, 'bin'),
'ecdev.include': os.path.join(artifacts_dir, 'include'),
'ecdev.extras': os.path.join(artifacts_dir, 'extras')
}
package_data={
'ecdev': [ 'crossplatform.mk', 'default.cf' ],
'ecdev.lib': lib_files,
'ecdev.bin': bin_files,
'ecdev.include': include_files,
'ecdev.extras': extras_files,
}
cmdclass={'build': build_with_make, 'bdist_wheel': setplatname_bdist_wheel, 'egg_info': egg_info_with_build }
if sys.platform.startswith('win'):
cmdclass['build_ext'] = CustomBuildExt
setup(
name='ecdev',
version=pkg_version,
# setup_requires is deprecated -- build dependencies must now be specified in pyproject.toml
# setup_requires=['setuptools'],
packages=packages,
package_dir=package_dir,
package_data=package_data,
include_package_data=True,
ext_modules=[],
cmdclass=cmdclass,
description='eC Software Development Kit',
url='https://ec-lang.org',
long_description=long_description,
long_description_content_type='text/markdown',
author='Jérôme Jacovella-St-Louis, Ecere Corporation',
author_email='jerome@ecere.com',
license='BSD-3-Clause',
keywords='eC sdk compiler transpiler archiver runtime type-system object-model reflection file-system collections datetime json-parser econ serialization',
classifiers=[
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
'Operating System :: Microsoft :: Windows',
'Operating System :: POSIX :: Linux',
'Operating System :: MacOS',
'Programming Language :: Other',
'Programming Language :: Python :: 3',
'Topic :: File Formats :: JSON',
'Topic :: Software Development :: Compilers',
'Topic :: Software Development :: Internationalization',
'Topic :: Software Development :: Libraries',
'Topic :: System :: Archiving',
]
)