update-rust 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #!/usr/bin/env python3
  2. import argparse
  3. import pathlib
  4. import sys
  5. import urllib.request
  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. "powerpc-unknown-linux-gnu",
  50. "powerpc64-unknown-linux-gnu",
  51. "powerpc64le-unknown-linux-gnu",
  52. "riscv64gc-unknown-linux-gnu",
  53. "s390x-unknown-linux-gnu",
  54. "sparc64-unknown-linux-gnu",
  55. "x86_64-unknown-linux-gnu",
  56. "x86_64-unknown-linux-musl",
  57. ]
  58. RUST_DIST_URL = "https://static.rust-lang.org/dist"
  59. LICENSES = {
  60. "APACHE": "62c7a1e35f56406896d7aa7ca52d0cc0d272ac022b5d2796e7d6905db8a3636a",
  61. "MIT": "23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3",
  62. }
  63. def update_mk_file(mk_file, new_version):
  64. with open(mk_file, "r") as fd:
  65. lines = fd.readlines()
  66. version_var = pathlib.Path(mk_file).stem.upper().replace("-", "_") + "_VERSION"
  67. with open(mk_file, "w") as fd:
  68. for line in lines:
  69. words = line.split()
  70. if len(words) == 3 and words[0] == version_var and words[1] == "=":
  71. fd.write(f"{words[0]} = {new_version}\n")
  72. else:
  73. fd.write(line)
  74. def gen_hash_file_src(hash_file, new_version):
  75. with open(hash_file, "w") as fd:
  76. fd.write(f"# Generated with {sys.argv[0]}\n# Do not edit manually\n\n")
  77. f_name = f"rustc-{new_version}-src.tar.xz"
  78. print(f"\r\033[KUpdating {f_name}", end="")
  79. h_url = f"{RUST_DIST_URL}/{f_name}.sha256"
  80. with urllib.request.urlopen(h_url) as r:
  81. if r.status != 200:
  82. raise RuntimeError(f"No hash for {f_name}. Has source been removed?")
  83. # rstrip() content, and explicitly add the \n, in case
  84. # a hash file does not have a trailing \n.
  85. fd.write(f"# From {h_url}\nsha256 {r.read().decode().rstrip()}\n")
  86. fd.write("# Locally generated\n")
  87. for license in LICENSES:
  88. fd.write(f"sha256 {LICENSES[license]} LICENSE-{license}\n")
  89. def gen_hash_file_bin(hash_file, new_version):
  90. with open(hash_file, "w") as fd:
  91. fd.write(f"# Generated with {sys.argv[0]}\n# Do not edit manually\n\n")
  92. for host in RUST_HOSTS:
  93. f_name = f"rust-{new_version}-{host}.tar.xz"
  94. print(f"\r\033[KUpdating {f_name}", end="")
  95. h_url = f"{RUST_DIST_URL}/{f_name}.sha256"
  96. with urllib.request.urlopen(h_url) as r:
  97. if r.status != 200:
  98. raise RuntimeError(f"No hash for {f_name}. Has host {host} been removed?")
  99. # rstrip() content, and explicitly add the \n, in case
  100. # a hash file does not have a trailing \n.
  101. fd.write(f"# From {h_url}\nsha256 {r.read().decode().rstrip()}\n")
  102. for target in RUST_TARGETS:
  103. f_name = f"rust-std-{new_version}-{target}.tar.xz"
  104. print(f"\r\033[KUpdating {f_name}", end="")
  105. h_url = f"{RUST_DIST_URL}/{f_name}.sha256"
  106. with urllib.request.urlopen(h_url) as r:
  107. if r.status != 200:
  108. raise RuntimeError(f"No hash for {f_name}. Has target {target} been removed?")
  109. # rstrip() content, and explicitly add the \n, in case
  110. # a hash file does not have a trailing \n.
  111. fd.write(f"# From {h_url}\nsha256 {r.read().decode().rstrip()}\n")
  112. fd.write("# Locally generated\n")
  113. for license in LICENSES:
  114. fd.write(f"sha256 {LICENSES[license]} LICENSE-{license}\n")
  115. def main():
  116. parser = argparse.ArgumentParser(description="Update rust")
  117. parser.add_argument("version", help="Rust version to update to", type=str)
  118. args = parser.parse_args()
  119. try:
  120. update_mk_file("package/rust/rust.mk", args.version)
  121. update_mk_file("package/rust-bin/rust-bin.mk", args.version)
  122. gen_hash_file_src("package/rust/rust.hash", args.version)
  123. gen_hash_file_bin("package/rust-bin/rust-bin.hash", args.version)
  124. except FileNotFoundError as e:
  125. print(f"{e.filename}: {e.strerror} ({sys.argv[0]} must be run at the root of the Buildroot tree)")
  126. print("\r\033[K", end="")
  127. if __name__ == "__main__":
  128. main()