diff options
author | Martin Robinson <mrobinson@igalia.com> | 2023-08-01 16:44:57 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-01 14:44:57 +0000 |
commit | fef332f38552ae8af83cf69993dd6aabdebffd6a (patch) | |
tree | 577bca564e78c7b8a2e02e7e9b3431518533edae /python/servo/command_base.py | |
parent | 4061d13ba6d06f775e1a4a0fe50662ea3b16d2fa (diff) | |
download | servo-fef332f38552ae8af83cf69993dd6aabdebffd6a.tar.gz servo-fef332f38552ae8af83cf69993dd6aabdebffd6a.zip |
Make rustup a requirement and switch to `rust-toolchain.toml` (#30056)
This change makes rustup a requirement for building Servo with `./mach`
and switches to the newer `rust-toolchain.toml` format. The goal here is
to make mach builds more similar to non-mach builds.
- The new format allows listing the required components, removing some of
the complexity from our mach scripts.
- This means we must raise the required version of rustup to 1.23. The
current version is 1.26.
- We no longer wrap every call to cargo and rustc in "rustup run" calls
as both cargo and rustc will take care of installing and using all
necessary components specified in `rust-toolchain.toml` when run
inside the project directory.
Diffstat (limited to 'python/servo/command_base.py')
-rw-r--r-- | python/servo/command_base.py | 62 |
1 files changed, 13 insertions, 49 deletions
diff --git a/python/servo/command_base.py b/python/servo/command_base.py index 63911e01c4a..ce8c1ddb237 100644 --- a/python/servo/command_base.py +++ b/python/servo/command_base.py @@ -244,7 +244,6 @@ class CommandBase(object): context.sharedir = self.config["tools"]["cache-dir"] - self.config["tools"].setdefault("use-rustup", True) self.config["tools"].setdefault("rustc-with-gold", get_env_bool("SERVO_RUSTC_WITH_GOLD", True)) self.config.setdefault("build", {}) @@ -272,24 +271,13 @@ class CommandBase(object): _rust_toolchain = None def rust_toolchain(self): - if self._rust_toolchain is None: - filename = path.join(self.context.topdir, "rust-toolchain") - with open(filename) as f: - self._rust_toolchain = f.read().strip() - - if platform.system() == "Windows": - self._rust_toolchain += "-x86_64-pc-windows-msvc" + if self._rust_toolchain: + return self._rust_toolchain + toolchain_file = path.join(self.context.topdir, "rust-toolchain.toml") + self._rust_toolchain = toml.load(toolchain_file)['toolchain']['channel'] return self._rust_toolchain - def call_rustup_run(self, args, **kwargs): - if self.config["tools"]["use-rustup"]: - assert self.context.bootstrapped - args = ["rustup" + BIN_SUFFIX, "run", "--install", self.rust_toolchain()] + args - else: - args[0] += BIN_SUFFIX - return call(args, **kwargs) - def get_top_dir(self): return self.context.topdir @@ -933,7 +921,7 @@ class CommandBase(object): if with_debug_assertions or self.config["build"]["debug-assertions"]: env['RUSTFLAGS'] = env.get('RUSTFLAGS', "") + " -C debug_assertions" - return self.call_rustup_run(["cargo", command] + args + cargo_args, env=env, verbose=verbose) + return call(["cargo", command] + args + cargo_args, env=env, verbose=verbose) def android_support_dir(self): return path.join(self.context.topdir, "support", "android") @@ -986,43 +974,19 @@ class CommandBase(object): return True return False - def ensure_bootstrapped(self, rustup_components=None): + def ensure_bootstrapped(self): if self.context.bootstrapped: return servo.platform.get().passive_bootstrap() - if self.config["tools"]["use-rustup"]: - self.ensure_rustup_version() - toolchain = self.rust_toolchain() - - status = subprocess.call( - ["rustup", "run", toolchain, "rustc", "--version"], - stdout=open(os.devnull, "wb"), - stderr=subprocess.STDOUT, + needs_toolchain_install = self.cross_compile_target \ + and self.cross_compile_target not in check_output( + ["rustup", "target", "list", "--installed"], cwd=self.context.topdir ) - if status: - check_call(["rustup", "toolchain", "install", "--profile", "minimal", toolchain]) - - installed = check_output( - ["rustup", "component", "list", "--installed", "--toolchain", toolchain] - ) - required_components = { - # For components/script_plugins, https://github.com/rust-lang/rust/pull/67469 - "rustc-dev", - # https://github.com/rust-lang/rust/issues/72594#issuecomment-633779564 - "llvm-tools-preview", - } - for component in set(rustup_components or []) | required_components: - if component.encode("utf-8") not in installed: - check_call(["rustup", "component", "add", "--toolchain", toolchain, component]) - - needs_toolchain_install = self.cross_compile_target \ - and self.cross_compile_target.encode("utf-8") not in check_output( - ["rustup", "target", "list", "--installed", "--toolchain", toolchain] - ) - if needs_toolchain_install: - check_call(["rustup", "target", "add", "--toolchain", toolchain, self.cross_compile_target]) + if needs_toolchain_install: + check_call(["rustup", "target", "add", self.cross_compile_target], + cwd=self.context.topdir) self.context.bootstrapped = True @@ -1042,7 +1006,7 @@ class CommandBase(object): sys.exit(1) raise version = tuple(map(int, re.match(br"rustup (\d+)\.(\d+)\.(\d+)", version_line).groups())) - version_needed = (1, 21, 0) + version_needed = (1, 23, 0) if version < version_needed: print("rustup is at version %s.%s.%s, Servo requires %s.%s.%s or more recent." % (version + version_needed)) print("Try running 'rustup self update'.") |