5
5
import os
6
6
import zipfile
7
7
import sys
8
+ from multiprocessing import Pool
8
9
9
10
def make_release_tarballs ():
10
11
VERSION = None
11
12
if VERSION is None :
12
13
process = subprocess .run (["zig" , "build" , "run-zigverm" , "--" , "--version" ], check = True , capture_output = True )
13
14
VERSION = process .stdout .decode ('utf-8' ).strip ()
14
15
15
- try :
16
16
targets = [
17
17
["aarch64" , "macos" ],
18
18
["x86_64" , "macos" ],
@@ -25,33 +25,44 @@ def make_release_tarballs():
25
25
if not os .path .exists ("releases" ):
26
26
os .mkdir ("releases" )
27
27
28
- for target in targets :
29
- print (f"Building for { target } " )
30
- target_str = f"{ target [0 ]} -{ target [1 ]} "
31
- target_dir = "zigverm-" + VERSION + "-" + target_str
32
- subprocess .run (["zig" , "build" , "install" , "--prefix" , "releases/" ,
33
- "--prefix-exe-dir" , target_dir , "--release=safe" ,
34
- f"-Dtarget={ target_str } " ], check = True )
35
- subprocess .run (["zig" , "build" , "install" , "--prefix" , "releases/" ,
36
- "--prefix-exe-dir" , target_dir , "--release=safe" ,
37
- f"-Dtarget={ target_str } " ], check = True )
28
+ with Pool (processes = len (targets )) as pool :
29
+ for target in targets :
30
+ pool .apply_async (make_target_release , [target , VERSION ])
31
+
32
+ pool .close ()
33
+ pool .join ()
38
34
39
- with zipfile .ZipFile ("releases/" + target_dir + ".zip" , "w" ) as z :
40
- z .write ("releases/" + target_dir , target_dir );
41
- if target [1 ] == "windows" :
42
- exe_ext = ".exe"
43
- else :
44
- exe_ext = ""
35
+ def make_target_release (target : str , version : str ):
36
+ try :
37
+ print (f"Building for { target } " )
38
+ target_str = f"{ target [0 ]} -{ target [1 ]} "
39
+ target_dir = "zigverm-" + version + "-" + target_str
40
+ subprocess .run (["zig" , "build" , "install" , "--prefix" , "releases/" ,
41
+ "--prefix-exe-dir" , target_dir , "--release=safe" ,
42
+ f"-Dtarget={ target_str } " ], check = True , stderr = subprocess .DEVNULL )
43
+ subprocess .run (["zig" , "build" , "install" , "--prefix" , "releases/" ,
44
+ "--prefix-exe-dir" , target_dir , "--release=safe" ,
45
+ f"-Dtarget={ target_str } " ], check = True , stderr = subprocess .DEVNULL )
45
46
46
- z .write ("releases/" + target_dir + "/zigverm" +
47
- exe_ext , target_dir + "/zigverm" )
48
- z .write ("releases/" + target_dir + "/zig" + exe_ext , target_dir + "/zig" )
49
- z .write ("LICENSE" , target_dir + "/LICENSE" )
50
- z .write ("README.md" , target_dir + "/README" )
47
+ with zipfile .ZipFile ("releases/" + target_dir + ".zip" , "w" ) as z :
48
+ z .write ("releases/" + target_dir , target_dir );
49
+ if target [1 ] == "windows" :
50
+ exe_ext = ".exe"
51
+ else :
52
+ exe_ext = ""
53
+
54
+ z .write ("releases/" + target_dir + "/zigverm" +
55
+ exe_ext , target_dir + "/zigverm" )
56
+ z .write ("releases/" + target_dir + "/zig" + exe_ext , target_dir + "/zig" )
57
+ z .write ("LICENSE" , target_dir + "/LICENSE" )
58
+ z .write ("README.md" , target_dir + "/README" )
51
59
except subprocess .CalledProcessError as e :
52
- print ("\n \n ===========================================================" )
53
- print (f"ERROR: Workgroup failed with exit code { e .returncode } " )
54
- print ("===========================================================" )
60
+ eprint ("\n \n =====================================================================================================" )
61
+ eprint (f"ERROR: Build failed for target '{ target } ' with exit code { e .returncode } " )
62
+ eprint ("=========================================================================================================" )
63
+
64
+ def eprint (text : str ):
65
+ print (f"\x1b [33m{ text } " , file = sys .stderr )
55
66
56
67
57
68
def main ():
@@ -60,7 +71,7 @@ def main():
60
71
if args [1 ] == "make-release" :
61
72
make_release_tarballs ()
62
73
else :
63
- print (f"\x1b [33minvalid usage. No such subcommand '{ args [1 ]} '" , file = sys . stderr )
74
+ eprint (f"invalid usage. No such subcommand '{ args [1 ]} '" )
64
75
65
76
66
77
if __name__ == "__main__" :
0 commit comments