-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrustc-sysroot
More file actions
executable file
·46 lines (36 loc) · 1.17 KB
/
Copy pathrustc-sysroot
File metadata and controls
executable file
·46 lines (36 loc) · 1.17 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
#!/usr/bin/env python3
import re
import os
import subprocess
import sys
from pathlib import Path
target = "x86_64-unknown-elpytios"
def main():
if len(sys.argv) < 2:
print("rustc-sysroot: expected rustc path as first argument", file=sys.stderr)
sys.exit(1)
real_rustc = sys.argv[1]
rustc_args = sys.argv[2:]
root = Path(__file__).resolve().parent
sysroot = root / "std" / "sysroot"
should_inject = False
for i, arg in enumerate(rustc_args):
if arg == "--target" and i + 1 < len(rustc_args) and (rustc_args[i + 1] == target or rustc_args[i + 1].endswith(f"{target}.json")):
should_inject = True
break
if should_inject:
for i, arg in enumerate(rustc_args):
if arg == "--sysroot" or arg.startswith("--sysroot="):
break
else:
rustc_args.extend(["--sysroot", str(sysroot)])
subprocess.run([real_rustc, *rustc_args], close_fds=False, shell=False, check=True)
if __name__ == "__main__":
try:
main()
except subprocess.CalledProcessError as e:
if (err := e.stderr):
print(err)
exit(1)
except:
exit(1)