update-rust 5.4 KB

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