@@ -24,25 +24,24 @@ def getenv(name, default):
24
24
return default
25
25
26
26
BUILD_DIR = 'build-dist'
27
- BUILD_X64_DIR = os .path .join ('build-dist' , 'x64' )
28
- BUILD_X86_DIR = os .path .join ('build-dist' , 'x86' )
29
- BUILD_ARM64_DIR = os .path .join ('build-dist' , 'arm64' ) # ARM64 build directory
30
- VERBOSE = True
31
27
DIST_DIR = 'dist'
28
+ BUILD_X64_DIR = os .path .join (BUILD_DIR , 'x64' )
29
+ BUILD_X86_DIR = os .path .join (BUILD_DIR , 'x86' )
30
+ BUILD_ARM64_DIR = os .path .join (BUILD_DIR , 'arm64' )
31
+ VERBOSE = True
32
32
FORCE_MK = False
33
33
ASSEMBLY_VERSION = None
34
34
DOTNET_CORE_ENABLED = True
35
35
DOTNET_KEY_FILE = None
36
36
JAVA_ENABLED = True
37
+ JULIA_ENABLED = False
37
38
ZIP_BUILD_OUTPUTS = False
38
39
GIT_HASH = False
39
40
PYTHON_ENABLED = True
40
41
X86ONLY = False
41
42
X64ONLY = False
42
- ARM64ONLY = False # ARM64 flag
43
- MAKEJOBS = getenv ("MAKEJOBS" , "24" )
44
-
45
- ARCHS = []
43
+ ARM64ONLY = False
44
+ ARCHITECTURES = []
46
45
47
46
def set_verbose (flag ):
48
47
global VERBOSE
@@ -53,15 +52,40 @@ def is_verbose():
53
52
54
53
def mk_dir (d ):
55
54
if not os .path .exists (d ):
55
+ if is_verbose ():
56
+ print ("Make directory" , d )
56
57
os .makedirs (d )
57
58
59
+ def get_z3_name (arch ):
60
+ version = "4"
61
+ if ASSEMBLY_VERSION :
62
+ version = ASSEMBLY_VERSION
63
+ print ("Assembly version:" , version )
64
+ if GIT_HASH :
65
+ return 'z3-%s.%s-%s-win' % (version , get_git_hash (), arch )
66
+ else :
67
+ return 'z3-%s-%s-win' % (version , arch )
68
+
69
+ def get_build_dir (arch ):
70
+ return ARCHITECTURES [arch ]
71
+
72
+ def get_build_dist_path (arch ):
73
+ return os .path .join (get_build_dir (arch ), DIST_DIR )
74
+
75
+ def get_bin_path (arch ):
76
+ return os .path .join (get_build_dist_path (arch ), "bin" )
77
+
78
+ def get_dist_path (arch ):
79
+ return os .path .join (DIST_DIR , arch )
80
+
81
+
58
82
def set_build_dir (path ):
59
- global BUILD_DIR , BUILD_X86_DIR , BUILD_X64_DIR , BUILD_ARM64_DIR , ARCHS
83
+ global BUILD_DIR , BUILD_X86_DIR , BUILD_X64_DIR , BUILD_ARM64_DIR , ARCHITECTURES
60
84
BUILD_DIR = os .path .expanduser (os .path .normpath (path ))
61
85
BUILD_X86_DIR = os .path .join (path , 'x86' )
62
86
BUILD_X64_DIR = os .path .join (path , 'x64' )
63
87
BUILD_ARM64_DIR = os .path .join (path , 'arm64' ) # Set ARM64 build directory
64
- ARCHS = {'x64' : BUILD_X64_DIR , 'x86' :BUILD_X86_DIR , 'arm64' :BUILD_ARM64_DIR }
88
+ ARCHITECTURES = {'x64' : BUILD_X64_DIR , 'x86' :BUILD_X86_DIR , 'arm64' :BUILD_ARM64_DIR }
65
89
mk_dir (BUILD_X86_DIR )
66
90
mk_dir (BUILD_X64_DIR )
67
91
mk_dir (BUILD_ARM64_DIR )
@@ -81,6 +105,7 @@ def display_help():
81
105
print (" --dotnet-key=<file> strongname sign the .NET assembly with the private key in <file>." )
82
106
print (" --nojava do not include Java bindings in the binary distribution files." )
83
107
print (" --nopython do not include Python bindings in the binary distribution files." )
108
+ print (" --julia build Julia bindings." )
84
109
print (" --zip package build outputs in zip file." )
85
110
print (" --githash include git hash in the Zip file." )
86
111
print (" --x86-only x86 dist only." )
@@ -90,7 +115,7 @@ def display_help():
90
115
91
116
# Parse configuration option for mk_make script
92
117
def parse_options ():
93
- global FORCE_MK , JAVA_ENABLED , ZIP_BUILD_OUTPUTS , GIT_HASH , DOTNET_CORE_ENABLED , DOTNET_KEY_FILE , ASSEMBLY_VERSION , PYTHON_ENABLED , X86ONLY , X64ONLY , ARM64ONLY
118
+ global FORCE_MK , JAVA_ENABLED , JULIA_ENABLED , ZIP_BUILD_OUTPUTS , GIT_HASH , DOTNET_CORE_ENABLED , DOTNET_KEY_FILE , ASSEMBLY_VERSION , PYTHON_ENABLED , X86ONLY , X64ONLY , ARM64ONLY
94
119
path = BUILD_DIR
95
120
options , remainder = getopt .gnu_getopt (sys .argv [1 :], 'b:hsf' , ['build=' ,
96
121
'help' ,
@@ -103,6 +128,7 @@ def parse_options():
103
128
'zip' ,
104
129
'githash' ,
105
130
'nopython' ,
131
+ 'julia' ,
106
132
'x86-only' ,
107
133
'x64-only' ,
108
134
'arm64-only'
@@ -128,6 +154,8 @@ def parse_options():
128
154
DOTNET_KEY_FILE = arg
129
155
elif opt == '--nojava' :
130
156
JAVA_ENABLED = False
157
+ elif opt == '--julia' :
158
+ JULIA_ENABLED = True
131
159
elif opt == '--zip' :
132
160
ZIP_BUILD_OUTPUTS = True
133
161
elif opt == '--githash' :
@@ -170,18 +198,19 @@ def get_git_hash():
170
198
171
199
# Create a build directory using mk_make.py
172
200
def mk_build_dir (arch ):
173
- global ARCHS
174
- build_path = ARCHS [arch ]
175
- install_path = DIST_DIR
201
+ build_path = get_build_dir (arch )
176
202
if not check_build_dir (build_path ) or FORCE_MK :
177
203
mk_dir (build_path )
178
-
179
204
if arch == "arm64" :
180
205
arch = "amd64_arm64"
181
206
182
207
cmds = []
208
+ if JULIA_ENABLED :
209
+ cmds .append ('julia -e "using Pkg; Pkg.add(PackageSpec(name=\" libcxxwrap_julia_jll\" ))"' )
210
+ cmds .append ('julia -e "using libcxxwrap_julia_jll; print(dirname(libcxxwrap_julia_jll.libcxxwrap_julia_path))" > tmp.env' )
211
+ cmds .append ('set /P JlCxxDir=<tmp.env' )
183
212
cmds .append (f"cd { build_path } " )
184
- cmds .append (f" call \" C: \\ Program Files \\ Microsoft Visual Studio \\ 2022 \\ Enterprise \\ VC \\ Auxiliary\\ Build \\ vcvarsall.bat\" { arch } " )
213
+ cmds .append (' call "%VCINSTALLDIR% Auxiliary\\ build \\ vcvarsall.bat" ' + arch )
185
214
cmd = []
186
215
cmd .append ("cmake -S ." )
187
216
if DOTNET_CORE_ENABLED :
@@ -196,28 +225,25 @@ def mk_build_dir(arch):
196
225
cmd .append (' -DZ3_BUILD_PYTHON_BINDINGS=ON' )
197
226
cmd .append (' -DZ3_INSTALL_PYTHON_BINDINGS=ON' )
198
227
cmd .append (' -DCMAKE_INSTALL_PYTHON_PKG_DIR=python' )
228
+ if JULIA_ENABLED :
229
+ cmd .append (' -DJlCxx_DIR=%JlCxxDir%\\ ..\\ lib\\ cmake\\ JlCxx' )
199
230
200
231
if GIT_HASH :
201
232
git_hash = get_git_hash ()
202
233
cmd .append (' -DGIT_HASH=' + git_hash )
203
234
cmd .append (' -DZ3_USE_LIB_GMP=OFF' )
204
235
cmd .append (' -DZ3_BUILD_LIBZ3_SHARED=ON' )
205
236
cmd .append (' -DCMAKE_BUILD_TYPE=RelWithDebInfo' )
206
- cmd .append (' -DCMAKE_INSTALL_PREFIX=' + install_path )
207
- cmd .append (' -G "NMake Makefiles "' )
237
+ cmd .append (' -DCMAKE_INSTALL_PREFIX=' + DIST_DIR )
238
+ cmd .append (' -G "Ninja "' )
208
239
cmd .append (' ../..\n ' )
209
240
cmds .append ("" .join (cmd ))
210
- print (cmds )
241
+ print ("CMAKE commands:" , cmds )
211
242
sys .stdout .flush ()
212
243
if exec_cmds (cmds ) != 0 :
213
244
raise MKException ("failed to run commands" )
214
245
215
246
216
- # Create build directories
217
- def mk_build_dirs ():
218
- global ARCHS
219
- for k in ARCHS :
220
- mk_build_dir (k )
221
247
222
248
# Check if on Visual Studio command prompt
223
249
def check_vc_cmd_prompt ():
@@ -245,62 +271,49 @@ def exec_cmds(cmds):
245
271
pass
246
272
return res
247
273
248
- def get_build_dir (arch ):
249
- global ARCHS
250
- return ARCHS [arch ]
274
+
251
275
252
276
def mk_z3 (arch ):
277
+ if is_verbose ():
278
+ print ("mk z3" )
253
279
build_dir = get_build_dir (arch )
254
280
if arch == "arm64" :
255
281
arch = "x64_arm64"
256
282
cmds = []
257
283
cmds .append ('call "%VCINSTALLDIR%Auxiliary\\ build\\ vcvarsall.bat" ' + arch )
258
284
cmds .append ('cd %s' % build_dir )
259
- cmds .append ('nmake install' )
285
+ cmds .append ('ninja install' )
260
286
if exec_cmds (cmds ) != 0 :
261
287
raise MKException ("Failed to make z3" )
262
288
263
- def mk_z3s ():
264
- global ARCHS
265
- for k in ARCHS :
266
- mk_z3 (k )
267
289
268
- def get_z3_name (arch ):
269
- global ASSEMBLY_VERSION
270
- version = "4"
271
- if ASSEMBLY_VERSION :
272
- version = ASSEMBLY_VERSION
273
- print ("Assembly version:" , version )
274
- if GIT_HASH :
275
- return 'z3-%s.%s-%s-win' % (version , get_git_hash (), arch )
276
- else :
277
- return 'z3-%s-%s-win' % (version , arch )
278
290
279
-
280
291
def mk_zip (arch ):
281
- global ARCHS
282
- build_dir = ARCHS [ arch ]
283
- dist_dir = os . path . join ( build_dir , DIST_DIR )
292
+ if not ZIP_BUILD_OUTPUTS :
293
+ return
294
+ build_dist = get_build_dist_path ( arch )
284
295
dist_name = get_z3_name (arch )
296
+ dist_path = get_dist_path (arch )
297
+ build_dir = get_build_dir (arch )
285
298
old = os .getcwd ()
286
299
try :
287
- os .chdir (dist_dir )
288
- zfname = '%s.zip' % dist_name
300
+ if is_verbose ():
301
+ print ("dist path" , dist_path )
302
+ mk_dir (dist_path )
303
+ zfname = os .path .join (dist_path , '%s.zip' % dist_name )
289
304
zipout = zipfile .ZipFile (zfname , 'w' , zipfile .ZIP_DEFLATED )
290
- for root , dirs , files in os .walk (dist_path ):
305
+ os .chdir (build_dist )
306
+ for root , dirs , files in os .walk ("." ):
291
307
for f in files :
308
+ if is_verbose ():
309
+ print ("adding " , os .path .join (root , f ))
292
310
zipout .write (os .path .join (root , f ))
293
311
if is_verbose ():
294
312
print ("Generated '%s'" % zfname )
295
313
except :
296
314
pass
297
315
os .chdir (old )
298
316
299
- # Create a zip file for each platform
300
- def mk_zips ():
301
- global ARCHS
302
- for k in ARCHS :
303
- mk_zip (k )
304
317
305
318
306
319
VS_RUNTIME_PATS = [re .compile (r'vcomp.*\.dll' ),
@@ -334,35 +347,36 @@ def check_root(root):
334
347
vs_runtime_files .append (fname )
335
348
if not vs_runtime_files :
336
349
raise MKException ("Did not find any runtime files to include" )
337
- build_dir = get_build_dir (arch )
338
- bin_dist_path = os .path .join (build_dir , DIST_DIR , 'bin' )
350
+ bin_dist_path = get_bin_path (arch )
339
351
for f in vs_runtime_files :
340
352
shutil .copy (f , bin_dist_path )
341
353
if is_verbose ():
342
354
print ("Copied '%s' to '%s'" % (f , bin_dist_path ))
343
-
344
- def cp_vs_runtimes ():
345
- global ARCHS
346
- for k in ARCHS :
347
- cp_vs_runtime (k )
348
355
349
356
def cp_license (arch ):
350
- shutil .copy ("LICENSE.txt" , os .path .join (DIST_DIR , get_z3_name (arch )))
351
-
352
- def cp_licenses ():
353
- global ARCHS
354
- for k in ARCHS :
355
- cp_license (k )
356
-
357
+ if is_verbose ():
358
+ print ("copy licence" )
359
+ path = get_build_dist_path (arch )
360
+ mk_dir (path )
361
+ shutil .copy ("LICENSE.txt" , path )
362
+
363
+ def cp_pdb (arch ):
364
+ if is_verbose ():
365
+ print ("copy pdb" )
366
+ build_dir = get_build_dir (arch )
367
+ bin_path = get_bin_path (arch )
368
+ mk_dir (bin_path )
369
+ for f in os .listdir (build_dir ):
370
+ if f .endswith ("pdb" ):
371
+ shutil .copy (os .path .join (build_dir , f ), bin_path )
357
372
358
373
def build_for_arch (arch ):
359
- global ARCHS
360
374
mk_build_dir (arch )
361
375
mk_z3 (arch )
362
376
cp_license (arch )
377
+ cp_pdb (arch )
363
378
cp_vs_runtime (arch )
364
- if ZIP_BUILD_OUTPUTS :
365
- mk_zip (arch )
379
+ mk_zip (arch )
366
380
367
381
# Entry point
368
382
def main ():
@@ -379,12 +393,8 @@ def main():
379
393
elif ARM64ONLY :
380
394
build_for_arch ("arm64" )
381
395
else :
382
- mk_build_dirs ()
383
- mk_z3s ()
384
- cp_licenses ()
385
- cp_vs_runtimes ()
386
- if ZIP_BUILD_OUTPUTS :
387
- mk_zips ()
396
+ for arch in ARCHITECTURES :
397
+ build_for_arch (arch )
388
398
389
399
main ()
390
400
0 commit comments