-
Notifications
You must be signed in to change notification settings - Fork 6
/
build.py
61 lines (54 loc) · 1.77 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
import os
import re
import sys
from cffi import FFI
ffibuilder = FFI()
# cwd = os.path.dirname(os.path.realpath(__file__))
cdef_pattern = re.compile("// begin cdef([^$]*)// end cdef")
cb_cdef_pattern = re.compile("// begin cb cdef([^$]*)// end cb cdef")
for header_file in ["R.h", "libR.h", "gil.h", "parse.h", "process_events.h"]:
with open(os.path.join("rchitect", "src", header_file), "r") as f:
m = cdef_pattern.search(f.read(), re.M)
ffibuilder.cdef(m.group(1).replace("RAPI_EXTERN", "extern"))
if sys.platform.startswith("win"):
ffibuilder.cdef("""
extern char *(*get_R_HOME)(void);
extern char *(*getRUser)(void);
extern int* UserBreak_t;
extern int* CharacterMode_t;
extern int* EmitEmbeddedUTF8_t;
extern int (*GA_peekevent)(void);
extern int (*GA_initapp)(int, char **);
""")
else:
ffibuilder.cdef("""
extern void* R_InputHandlers;
extern void (**R_PolledEvents_t)(void);
extern void* (*R_checkActivity)(int usec, int ignore_stdin);
extern void (*R_runHandlers)(void* handlers, void* mask);
extern int* R_interrupts_pending_t;
""")
with open(os.path.join("rchitect", "src", "libR.h"), "r") as f:
m = cb_cdef_pattern.search(f.read(), re.M)
ffibuilder.cdef("""
extern "Python+C" {{
{}
}}
""".format(m.group(1)))
ffibuilder.set_source(
"rchitect._cffi",
"""
# include "gil.h"
# include "libR.h"
# include "parse.h"
# include "process_events.h"
""",
include_dirs=['rchitect/src'],
sources=[
'rchitect/src/libR.c',
'rchitect/src/gil.c',
'rchitect/src/parse.c',
'rchitect/src/process_events.c'
])
if __name__ == "__main__":
ffibuilder.compile(verbose=True)