-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.py
93 lines (70 loc) · 2.33 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
import subprocess
import sys
from shutil import which
LLVM_VERSION = "18"
CARGO_VERSION = "cargo 1.75.0 (1d8b05cdd 2023-11-20)"
# 1. check that llvm-config exists and version is usable
# 2. if llvm exists continue to step 4
# 3. if llvm not exists install llvm@18 from homebrew
# 4. check that rustc & cargo of correct version exists
# 5. if correct cargo version exists skip to step 7
# 6. if cargo version incorrect install correct version
# 7. run cargo build
# 8. copy to usr/bin
def check_llvm():
if which("llvm-config") is not None:
print("llvm is installed.")
return True
else:
print("llc is not installed.")
return False
def install_llvm():
try:
print(f"Downloading LLVM version {LLVM_VERSION}...")
subprocess.check_output(['brew', 'install', f'llvm@{LLVM_VERSION}'])
except Exception as e:
print(f"An error occurred while installing LLVM: {e}")
sys.exit(1)
def check_rust():
if which("cargo") is not None:
print(f"Cargo is already installed.")
return True
else:
print(f"Cargo is not installed.")
return False
def install_rust():
try:
print("Installing Cargo...")
subprocess.check_output(['brew', 'install', 'cargo'])
except subprocess.CalledProcessError as e:
print(f"An error occurred while installing Cargo: {e}")
sys.exit(1)
def run_cargo_build():
try:
print("Running Cargo build...")
subprocess.check_call(["cargo", "build", "--release"])
print("Cargo build completed successfully.")
except subprocess.CalledProcessError as e:
print(f"An error occurred during the Cargo build: {e}")
sys.exit(1)
def copy_to_usr_bin():
try:
print("Copying to usr/bin...")
subprocess.check_call(["cp", "./target/release/microc", "/usr/bin"])
print("Successfully copied to '/usr/bin'")
except subprocess.CalledProcessError as e:
print(f"An error occurred while copying to '/usr/bin': {e}")
sys.exit(1)
def main():
try:
if not check_llvm():
install_llvm()
if not check_rust():
install_rust()
run_cargo_build()
copy_to_usr_bin()
except Exception as e:
print(f"A fatal error occurred: {e}")
sys.exit(1)
if __name__ == "__main__":
main()