linker-wrapper.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. from __future__ import absolute_import, print_function, unicode_literals
  2. import os
  3. import pipes
  4. import subprocess
  5. import sys
  6. args = [
  7. os.environ["RUST_ANDROID_GRADLE_CC"],
  8. os.environ["RUST_ANDROID_GRADLE_CC_LINK_ARG"],
  9. ] + sys.argv[1:]
  10. def update_in_place(arglist):
  11. # The `gcc` library is not included starting from NDK version 23.
  12. # Work around by using `unwind` replacement.
  13. ndk_major_version = os.environ["CARGO_NDK_MAJOR_VERSION"]
  14. if ndk_major_version.isdigit():
  15. if 23 <= int(ndk_major_version):
  16. for i, arg in enumerate(arglist):
  17. if arg.startswith("-lgcc"):
  18. # This is one way to preserve line endings.
  19. arglist[i] = "-lunwind" + arg[len("-lgcc") :]
  20. update_in_place(args)
  21. for arg in args:
  22. if arg.startswith("@"):
  23. fileargs = open(arg[1:], "r").read().splitlines(keepends=True)
  24. update_in_place(fileargs)
  25. open(arg[1:], "w").write("".join(fileargs))
  26. # This only appears when the subprocess call fails, but it's helpful then.
  27. printable_cmd = " ".join(pipes.quote(arg) for arg in args)
  28. print(printable_cmd)
  29. sys.exit(subprocess.call(args))