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/vfs.h"
17
18struct VFile* VFileFromPython(void* fileobj);
19
20struct VFilePy {
21 struct VFile d;
22 void* fileobj;
23};
24""", include_dirs=[src],
25 extra_compile_args=sys.argv[1:],
26 libraries=["mgba"],
27 library_dirs=[os.path.join(os.getcwd(), "..")],
28 sources=[os.path.join(os.path.dirname(__file__), path) for path in ["vfs-py.c"]])
29
30with open(os.path.join(os.getcwd(), "_builder.h")) as core:
31 lines = []
32 for line in core:
33 line = line.strip()
34 if line.startswith('#'):
35 continue
36 lines.append(line)
37 ffi.cdef('\n'.join(lines))
38
39ffi.compile()