Matthew Maurer | a67627c | 2019-06-20 13:19:25 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | |
| 3 | import subprocess |
| 4 | from os.path import abspath |
| 5 | import hashlib |
| 6 | import urllib3 |
| 7 | import tarfile |
| 8 | |
| 9 | def rustc_url(version): |
| 10 | return f"https://static.rust-lang.org/dist/rustc-{version}-src.tar.gz" |
| 11 | |
| 12 | version_sequence = ["1.21.0", "1.22.1", "1.23.0", "1.24.1", "1.25.0", "1.26.2", "1.27.2", "1.28.0", "1.29.2", "1.30.1", "1.31.1", "1.32.0", "1.33.0", "1.34.2"] |
| 13 | |
| 14 | bootstrap_version = "1.20.0" |
| 15 | bootstrap_path = abspath("mrustc-bootstrap/mrustc/mrustc-rustc-rustc/rustc-1.20.0-src/") |
| 16 | clang_prebuilt_path = abspath("mrustc-bootstrap/clang-prebuilt/clang-r353983c/bin") |
| 17 | cc = clang_prebuilt_path + "/clang" |
| 18 | cxx = clang_prebuilt_path + "/clang++" |
| 19 | ar = clang_prebuilt_path + "/llvm-ar" |
| 20 | |
| 21 | class RustBuild(object): |
| 22 | def __init__(self, version, path, stage0): |
| 23 | self.version = version |
| 24 | self.stage0 = stage0 |
| 25 | self.path = path |
| 26 | self.built = False |
| 27 | |
| 28 | def configure(self): |
| 29 | minor = self.version.split('.')[1] |
| 30 | remap = "" |
| 31 | if int(minor) > 30: |
| 32 | remap = "[rust]\nremap-debuginfo = true" |
| 33 | config_toml = f"""\ |
| 34 | [build] |
| 35 | cargo = "{self.stage0.cargo()}" |
| 36 | rustc = "{self.stage0.rustc()}" |
| 37 | full-bootstrap = true |
| 38 | vendor = true |
| 39 | extended = true |
| 40 | docs = false |
| 41 | {remap} |
| 42 | [target.x86_64-unknown-linux-gnu] |
| 43 | cc = "{cc}" |
| 44 | cxx = "{cxx}" |
| 45 | """ |
| 46 | with open(self.path + "/config.toml", "w+") as f: |
| 47 | f.write(config_toml) |
| 48 | |
| 49 | def build(self): |
| 50 | self.configure() |
| 51 | subprocess.run(["./x.py", "--stage", "3", "build"], check=True, cwd=self.path) |
| 52 | self.built = True |
| 53 | |
| 54 | def rustc(self): |
| 55 | if not self.built: |
| 56 | self.build() |
| 57 | return self.path + "/build/x86_64-unknown-linux-gnu/stage3/bin/rustc" |
| 58 | |
| 59 | def cargo(self): |
| 60 | if not self.built: |
| 61 | self.build() |
| 62 | return self.path + "/build/x86_64-unknown-linux-gnu/stage3-tools/x86_64-unknown-linux-gnu/release/cargo" |
| 63 | |
| 64 | |
| 65 | class RustPrebuilt(RustBuild): |
| 66 | def __init__(self, version, path): |
| 67 | super().__init__(version, path, None) |
| 68 | self.built = True |
| 69 | def build(self): pass |
| 70 | |
| 71 | |
| 72 | def fetch_rustc(): |
| 73 | http = urllib3.PoolManager() |
| 74 | for version in version_sequence: |
| 75 | rust_src_resp = http.request("GET", rustc_url(version), preload_content=False) |
| 76 | rust_src_tar_path = f"rustc-{version}-src.tar.gz" |
| 77 | hasher = hashlib.sha256() |
| 78 | with open(rust_src_tar_path, "wb+") as tar_file: |
| 79 | for chunk in rust_src_resp.stream(): |
| 80 | hasher.update(chunk) |
| 81 | tar_file.write(chunk) |
| 82 | rust_src_resp.release_conn() |
| 83 | print(f"rustc-{version}-src.tar.gz {hasher.hexdigest()}") |
| 84 | tarfile.open(rust_src_tar_path).extractall() |
| 85 | |
| 86 | |
| 87 | def main(): |
| 88 | fetch_rustc() |
| 89 | build = RustPrebuilt(bootstrap_version, bootstrap_path) |
| 90 | for version in version_sequence: |
| 91 | build = RustBuild(version, abspath(f"rustc-{version}-src"), build) |
| 92 | print(f"rustc: {build.rustc()}") |
| 93 | print(f"cargo: {build.rustc()}") |
| 94 | |
| 95 | |
| 96 | if __name__ == "__main__": |
| 97 | main() |