From 7b67fa3b88cdbb9bb132d5e81c40a868f30c0a7e Mon Sep 17 00:00:00 2001 From: Shing Lyu Date: Thu, 27 Jul 2017 17:28:17 +0800 Subject: [PATCH] [WIP] Use rustup to manage toolchains --- python/servo/bootstrap_commands.py | 16 +++++++++++++++- python/servo/command_base.py | 24 ++++++++++++++++++++++++ rust-toolchain | 1 + 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 rust-toolchain diff --git a/python/servo/bootstrap_commands.py b/python/servo/bootstrap_commands.py index b12ba0242d7c..152f4cb5f2d1 100644 --- a/python/servo/bootstrap_commands.py +++ b/python/servo/bootstrap_commands.py @@ -27,7 +27,7 @@ ) import servo.bootstrap as bootstrap -from servo.command_base import CommandBase, BIN_SUFFIX, cd +from servo.command_base import CommandBase, BIN_SUFFIX, cd, call from servo.util import delete, download_bytes, download_file, extract, host_triple @@ -67,6 +67,20 @@ def bootstrap(self, force=False): action='store_true', help='Use stable rustc version') def bootstrap_rustc(self, force=False, target=[], stable=False): + if self.has_rustup(): + print("Found rustup, using rustup to manage rust toolchain") + self.bootstrap_rustc_rustup(force=force, target=target, stable=stable) + else: + print("No rustup, downloading rust toolchain") + self.bootstrap_rustc_vendor(force=force, target=target, stable=stable) + + def bootstrap_rustc_rustup(self, force=False, target=[], stable=False): + # TODO: how do we install the stable toolchain with the override file? + with open("rust-toolchain", "rb") as fo: + toolchain_version = fo.read().rstrip() + call(["rustup", "install", toolchain_version]) + + def bootstrap_rustc_vendor(self, force=False, target=[], stable=False): self.set_use_stable_rust(stable) version = self.rust_version() rust_path = self.rust_path() diff --git a/python/servo/command_base.py b/python/servo/command_base.py index abaa643fbb3c..8cf5048dbd63 100644 --- a/python/servo/command_base.py +++ b/python/servo/command_base.py @@ -420,6 +420,8 @@ def package_dir(package): # Always build harfbuzz from source env["HARFBUZZ_SYS_NO_PKG_CONFIG"] = "true" + if self.has_rustup(): + self.config["tools"]["rust-root"] = subprocess.check_output(["rustup", "which", "rustc"]).rstrip("rustc") if not self.config["tools"]["system-rust"] \ or self.config["tools"]["rust-root"]: env["RUST_ROOT"] = self.config["tools"]["rust-root"] @@ -430,6 +432,8 @@ def package_dir(package): extra_path += [path.join(self.config["tools"]["rust-root"], "bin")] extra_lib += [path.join(self.config["tools"]["rust-root"], "lib")] + if self.has_rustup(): + self.config["tools"]["cargo-root"] = subprocess.check_output(["rustup", "which", "cargo"]).rstrip("cargo") if not self.config["tools"]["system-cargo"] \ or self.config["tools"]["cargo-root"]: # This path is for when rust-root points to an unpacked installer @@ -442,6 +446,7 @@ def package_dir(package): if extra_path: env["PATH"] = "%s%s%s" % (os.pathsep.join(extra_path), os.pathsep, env["PATH"]) + # TODO: set this with rustup env["CARGO_HOME"] = self.config["tools"]["cargo-home-dir"] if self.config["build"]["incremental"]: env["CARGO_INCREMENTAL"] = "1" @@ -565,7 +570,26 @@ def handle_android_target(self, target): return True return False + def has_rustup(self): + # TODO: Cache the result and don't call subprocess everytime + try: + check_call(["rustup", "--version"]) + self.config['tools']['rustup'] = True + return True + + except OSError, subprocess.CalledProcessError: + return False + def ensure_bootstrapped(self, target=None): + if self.has_rustup(): + try: + self.config["tools"]["rust-root"] = subprocess.check_output(["rustup", "which", "rustc"]).rstrip("rustc") + except subprocess.CalledProcessError: + Registrar.dispatch("bootstrap-rust", context=self.context, target=filter(None, [target]), + stable=self._use_stable_rust) + # TODO: should we also bootstrap cargo here? Maybe rustup + # install implies cargo as well? + if self.context.bootstrapped: return diff --git a/rust-toolchain b/rust-toolchain new file mode 100644 index 000000000000..ffca3a6d80f3 --- /dev/null +++ b/rust-toolchain @@ -0,0 +1 @@ +nightly-2017-07-17