-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.py
executable file
·341 lines (269 loc) · 10.7 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
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
#!/usr/bin/python3
import os
import sys
# submodule update
def submodule_update(submoddir) :
if (False == os.path.isfile(submoddir + "/.git")):
if (os.path.isdir(submoddir)) :
os.system("rm -rf " + submoddir)
os.system("git submodule update --init --recursive " + submoddir)
if (not os.path.isdir(submoddir)):
print("Error: No " + submoddir + " submodule")
exit(1)
def help():
print(" sodium \n\tlibOTe module.")
print(" libote \n\tlibOTe module.")
print(" spdz \n\tMP-SPDZ module.")
print(" xsce \n\txsce module.")
print(" debug \n\tdebug build.")
print(" release \n\trelease build, default.")
print(" clean \n\tclean build.")
print(" verbose \n\tshow the build details.")
print(" install \n\tinstall the exe and library to the default location.")
print(" install=prefix \n\tinstall exe and library to the provided predix.")
print(" setup \n\tsetup the source code of module in third_party.")
print(" docker=images \n\tbuild the docker.")
print(" sodu \n\tprivilege escalation.")
def copy_files(srcpath, dstpath, subdir, tail2, sudoflag):
for i in os.listdir(srcpath):
sub_path = os.path.join(srcpath, i)
if os.path.isdir(sub_path):
local_dir=""
if subdir=="":
local_dir=i
else :
local_dir=subdir+"/"+i
copy_files(sub_path, dstpath, local_dir, tail2, sudoflag)
elif os.path.isfile(sub_path):
tail1 = i.split('.')[-1]
if tail1 == tail2:
local_path=dstpath+"/"+subdir
SUDO=""
if sudoflag :
SUDO="sudo "
os.system(SUDO + "mkdir -p " + local_path)
os.system(SUDO + "cp " + sub_path + " " + local_path)
def check_str_in_file(filename, text):
# 检测文件是否存在
if os.path.isfile(filename):
f = open(filename, "r")
# 在文件中查找字符串
if text in f.read():
return True
return False
def build_libOTe(argv):
THIRD_LIB="third_party/libOTe_libs"
LIBOTE="third_party/libOTe"
if "clean" in argv :
os.system("rm -rf " + THIRD_LIB)
os.system("rm -rf " + LIBOTE + "/out")
wd=os.getcwd()
submodule_update(LIBOTE)
os.chdir(LIBOTE)
submodule_update("cryptoTools")
os.system("python3 build.py --setup --boost --relic -D CMAKE_C_FLAGS=-fPIC -D CMAKE_CXX_FLAGS=-fPIC -D ENABLE_SIMPLESTOT=OFF -D ENABLE_SIMPLESTOT_ASM=OFF -D ENABLE_MRR=ON -D ENABLE_SILENTOT=ON -D ENABLE_KKRT=ON")
os.system("python3 build.py -D ENABLE_RELIC=ON -D ENABLE_SODIUM=OFF -D ENABLE_CIRCUITS=ON -D CMAKE_C_FLAGS=-fPIC -D CMAKE_CXX_FLAGS=-fPIC -D ENABLE_SIMPLESTOT=OFF -D ENABLE_SIMPLESTOT_ASM=OFF -D ENABLE_MRR=ON -D ENABLE_MR=ON -D ENABLE_SILENTOT=ON -D ENABLE_KKRT=ON -D ENABLE_KOS=ON -D ENABLE_IKNP=ON -D ENABLE_DELTA_KOS=ON -D ENABLE_OOS=ON -D ENABLE_RR=ON")
os.system("python3 build.py --install=../../" + THIRD_LIB)
os.chdir(wd)
return THIRD_LIB
def build_sodium(argv):
sodium_path="third_party/sodium"
sodium_source = "https://github.com/osu-crypto/libsodium.git"
sodium_tag = "4e825a68baebdf058543f29762c73c17b1816ec0"
if "clean" in argv :
os.system("rm -rf " + sodium_path)
wd=os.getcwd()
if(not os.path.isdir(sodium_path)):
os.mkdir(path=sodium_path)
os.chdir(sodium_path)
print("============= XSCE_OSE Building Sodium =============")
os.system("git clone {0}".format(sodium_source))
os.chdir("./libsodium")
os.system("git checkout {0}".format(sodium_tag))
os.system("./autogen.sh -s")
os.system("./configure --prefix=${PWD}/../../libOTe_libs")
os.system("make && make check")
os.system("make install ")
os.chdir(wd)
return True
def build_spdz(argv):
lib_path="lib"
if "clean" in argv :
if (os.path.isdir(lib_path)):
os.system("rm -f " + lib_path + "/libMP-SPDZ.a")
os.system("rm -f " + lib_path + "/libmpir.a")
os.system("rm -f " + lib_path + "/libmpirxx.a")
os.system("rm -f " + lib_path + "/libsimpleot.a")
if (not os.path.isdir("lib")):
os.system("mkdir " + "lib")
SPDZ="third_party/MP-SPDZ"
wd=os.getcwd()
submodule_update(SPDZ)
os.chdir(SPDZ)
if "clean" in argv:
os.system("make clean");
if (False == os.path.isfile("local/lib/libmpir.a")):
os.system("make mpir")
if (False == os.path.isfile("local/lib/libmpir.so")):
os.system("make mpir")
if (False == os.path.isfile("local/lib/libmpirxx.a")):
os.system("make mpir")
if (False == os.path.isfile("local/lib/libmpirxx.so")):
os.system("make mpir")
os.system("make linux-machine-setup simde/simde")
if (False == os.path.isfile("SimpleOT/libsimpleot.a")):
os.system("make SimpleOT/libsimpleot.a")
# if (False == os.path.isfile("SimplestOT_C/ref10/libSimplestOT.a")):
# os.system("make SimplestOT_C/ref10/libSimplestOT.a")
# 检测Makefile释放已调整,如果未调整,则修改Makefile
makefile_flag = check_str_in_file("Makefile", "libMP-SPDZ.a: $(FHEOBJS) $(COMMONOBJS) $(PROCESSOR) $(GC) $(OT)")
if (True == makefile_flag):
makefile_flag = check_str_in_file("Makefile", " $(AR) -csr $@ $^")
if (False == makefile_flag):
os.system("git restore Makefile")
os.system("echo 'libMP-SPDZ.a: $(FHEOBJS) $(COMMONOBJS) $(PROCESSOR) $(GC) $(OT)' >> Makefile")
os.system("echo ' $(AR) -csr $@ $^' >> Makefile")
# 检测CONFIG释放已调整,如果未调整,则修改CONFIG
config_flag = check_str_in_file("CONFIG", "USE_KOS = 1")
if (False == config_flag):
os.system("git restore CONFIG")
os.system("rm -f CONFIG.old")
os.system("mv CONFIG CONFIG.old")
os.system("sed 's/USE_KOS = 1/USE_KOS = 0/' CONFIG.old > CONFIG")
# 编译
os.system("make MY_CFLAGS+=\"-Werror=unused-parameter -I../libOTe_libs/include -Ilocal/include -L../libOTe_libs/lib -Llocal/lib\" libMP-SPDZ.a")
os.chdir(wd)
# 拷贝编译好的库文件
os.system("cp " + SPDZ + "/local/lib/*.a ./lib/")
os.system("cp " + SPDZ + "/libMP-SPDZ.a ./lib/")
os.system("cp " + SPDZ + "/SimpleOT/libsimpleot.a ./lib/libsimpleot.a")
def build_clean(argv) :
build_path="build"
lib_path="lib"
if "clean" in argv :
if (os.path.isdir(build_path)):
os.system("rm -rf " + build_path)
if (os.path.isdir(lib_path)):
os.system("rm -rf " + lib_path)
def build_xsce(argv, THIRD_LIB):
build_path="build"
lib_path="lib"
if "clean" in argv :
if (os.path.isdir(build_path)):
os.system("rm -rf " + build_path)
if (os.path.isdir(lib_path)):
os.system("rm -f " + lib_path + "/libarich.a")
os.system("rm -f " + lib_path + "/libcommon.a")
os.system("rm -f " + lib_path + "/libPIR.a")
os.system("rm -f " + lib_path + "/libPSI.a")
os.system("rm -f " + lib_path + "/libtoolkits.a")
if (not os.path.isdir(build_path)):
os.system("mkdir " + build_path)
if (not os.path.isdir("lib")):
os.system("mkdir " + "lib")
# 设置cmake编译选项
cmake_compile_arg = "cmake -S . -B " + build_path
if "verbose" in argv :
cmake_compile_arg += " -DCMAKE_VERBOSE_MAKEFILE=ON "
if "debug" in argv :
cmake_compile_arg += " -DCMAKE_BUILD_TYPE=Debug "
else :
cmake_compile_arg += " -DCMAKE_BUILD_TYPE=Release "
if THIRD_LIB == "" :
cmake_compile_arg += ""
else :
cmake_compile_arg += " -DTHIRD_LIB=" + THIRD_LIB
print(cmake_compile_arg)
os.system(cmake_compile_arg)
os.system("make -j5 -C " + build_path)
def parseArgs(arg, args, default_value):
doarg = False
valuearg = default_value
for x in args:
if x.startswith(arg+"="):
valuearg = x.split("=",1)[1]
doarg = True
if x == arg:
doarg = True
return (valuearg, doarg)
def parseInstallArgs(args):
installpath = "/usr/local"
doInstall = False
for x in args:
if x.startswith("install="):
installpath = x.split("=",1)[1]
doInstall = True
if x == "install":
doInstall = True
return (installpath, doInstall)
def build_install(installpath, argv):
if installpath == "" :
installpath = "/usr/local"
installpath_include = installpath + "/include/xsce"
installpath_lib = installpath + "/lib"
sudoflag = "sudo" in argv
SUDO=""
if sudoflag :
SUDO = "sudo "
if (not os.path.isdir(installpath_include)):
os.system(SUDO + "mkdir -p " + installpath_include)
if (not os.path.isdir(installpath_lib)):
os.system(SUDO + "mkdir -p " + installpath_lib)
os.system(SUDO + "cp -rf third_party/libOTe_libs/* " + installpath)
os.system(SUDO + "cp lib/* " + installpath_lib)
copy_files("./src", installpath_include, "", "h", sudoflag)
copy_files("./src", installpath_include, "", "hpp", sudoflag)
copy_files("./third_party/MP-SPDZ", installpath+"/include/MP-SPDZ", "", "h", sudoflag)
copy_files("./third_party/MP-SPDZ", installpath+"/include/MP-SPDZ", "", "hpp", sudoflag)
def build_docker(images):
os.system("docker build -t " + images + " . ")
def build_setup(argv):
THIRD_LIB="third_party/libOTe_libs"
LIBOTE="third_party/libOTe"
if "libote" in argv :
if "clean" in argv :
os.system("rm -rf " + THIRD_LIB)
os.system("rm -rf " + LIBOTE)
submodule_update(LIBOTE)
THIRD_SPDZ="third_party/MP-SPDZ"
if "spdz" in argv :
if "clean" in argv :
os.system("rm -rf " + THIRD_SPDZ + "/*")
os.system("rm -rf " + THIRD_SPDZ + "/.git*")
submodule_update(THIRD_SPDZ)
def main(projectName, argv):
flag=False
if "help" in argv:
help()
return
if "setup" in argv :
build_setup(argv)
return
THIRD_LIB=""
if "sodium" in argv :
flag = True
build_sodium(argv)
if "libote" in argv :
flag = True
THIRD_LIB = build_libOTe(argv)
if "spdz" in argv :
flag = True
build_spdz(argv)
if "xsce" in argv :
flag = True
build_xsce(argv, THIRD_LIB)
installpath, install = parseInstallArgs(argv)
if install :
flag = True
build_install(installpath, argv)
images, dockerflag = parseArgs("docker", argv, "")
if dockerflag :
if images=="" :
help()
return
flag = True
build_docker(images)
if False == flag :
help()
if __name__ == "__main__":
main("xsce", sys.argv[1:])