-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.py
62 lines (50 loc) · 1.41 KB
/
build.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
import os
import sys
from cffi import FFI, VerificationError
ffi = FFI()
dirs = ['/secp256k1-zkp/include']
c_files = []
h_files = []
# os.environ['USE_NUM_NONE'] = '1'
for d in dirs:
root_dir = os.path.abspath(os.path.dirname(__file__)) + d
cwd = str(os.getcwdb())
for root, dirs, _files in os.walk(root_dir):
for f in _files:
path = os.path.join(os.path.relpath(root), f)
if (f.endswith('.h')):
h_files.append(path)
c_files = [
'secp256k1-zkp/contrib/lax_der_parsing.c',
'secp256k1-zkp/src/secp256k1.c'
]
definitions = [
('USE_NUM_NONE', '1'),
('USE_FIELD_INV_BUILTIN', '1'),
('USE_SCALAR_INV_BUILTIN', '1'),
('USE_FIELD_10X26', '1'),
('USE_SCALAR_8X32', '1'),
('USE_ENDOMORPHISM', '1'),
('ENABLE_MODULE_ECDH', '1'),
('ENABLE_MODULE_GENERATOR', '1'),
('ENABLE_MODULE_RECOVERY', '1'),
('ENABLE_MODULE_RANGEPROOF', '1'),
('ENABLE_MODULE_BULLETPROOF', '1'),
('ENABLE_MODULE_AGGSIG', '1'),
('ENABLE_MODULE_SCHNORRSIG', '1')
]
include = ''
for f in h_files:
include += '#include "{0}"\n'.format(f)
with open('defs.c', 'rt') as fid:
_source = fid.read()
ffi.cdef(_source)
ffi.set_source(
"secp256k1_mw",
include,
include_dirs=['secp256k1-zkp', 'secp256k1-zkp/src', 'secp256k1-zkp/include'],
extra_compile_args=['-g'],
sources=c_files,
define_macros=definitions
)
ffi.compile()