-
Notifications
You must be signed in to change notification settings - Fork 105
Expand file tree
/
Copy pathbuild_ext.py
More file actions
86 lines (69 loc) · 3.01 KB
/
build_ext.py
File metadata and controls
86 lines (69 loc) · 3.01 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
import os
import sys
from distutils import log
from distutils.errors import DistutilsError
from setuptools.command.build_ext import build_ext as build_ext_orig
from .static_build import CrossCompileInfo, StaticBuildHelper
class build_ext(build_ext_orig):
def info(self, message):
self.announce(message, level=log.INFO)
def run(self):
ext = self.ext_map['xmlsec']
self.debug = os.environ.get('PYXMLSEC_ENABLE_DEBUG', False)
self.static = os.environ.get('PYXMLSEC_STATIC_DEPS', False)
self.size_opt = os.environ.get('PYXMLSEC_OPTIMIZE_SIZE', True)
if self.static or sys.platform == 'win32':
helper = StaticBuildHelper(self)
helper.prepare(sys.platform)
else:
import pkgconfig
try:
config = pkgconfig.parse('xmlsec1')
except OSError as error:
raise DistutilsError('Unable to invoke pkg-config.') from error
except pkgconfig.PackageNotFoundError as error:
raise DistutilsError('xmlsec1 is not installed or not in path.') from error
if config is None or not config.get('libraries'):
raise DistutilsError('Bad or incomplete result returned from pkg-config.')
ext.define_macros.extend(config['define_macros'])
ext.include_dirs.extend(config['include_dirs'])
ext.library_dirs.extend(config['library_dirs'])
ext.libraries.extend(config['libraries'])
import lxml
ext.include_dirs.extend(lxml.get_include())
ext.define_macros.extend(
[('MODULE_NAME', self.distribution.metadata.name), ('MODULE_VERSION', self.distribution.metadata.version)]
)
for key, value in ext.define_macros:
if key == 'XMLSEC_CRYPTO' and not (value.startswith('"') and value.endswith('"')):
ext.define_macros.remove((key, value))
ext.define_macros.append((key, f'"{value}"'))
break
if sys.platform == 'win32':
ext.extra_compile_args.append('/Zi')
else:
ext.extra_compile_args.extend(
[
'-g',
'-std=c99',
'-fPIC',
'-fno-strict-aliasing',
'-Wno-error=declaration-after-statement',
'-Werror=implicit-function-declaration',
]
)
if self.debug:
ext.define_macros.append(('PYXMLSEC_ENABLE_DEBUG', '1'))
if sys.platform == 'win32':
ext.extra_compile_args.append('/Od')
else:
ext.extra_compile_args.append('-Wall')
ext.extra_compile_args.append('-O0')
else:
if self.size_opt:
if sys.platform == 'win32':
ext.extra_compile_args.append('/Os')
else:
ext.extra_compile_args.append('-Os')
super().run()
__all__ = ('CrossCompileInfo', 'build_ext')