-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
51 lines (40 loc) · 1.44 KB
/
run.py
File metadata and controls
51 lines (40 loc) · 1.44 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
import argparse
import os
import pathlib
import platform
import subprocess
BLACK = "\u001b[30m"
RED = "\u001b[31m"
GREEN = "\u001b[32m"
WHITE = "\u001b[97m"
def cprint(text, color):
print(f"{color}{text}{WHITE}")
compile_stdlib = True
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("file", help="The file to compile")
args = parser.parse_args()
outfile = pathlib.Path("a.out")
env = {**os.environ, "RUST_BACKTRACE": "full"}
if outfile.is_file():
outfile.unlink()
result = subprocess.run(["cargo", "run", "--release", args.file], env=env)
if result.returncode != 0:
exit(result.returncode)
if platform.system() == "Darwin":
subprocess.check_call(["cc", outfile])
result = subprocess.run(["./a.out"])
cprint("Successfully compiled for MacOS", GREEN)
print(result)
if platform.system() == "Windows":
if compile_stdlib:
cprint("Compiling stdlib", GREEN)
if os.path.isfile("builtins.obj"):
os.unlink("builtins.obj")
if os.path.isfile("builtins.dll"):
os.unlink("builtins.dll")
subprocess.check_call(["cl", "builtins.c", "/LD", "/MD", "/Wall"])
subprocess.check_call(["LINK", outfile, "builtins", "/SUBSYSTEM:CONSOLE"])
result = subprocess.run(["a.exe"])
cprint("Successfully compiled for Windows", GREEN)
print(result)