Skip to content

Commit 4be8b7d

Browse files
update win-dist
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
1 parent 908aaa0 commit 4be8b7d

File tree

2 files changed

+93
-83
lines changed

2 files changed

+93
-83
lines changed

scripts/mk_win_dist_cmake.py

+87-77
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,24 @@ def getenv(name, default):
2424
return default
2525

2626
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
3127
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
3232
FORCE_MK = False
3333
ASSEMBLY_VERSION = None
3434
DOTNET_CORE_ENABLED = True
3535
DOTNET_KEY_FILE = None
3636
JAVA_ENABLED = True
37+
JULIA_ENABLED = False
3738
ZIP_BUILD_OUTPUTS = False
3839
GIT_HASH = False
3940
PYTHON_ENABLED = True
4041
X86ONLY = False
4142
X64ONLY = False
42-
ARM64ONLY = False # ARM64 flag
43-
MAKEJOBS = getenv("MAKEJOBS", "24")
44-
45-
ARCHS = []
43+
ARM64ONLY = False
44+
ARCHITECTURES = []
4645

4746
def set_verbose(flag):
4847
global VERBOSE
@@ -53,15 +52,40 @@ def is_verbose():
5352

5453
def mk_dir(d):
5554
if not os.path.exists(d):
55+
if is_verbose():
56+
print("Make directory", d)
5657
os.makedirs(d)
5758

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+
5882
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
6084
BUILD_DIR = os.path.expanduser(os.path.normpath(path))
6185
BUILD_X86_DIR = os.path.join(path, 'x86')
6286
BUILD_X64_DIR = os.path.join(path, 'x64')
6387
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}
6589
mk_dir(BUILD_X86_DIR)
6690
mk_dir(BUILD_X64_DIR)
6791
mk_dir(BUILD_ARM64_DIR)
@@ -81,6 +105,7 @@ def display_help():
81105
print(" --dotnet-key=<file> strongname sign the .NET assembly with the private key in <file>.")
82106
print(" --nojava do not include Java bindings in the binary distribution files.")
83107
print(" --nopython do not include Python bindings in the binary distribution files.")
108+
print(" --julia build Julia bindings.")
84109
print(" --zip package build outputs in zip file.")
85110
print(" --githash include git hash in the Zip file.")
86111
print(" --x86-only x86 dist only.")
@@ -90,7 +115,7 @@ def display_help():
90115

91116
# Parse configuration option for mk_make script
92117
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
94119
path = BUILD_DIR
95120
options, remainder = getopt.gnu_getopt(sys.argv[1:], 'b:hsf', ['build=',
96121
'help',
@@ -103,6 +128,7 @@ def parse_options():
103128
'zip',
104129
'githash',
105130
'nopython',
131+
'julia',
106132
'x86-only',
107133
'x64-only',
108134
'arm64-only'
@@ -128,6 +154,8 @@ def parse_options():
128154
DOTNET_KEY_FILE = arg
129155
elif opt == '--nojava':
130156
JAVA_ENABLED = False
157+
elif opt == '--julia':
158+
JULIA_ENABLED = True
131159
elif opt == '--zip':
132160
ZIP_BUILD_OUTPUTS = True
133161
elif opt == '--githash':
@@ -170,18 +198,19 @@ def get_git_hash():
170198

171199
# Create a build directory using mk_make.py
172200
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)
176202
if not check_build_dir(build_path) or FORCE_MK:
177203
mk_dir(build_path)
178-
179204
if arch == "arm64":
180205
arch = "amd64_arm64"
181206

182207
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')
183212
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)
185214
cmd = []
186215
cmd.append("cmake -S .")
187216
if DOTNET_CORE_ENABLED:
@@ -196,28 +225,25 @@ def mk_build_dir(arch):
196225
cmd.append(' -DZ3_BUILD_PYTHON_BINDINGS=ON')
197226
cmd.append(' -DZ3_INSTALL_PYTHON_BINDINGS=ON')
198227
cmd.append(' -DCMAKE_INSTALL_PYTHON_PKG_DIR=python')
228+
if JULIA_ENABLED:
229+
cmd.append(' -DJlCxx_DIR=%JlCxxDir%\\..\\lib\\cmake\\JlCxx')
199230

200231
if GIT_HASH:
201232
git_hash = get_git_hash()
202233
cmd.append(' -DGIT_HASH=' + git_hash)
203234
cmd.append(' -DZ3_USE_LIB_GMP=OFF')
204235
cmd.append(' -DZ3_BUILD_LIBZ3_SHARED=ON')
205236
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"')
208239
cmd.append(' ../..\n')
209240
cmds.append("".join(cmd))
210-
print(cmds)
241+
print("CMAKE commands:", cmds)
211242
sys.stdout.flush()
212243
if exec_cmds(cmds) != 0:
213244
raise MKException("failed to run commands")
214245

215246

216-
# Create build directories
217-
def mk_build_dirs():
218-
global ARCHS
219-
for k in ARCHS:
220-
mk_build_dir(k)
221247

