-
Notifications
You must be signed in to change notification settings - Fork 1
/
ffi_build.py
66 lines (52 loc) · 2.26 KB
/
ffi_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
63
64
65
66
from cffi import FFI
from os import path
BASEDIR = path.dirname(path.realpath(__file__))
ffibuilder = FFI()
with open(path.join(BASEDIR, "rtrlib.cdef")) as file_obj:
ffibuilder.cdef(file_obj.read())
ffibuilder.cdef("""
extern "Python" void rtr_mgr_status_callback(const struct rtr_mgr_group *, enum rtr_mgr_status, const struct rtr_socket *, void *);
extern "Python" void pfx_update_callback(struct pfx_table *pfx_table, const struct pfx_record record, const bool added);
extern "Python" void spki_update_callback(struct spki_table *spki_table, const struct spki_record record, const bool added);
extern "Python" void pfx_table_callback(const struct pfx_record *pfx_record, void *data);
""")
ffibuilder.cdef("""
void free(void *ptr);
""")
ffibuilder.cdef("""
struct rtr_socket_wrapper {
struct rtr_socket rtr_socket;
void *data;
};
""")
ffibuilder.set_source("_rtrlib",
"""
#include <rtrlib/rtrlib.h>
/*
* check if ssh support is available
* if not define tr_ssh_config struct
* and have_ssh with return 0
* otherwise just define have_ssh with return 1
*/
#ifndef RTRLIB_HAVE_LIBSSH
struct tr_ssh_config {
char *host;
unsigned int port;
char *bindaddr;
char *username;
char *server_hostkey_path;
char *client_privkey_path;
};
int have_ssh(void) {return 0;}
#endif
#ifdef RTRLIB_HAVE_LIBSSH
int have_ssh(void) {return 1;}
#endif
struct rtr_socket_wrapper {
struct rtr_socket rtr_socket;
void *data;
};
""",
libraries=['rtr'])
if __name__ == "__main__":
ffibuilder.compile(verbose=True)