update-rust 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. #!/usr/bin/env python3
  2. import argparse
  3. import pathlib
  4. import requests
  5. import sys
  6. # When updating this list, also update:
  7. # - package/rustc/Config.in.host:
  8. # BR2_PACKAGE_HOST_RUSTC_ARCH_SUPPORTS
  9. # - package/rustc/rustc.mk:
  10. # RUSTC_HOST_NAME
  11. RUST_HOSTS = [
  12. "aarch64-unknown-linux-gnu",
  13. "i686-unknown-linux-gnu",
  14. "powerpc-unknown-linux-gnu",
  15. "powerpc64-unknown-linux-gnu",
  16. "powerpc64le-unknown-linux-gnu",
  17. "riscv64gc-unknown-linux-gnu",
  18. "s390x-unknown-linux-gnu",
  19. "x86_64-unknown-linux-gnu",
  20. ]
  21. # When updating this list, also update one of:
  22. # - package/rustc/Config.in.host:
  23. # BR2_PACKAGE_HOST_RUSTC_TARGET_TIER1_PLATFORMS
  24. # BR2_PACKAGE_HOST_RUSTC_TARGET_TIER2_HOST_TOOLS_PLATFORMS
  25. # BR2_PACKAGE_HOST_RUSTC_TARGET_TIER2_PLATFORMS
  26. # - package/rustc/rustc.mk:
  27. # RUSTC_TARGET_NAME
  28. # and check whether one of the follwoing needs updating:
  29. # - package/rustc/Config.in.host:
  30. # BR2_PACKAGE_HOST_RUSTC_ARCH
  31. # BR2_PACKAGE_HOST_RUSTC_ABI
  32. RUST_TARGETS = [
  33. "aarch64-unknown-linux-gnu",
  34. "aarch64-unknown-linux-musl",
  35. "arm-unknown-linux-gnueabi",
  36. "arm-unknown-linux-gnueabihf",
  37. "arm-unknown-linux-musleabi",
  38. "arm-unknown-linux-musleabihf",
  39. "armv5te-unknown-linux-gnueabi",
  40. "armv5te-unknown-linux-musleabi",
  41. "armv7-unknown-linux-gnueabi",
  42. "armv7-unknown-linux-gnueabihf",
  43. "armv7-unknown-linux-musleabi",
  44. "armv7-unknown-linux-musleabihf",
  45. "i586-unknown-linux-gnu",
  46. "i586-unknown-linux-musl",
  47. "i686-unknown-linux-gnu",
  48. "i686-unknown-linux-musl",
  49. "mips-unknown-linux-musl",
  50. "mips64-unknown-linux-muslabi64",
  51. "mips64el-unknown-linux-muslabi64",
  52. "mipsel-unknown-linux-musl",
  53. "powerpc-unknown-linux-gnu",
  54. "powerpc64-unknown-linux-gnu",
  55. "powerpc64le-unknown-linux-gnu",
  56. "riscv64gc-unknown-linux-gnu",
  57. "s390x-unknown-linux-gnu",
  58. "sparc64-unknown-linux-gnu",
  59. "x86_64-unknown-linux-gnu",
  60. "x86_64-unknown-linux-musl",
  61. ]
  62. RUST_DIST_URL = "https://static.rust-lang.org/dist"
  63. LICENSES = {
  64. "APACHE": "62c7a1e35f56406896d7aa7ca52d0cc0d272ac022b5d2796e7d6905db8a3636a",
  65. "MIT": "23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3",
  66. }
  67. def update_mk_file(mk_file, new_version):
  68. with open(mk_file, "r") as fd:
  69. lines = fd.readlines()
  70. version_var = pathlib.Path(mk_file).stem.upper().replace("-", "_") + "_VERSION"
  71. with open(mk_file, "w") as fd:
  72. for line in lines:
  73. words = line.split()
  74. if len(words) == 3 and words[0] == version_var and words[1] == "=":
  75. fd.write(f"{words[0]} = {new_version}\n")
  76. else:
  77. fd.write(line)
  78. def gen_hash_file_src(hash_file, new_version):
  79. with open(hash_file, "w") as fd:
  80. fd.write(f"# Generated with {sys.argv[0]}\n# Do not edit manually\n\n")
  81. f_name = f"rustc-{new_version}-src.tar.xz"
  82. print(f"\r\033[KUpdating {f_name}", end="")
  83. h_url = f"{RUST_DIST_URL}/{f_name}.sha256"
  84. r = requests.get(h_url)
  85. if r.status_code != 200:
  86. raise RuntimeError(f"No hash for {f_name}. Has source been removed?")
  87. # rstrip() content, and explicitly add the \n, in case
  88. # a hash file does not have a trailing \n.
  89. fd.write(f"# From {h_url}\nsha256 {r.content.decode().rstrip()}\n")
  90. fd.write("# Locally generated\n")
  91. for license in LICENSES:
  92. fd.write(f"sha256 {LICENSES[license]} LICENSE-{license}\n")
  93. def gen_hash_file_bin(hash_file, new_version):
  94. with open(hash_file, "w") as fd:
  95. fd.write(f"# Generated with {sys.argv[0]}\n# Do not edit manually\n\n")
  96. for host in RUST_HOSTS:
  97. f_name = f"rust-{new_version}-{host}.tar.xz"
  98. print(f"\r\033[KUpdating {f_name}", end="")
  99. h_url = f"{RUST_DIST_URL}/{f_name}.sha256"
  100. r = requests.get(h_url)
  101. if r.status_code != 200:
  102. raise RuntimeError(f"No hash for {f_name}. Has host {host} been removed?")
  103. # rstrip() content, and explicitly add the \n, in case
  104. # a hash file does not have a trailing \n.
  105. fd.write(f"# From {h_url}\nsha256 {r.content.decode().rstrip()}\n")
  106. for target in RUST_TARGETS:
  107. f_name = f"rust-std-{new_version}-{target}.tar.xz"
  108. print(f"\r\033[KUpdating {f_name}", end="")
  109. h_url = f"{RUST_DIST_URL}/{f_name}.sha256"
  110. r = requests.get(h_url)
  111. if r.status_code != 200:
  112. raise RuntimeError(f"No hash for {f_name}. Has target {target} been removed?")
  113. # rstrip() content, and explicitly add the \n, in case
  114. # a hash file does not have a trailing \n.
  115. fd.write(f"# From {h_url}\nsha256 {r.content.decode().rstrip()}\n")
  116. fd.write("# Locally generated\n")
  117. for license in LICENSES:
  118. fd.write(f"sha256 {LICENSES[license]} LICENSE-{license}\n")
  119. def main():
  120. parser = argparse.ArgumentParser(description="Update rust")
  121. parser.add_argument("version", help="Rust version to update to", type=str)
  122. args = parser.parse_args()
  123. try:
  124. update_mk_file("package/rust/rust.mk", args.version)
  125. update_mk_file("package/rust-bin/rust-bin.mk", args.version)
  126. gen_hash_file_src("package/rust/rust.hash", args.version)
  127. gen_hash_file_bin("package/rust-bin/rust-bin.hash", args.version)
  128. except FileNotFoundError as e:
  129. print(f"{e.filename}: {e.strerror} ({sys.argv[0]} must be run at the root of the Buildroot tree)")
  130. print("\r\033[K", end="")
  131. if __name__ == "__main__":
  132. main()