222248
# Check if on Visual Studio command prompt
223249
def check_vc_cmd_prompt():
@@ -245,62 +271,49 @@ def exec_cmds(cmds):
245271
pass
246272
return res
247273

248-
def get_build_dir(arch):
249-
global ARCHS
250-
return ARCHS[arch]
274+
251275

252276
def mk_z3(arch):
277+
if is_verbose():
278+
print("mk z3")
253279
build_dir = get_build_dir(arch)
254280
if arch == "arm64":
255281
arch = "x64_arm64"
256282
cmds = []
257283
cmds.append('call "%VCINSTALLDIR%Auxiliary\\build\\vcvarsall.bat" ' + arch)
258284
cmds.append('cd %s' % build_dir)
259-
cmds.append('nmake install')
285+
cmds.append('ninja install')
260286
if exec_cmds(cmds) != 0:
261287
raise MKException("Failed to make z3")
262288

263-
def mk_z3s():
264-
global ARCHS
265-
for k in ARCHS:
266-
mk_z3(k)
267289

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)
278290

279-
280291
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)
284295
dist_name = get_z3_name(arch)
296+
dist_path = get_dist_path(arch)
297+
build_dir = get_build_dir(arch)
285298
old = os.getcwd()
286299
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)
289304
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("."):
291307
for f in files:
308+
if is_verbose():
309+
print("adding ", os.path.join(root, f))
292310
zipout.write(os.path.join(root, f))
293311
if is_verbose():
294312
print("Generated '%s'" % zfname)
295313
except:
296314
pass
297315
os.chdir(old)
298316

299-
# Create a zip file for each platform
300-
def mk_zips():
301-
global ARCHS
302-
for k in ARCHS:
303-
mk_zip(k)
304317

305318

306319
VS_RUNTIME_PATS = [re.compile(r'vcomp.*\.dll'),
@@ -334,35 +347,36 @@ def check_root(root):
334347
vs_runtime_files.append(fname)
335348
if not vs_runtime_files:
336349
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)
339351
for f in vs_runtime_files:
340352
shutil.copy(f, bin_dist_path)
341353
if is_verbose():
342354
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)
348355

349356
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)
357372

358373
def build_for_arch(arch):
359-
global ARCHS
360374
mk_build_dir(arch)
361375
mk_z3(arch)
362376
cp_license(arch)
377+
cp_pdb(arch)
363378
cp_vs_runtime(arch)
364-
if ZIP_BUILD_OUTPUTS:
365-
mk_zip(arch)
379+
mk_zip(arch)
366380

367381
# Entry point
368382
def main():
@@ -379,12 +393,8 @@ def main():
379393
elif ARM64ONLY:
380394
build_for_arch("arm64")
381395
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)
388398

389399
main()
390400

scripts/nightly.yaml

+6-6
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ stages:
169169
--zip
170170
- task: CopyFiles@2
171171
inputs:
172-
sourceFolder: build-dist/x86/dist
172+
sourceFolder: dist/x86
173173
contents: '*.zip'
174174
targetFolder: $(Build.ArtifactStagingDirectory)
175175
- task: PublishPipelineArtifact@1
@@ -179,7 +179,7 @@ stages:
179179
- task: CopyFiles@2
180180
displayName: 'Collect Symbols'
181181
inputs:
182-
sourceFolder: build-dist/x86/dist
182+
sourceFolder: build-dist/x86
183183
contents: '**/*.pdb'
184184
targetFolder: '$(Build.ArtifactStagingDirectory)/symbols'
185185
# Publish symbol archive to match nuget package
@@ -209,7 +209,7 @@ stages:
209209
--zip
210210
- task: CopyFiles@2
211211
inputs:
212-
sourceFolder: build-dist/x64/dist
212+
sourceFolder: dist/x64
213213
contents: '*.zip'
214214
targetFolder: $(Build.ArtifactStagingDirectory)
215215
- task: PublishPipelineArtifact@1
@@ -219,7 +219,7 @@ stages:
219219
- task: CopyFiles@2
220220
displayName: 'Collect Symbols'
221221
inputs:
222-
sourceFolder: build-dist/x64/dist
222+
sourceFolder: build-dist/x64
223223
contents: '**/*.pdb'
224224
targetFolder: '$(Build.ArtifactStagingDirectory)/symbols'
225225
# Publish symbol archive to match nuget package
@@ -249,7 +249,7 @@ stages:
249249
--zip
250250
- task: CopyFiles@2
251251
inputs:
252-
sourceFolder: build-dist/arm64/dist
252+
sourceFolder: dist/arm64
253253
contents: '*.zip'
254254
targetFolder: $(Build.ArtifactStagingDirectory)
255255
- task: PublishPipelineArtifact@1
@@ -259,7 +259,7 @@ stages:
259259
- task: CopyFiles@2
260260
displayName: 'Collect Symbols'
261261
inputs:
262-
sourceFolder: build-dist/arm64/dist
262+
sourceFolder: build-dist/arm64
263263
contents: '**/*.pdb'
264264
targetFolder: '$(Build.ArtifactStagingDirectory)/symbols'
265265
# Publish symbol archive to match nuget package

0 commit comments

Comments
 (0)