src/platform/python/_builder.py (view raw)
1import cffi
2import os.path
3import subprocess
4import sys
5
6ffi = cffi.FFI()
7src = os.path.join(os.path.dirname(__file__), "..", "..")
8
9ffi.set_source("mgba._pylib", """
10#include "util/common.h"
11#include "core/core.h"
12#include "arm/arm.h"
13#include "gba/gba.h"
14#include "lr35902/lr35902.h"
15#include "gb/gb.h"
16#include "util/png-io.h"
17#include "util/vfs.h"
18
19struct VFile* VFileFromPython(void* fileobj);
20
21struct VFilePy {
22 struct VFile d;
23 void* fileobj;
24};
25""", include_dirs=[src],
26 extra_compile_args=sys.argv[1:],
27 libraries=["mgba"],
28 library_dirs=[os.path.join(os.getcwd(), "..")],
29 sources=[os.path.join(os.path.dirname(__file__), path) for path in ["vfs-py.c"]])
30
31with open(os.path.join(os.getcwd(), "_builder.h")) as core:
32 lines = []
33 for line in core:
34 line = line.strip()
35 if line.startswith('#'):
36 continue
37 lines.append(line)
38 ffi.cdef('\n'.join(lines))
39
40ffi.compile()