This repository has been archived by the owner on Sep 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
setup_ext.py
145 lines (129 loc) · 5.51 KB
/
setup_ext.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
from setuptools import Extension, setup
import os
import sys
import re
def is_suffix(fname, suffix):
return fname.rfind(suffix) == len(fname) - len(suffix)
def list_path(path, suffix, exclude_files=[]):
if path[-1] != "/":
path += "/"
re = []
for f in os.listdir(path):
if is_suffix(f, suffix) and (f not in exclude_files):
re.append(path+f)
return re
# SKYNET_3RD = "./skynet/3rd"
# JEMALLOC_STATICLIB = SKYNET_3RD + "/jemalloc/lib/libjemalloc_pic.a"
# JEMALLOC_INC = SKYNET_3RD + "/jemalloc/include/jemalloc"
LUA_PATH = "./skynet/3rd/lua"
SKYNET_SRC_PATH = "./skynet/skynet-src"
LIBRARIES = ["pthread", "m", "readline"]
MACROS = [("NOUSE_JEMALLOC", None), ("BUILD_FOR_PYSKYNET", None), ("__STDC_NO_ATOMICS__", None)]
TFLITE_LIB = None
if sys.platform == "linux":
MACROS += [("LUA_USE_LINUX", None)]
LIBRARIES += ["dl"]
TFLITE_LIB = "3rd/nn_libs/tflite/lib/manylinux/libtensorflow-lite.a"
elif sys.platform == "darwin":
MACROS += [("LUA_USE_MACOSX", None)]
TFLITE_LIB = "3rd/nn_libs/tflite/lib/macosx/libtensorflow-lite.a"
else:
TFLITE_LIB = "3rd/nn_libs/tflite/lib/win/tensorflow-lite.lib"
raise Exception("no build config for platform %s" % sys.platform)
INCLUDE_DIRS = [SKYNET_SRC_PATH, LUA_PATH, "./src", "./src/c_src", "./skynet/lualib-src", "3rd/numsky/src"]
def create_skynet_extensions():
SKYNET_CSERVICES = ["snlua", "logger", "gate", "harbor"]
ext_cservices = []
for cservice in SKYNET_CSERVICES:
ext = Extension('skynet.cservice.'+cservice,
include_dirs=INCLUDE_DIRS,
sources=['skynet/service-src/service_'+cservice+'.c'],
define_macros=MACROS,
extra_objects=[])
ext_cservices.append(ext)
clib_skynet_src = ["lua-skynet.c",
"lua-seri.c",
"lua-socket.c",
"lua-mongo.c",
"lua-netpack.c",
"lua-memory.c",
"lua-multicast.c",
"lua-cluster.c",
"lua-crypt.c",
"lsha1.c",
"lua-sharedata.c",
"lua-stm.c",
"lua-debugchannel.c",
"lua-datasheet.c",
"lua-sharetable.c"]
ext_skynet = Extension('skynet.luaclib.skynet',
include_dirs=INCLUDE_DIRS,
define_macros=MACROS,
sources=["skynet/lualib-src/" + s for s in clib_skynet_src],
extra_objects=[])
ext_lpeg = Extension('skynet.luaclib.lpeg',
include_dirs=[LUA_PATH, "skynet/3rd/lpeg"],
sources=list_path("skynet/3rd/lpeg", ".c"),
define_macros=MACROS,
extra_objects=[])
ext_md5 = Extension('skynet.luaclib.md5',
include_dirs=[LUA_PATH, "skynet/3rd/lua-md5"],
sources=list_path("skynet/3rd/lua-md5", ".c"),
define_macros=MACROS,
extra_objects=[])
ext_bson = Extension('skynet.luaclib.bson',
include_dirs=[SKYNET_SRC_PATH, LUA_PATH, "skynet/lualib-src/lua-bson"],
sources=["skynet/lualib-src/lua-bson.c"],
define_macros=MACROS,
extra_objects=[])
return ext_cservices + [ext_skynet, ext_lpeg, ext_md5, ext_bson]
def create_lua_extensions():
lua_service_pyholder = Extension('skynet.cservice.pyholder',
sources=['src/c_src/service_pyholder.c'],
include_dirs=INCLUDE_DIRS,
define_macros=MACROS,
libraries=LIBRARIES)
lua_foreign_seri = Extension('pyskynet.lualib.pyskynet.foreign_seri',
sources=['3rd/numsky/src/lua-foreign_seri.c'],
include_dirs=INCLUDE_DIRS,
define_macros=MACROS,
libraries=LIBRARIES)
#lua_seri_v2 = Extension('pyskynet.lualib.pyskynet.seri_v2',
# sources=list_path('3rd/numsky/src/foreign_seri/', '.cpp'),
# include_dirs=INCLUDE_DIRS,
# define_macros=MACROS,
# extra_compile_args=['-std=c++11'],
# libraries=LIBRARIES)
lua_modify = Extension('pyskynet.lualib.pyskynet.modify',
sources=['src/c_src/lua-modify.c'],
include_dirs=INCLUDE_DIRS,
define_macros=MACROS,
libraries=LIBRARIES)
lua_numsky = Extension('pyskynet.lualib.numsky',
sources=list_path("3rd/numsky/src/numsky/ndarray", ".cpp") +
list_path("3rd/numsky/src/numsky/ufunc", ".cpp") +
list_path("3rd/numsky/src/numsky/canvas", ".cpp") +
list_path("3rd/numsky/src/numsky/tinygl", ".cpp") +
list_path("3rd/TinyGL/tinygl", ".cpp") +
list_path("3rd/numsky/src/numsky", ".cpp"),
include_dirs=INCLUDE_DIRS + ["3rd/rapidxml", "3rd/TinyGL"],
define_macros=MACROS,
extra_compile_args=['-std=c++11'],
libraries=LIBRARIES)
return [lua_service_pyholder, lua_foreign_seri, lua_modify, lua_numsky]
def create_3rd_extensions():
lua_pb = Extension('pyskynet.lualib.pb',
sources=["3rd/lua-protobuf/pb.c"],
include_dirs=["3rd/lua-protobuf", LUA_PATH])
lua_rapidjson = Extension('pyskynet.lualib.rapidjson',
sources=list_path("3rd/lua-rapidjson/src", ".cpp"),
extra_compile_args=["-std=c++11"],
include_dirs=["3rd/lua-rapidjson/src", "3rd/lua-rapidjson/rapidjson/include", LUA_PATH, "3rd/"])
if sys.platform == "linux":
lua_unqlite = Extension('pyskynet.lualib.unqlite',
sources=["src/c_src/lua-unqlite.cpp", "3rd/unqlite/unqlite.c"],
include_dirs=["3rd/unqlite/"]+INCLUDE_DIRS)
return [lua_pb, lua_rapidjson, lua_unqlite]
else:
# lua_unqlite can't be compiled success on MacOS ...
return [lua_pb, lua_rapidjson]