-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathz.py
More file actions
executable file
·109 lines (90 loc) · 3.07 KB
/
z.py
File metadata and controls
executable file
·109 lines (90 loc) · 3.07 KB
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
#!/usr/bin/env python
import shutil
import sys
import subprocess
import os
import zipfile
from multiprocessing import Pool
def make_release_tarballs():
VERSION = None
if VERSION is None:
process = subprocess.run(
["zig", "build", "run-zigverm", "--", "--version"],
check=True,
capture_output=True,
)
VERSION = process.stdout.decode("utf-8").strip()
targets = [
["aarch64", "macos"],
["x86_64", "macos"],
["aarch64", "linux"],
["x86_64", "linux"],
["x86", "linux"],
["x86_64", "windows"],
["x86", "windows"],
]
if not os.path.exists("releases"):
os.mkdir("releases")
with Pool(processes=len(targets)) as pool:
for target in targets:
pool.apply_async(make_target_release, [target, VERSION])
pool.close()
pool.join()
def make_target_release(target: str, version: str):
try:
print(f"Building for {target}")
target_str = f"{target[0]}-{target[1]}"
target_dir = "zigverm-" + version + "-" + target_str
subprocess.run(
[
"zig",
"build",
"install",
"--prefix",
"releases/",
"--prefix-exe-dir",
target_dir,
"--release=safe",
f"-Dtarget={target_str}",
],
check=True,
stderr=subprocess.DEVNULL,
)
with zipfile.ZipFile("releases/" + target_dir + ".zip", "w") as z:
z.write("releases/" + target_dir, target_dir)
if target[1] == "windows":
exe_ext = ".exe"
else:
exe_ext = ""
z.write(
"releases/" + target_dir + "/zigverm" + exe_ext,
target_dir + "/zigverm" + exe_ext,
)
z.write(
"releases/" + target_dir + "/zig" + exe_ext,
target_dir + "/zig" + exe_ext,
)
z.write("LICENSE", target_dir + "/LICENSE")
z.write("README.md", target_dir + "/README")
if target[1] == "windows":
shutil.copy2("releases/" + target_dir + "/zigverm-setup.exe", f"releases/zigverm-setup-{target[0]}-windows.exe");
except subprocess.CalledProcessError as e:
eprint(
"\n\n====================================================================================================="
)
eprint(
f"ERROR: Build failed for target '{target}' with exit code {e.returncode}"
)
eprint(
"========================================================================================================="
)
def eprint(text: str):
print(f"\x1b[33m{text}", file=sys.stderr)
def main():
args = sys.argv
if args[1] == "make-release":
make_release_tarballs()
else:
eprint(f"invalid usage. No such subcommand '{args[1]}'")
if __name__ == "__main__":
main()