v86/tools/rust-lld-wrapper

66 lines
1.7 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env python3
# A wrapper for rust-lld that removes certain arguments inserted by rustc that
# we'd like to override
import sys
import subprocess
import re
from os import path
def main():
args = sys.argv[1:]
strip_debug = "--v86-strip-debug" in args
# filter out args inserted by rustc
2018-08-09 23:05:33 +02:00
TO_REMOVE = {
"--export-table",
2018-08-09 23:05:33 +02:00
"--stack-first",
"--strip-debug",
"--v86-strip-debug",
2018-08-09 23:05:33 +02:00
}
args = list(filter(lambda arg: arg not in TO_REMOVE, args))
if strip_debug:
args += ["--strip-debug"]
lld = find_rust_lld()
result = subprocess.run([lld] + args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
print(result.stderr, file=sys.stderr)
print(result.stdout)
2021-01-01 02:14:29 +01:00
result.check_returncode()
def find_host_triplet():
rustc = subprocess.run(["rustc", "--version", "--verbose"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
rustc.check_returncode()
rustc_details = rustc.stdout.decode("utf8")
host = re.search(r"host: (.*)", rustc_details)
if host is None:
raise ValueError("unexpected rustc output")
return host.group(1)
def find_rust_lld():
2022-09-13 17:32:10 +02:00
try:
which = subprocess.run(["rustup", "which", "rustc"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
except FileNotFoundError:
return "lld"
which.check_returncode()
rustc_path = which.stdout.decode("utf8").strip()
assert path.basename(rustc_path) == "rustc"
bin_path = path.dirname(rustc_path)
triplet = find_host_triplet()
rust_lld_path = path.join(bin_path, "../lib/rustlib", triplet, "bin/rust-lld")
assert path.isfile(rust_lld_path)
return rust_lld_path
main()