rust-lld-wrapper 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/usr/bin/env python3
  2. # A wrapper for rust-lld that removes certain arguments inserted by rustc that
  3. # we'd like to override
  4. import sys
  5. import subprocess
  6. from os import path
  7. def main():
  8. args = sys.argv[1:]
  9. strip_debug = "--v86-strip-debug" in args
  10. # filter out args inserted by rustc
  11. TO_REMOVE = {
  12. "--export-table",
  13. "--stack-first",
  14. "--strip-debug",
  15. "--v86-strip-debug",
  16. }
  17. args = list(filter(lambda arg: arg not in TO_REMOVE, args))
  18. if strip_debug:
  19. args += ["--strip-debug"]
  20. lld = find_rust_lld()
  21. result = subprocess.run([lld] + args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  22. print(result.stderr, file=sys.stderr)
  23. print(result.stdout)
  24. result.check_returncode()
  25. def find_rust_lld():
  26. which = subprocess.run(["rustup", "which", "rustc"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  27. which.check_returncode()
  28. rustc_path = which.stdout.decode("utf8").strip()
  29. assert path.basename(rustc_path) == "rustc"
  30. bin_path = path.dirname(rustc_path)
  31. rust_lld_path = path.join(bin_path, "../lib/rustlib/x86_64-unknown-linux-gnu/bin/rust-lld")
  32. assert path.isfile(rust_lld_path)
  33. return rust_lld_path
  34. main()