forked from ladnir/aby3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.py
199 lines (154 loc) · 5.57 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
import os
import platform
import sys
import multiprocessing
if __name__ == "__main__":
import thirdparty.getEigen as getEigen
import thirdparty.getJson as getJson
import thirdparty.getFunction2 as getFunction2
import thirdparty.getLibOTe as getLibOTe
else:
from .thirdparty import getSparsehash
from .thirdparty import getLibOTe
#import thirdparty
def getParallel(args):
par = multiprocessing.cpu_count()
for x in args:
if x.startswith("--par="):
val = x.split("=",1)[1]
par = int(val)
if par < 1:
par = 1
return par
def Setup(boost, libOTe,eigen, json,function2, install, prefix, par):
dir_path = os.path.dirname(os.path.realpath(__file__))
os.chdir(dir_path + "/thirdparty")
if not libOTe and not eigen and not json and not function2 and not boost:
sparsehash = True
libOTe = True
boost = True
eigen = True
json = True
function2 = True
if boost or libOTe:
getLibOTe.getLibOTe(install, prefix, par, libOTe, boost, False)
if function2:
getFunction2.getFunction2(install, prefix, par)
if eigen:
getEigen.getEigen(install, prefix, par)
if json:
getJson.getJson(install, prefix, par)
os.chdir(dir_path)
def Build(mainArgs, cmakeArgs,install, prefix, par):
osStr = (platform.system())
buildDir = ""
config = ""
buildType = ""
if "--Debug" in mainArgs:
buildType = "Debug"
else:
buildType = "Release"
if osStr == "Windows":
buildDir = "out/build/x64-{0}".format(buildType)
config = "--config {0}".format(buildType)
else:
buildDir = "out/build/linux"
cmakeArgs.append("-DCMAKE_BUILD_TYPE={0}".format(buildType))
argStr = ""
for a in cmakeArgs:
argStr = argStr + " " + a
parallel = ""
if par != 1:
parallel = " --parallel " + str(par)
mkDirCmd = "mkdir -p {0}".format(buildDir);
CMakeCmd = "cmake -S . -B {0} {1}".format(buildDir, argStr)
BuildCmd = "cmake --build {0} {1} {2} ".format(buildDir, config, parallel)
#InstallCmd = ""
#sudo = ""
#if "--sudo" in sys.argv:
# sudo = "sudo "
#if install:
# InstallCmd = sudo
# InstallCmd += "cmake --install {0} {1} ".format(buildDir, config)
# if len(prefix):
# InstallCmd += " --prefix {0} ".format(prefix)
projectName = "aby3"
print("======= build.py ("+projectName+") ==========")
print(mkDirCmd)
print(CMakeCmd)
print(BuildCmd)
#if len(InstallCmd):
# print(InstallCmd)
print("vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv\n")
os.system(mkDirCmd)
os.system(CMakeCmd)
os.system(BuildCmd)
#if len(sudo) > 0:
# print("installing libraries: {0}".format(InstallCmd))
#
#os.system(InstallCmd)
def getInstallArgs(args):
prefix = ""
for x in args:
if x.startswith("--install="):
prefix = x.split("=",1)[1]
prefix = os.path.abspath(os.path.expanduser(prefix))
return (True, prefix)
if x == "--install":
return (True, "")
return (False, "")
def parseArgs():
hasCmakeArgs = "--" in sys.argv
mainArgs = []
cmakeArgs = []
if hasCmakeArgs:
idx = sys.argv.index("--")
mainArgs = sys.argv[:idx]
cmakeArgs = sys.argv[idx+1:]
else:
mainArgs = sys.argv
return (mainArgs, cmakeArgs)
def help():
print(" --setup \n\tfetch, build and optionally install the dependencies. \
Must also pass --libOTe, --relic and/or --boost to specify which to build. Without \
--setup, the main library is built.")
print(" --install \n\tInstructs the script to install whatever is currently being built to the default location.")
print(" --install=prefix \n\tinstall to the provided predix.")
print(" --sudo \n\twhen installing, use sudo. May require password.")
print(" --par=n \n\twhen building do use parallel builds with n threads. default = num cores.")
print(" -- \n\tafter the \"--\" argument, all command line args are passed to cmake")
print("\n\nExamples:")
print("-fetch the dependancies and dont install")
print(" python build.py --setup --boost --relic")
print("-fetch the dependancies and install with sudo")
print(" python build.py --setup --boost --relic --install --sudo")
print("-fetch the dependancies and install to a specified location")
print(" python build.py --setup --boost --relic --install=~/my/install/dir")
print("")
print("-build the main library")
print(" python build.py")
print("-build the main library with cmake configurations")
print(" python build.py -- -DCMAKE_BUILD_TYPE=Debug -DENABLE_SSE=ON")
print("-build the main library and install with sudo")
print(" python build.py --install --sudo")
print("-build the main library and install to prefix")
print(" python build.py --install=~/my/install/dir ")
def main():
(mainArgs, cmake) = parseArgs()
if "--help" in mainArgs:
help()
return
boost = ("--boost" in mainArgs)
eigen = ("--eigen" in mainArgs)
json = ("--json" in mainArgs)
function2 = ("--function2" in mainArgs)
libOTe = ("--libOTe" in mainArgs)
setup = ("--setup" in mainArgs)
install, prefix = getInstallArgs(mainArgs)
par = getParallel(mainArgs)
if(setup):
Setup(boost, libOTe,eigen, json,function2,install, prefix, par)
else:
Build(mainArgs, cmake,install, prefix, par)
if __name__ == "__main__":
main()