From 73257b0778de67890d9c619be138ab2f8e6c3ec5 Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Wed, 22 Nov 2023 08:12:05 -0500 Subject: [PATCH] rust: Rebuild targets when compiler got updated rustc updates are usually incompatible and requires recompiling of all targets. This adds the compiler exe as dependency of every rust ninja targets. Also try to resolve the real rustc exe being used when the toolchain is wrapped by rustup. Fixes: #10706 --- mesonbuild/backend/ninjabackend.py | 2 +- mesonbuild/compilers/rust.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 049ae253fe34..92b88f121bf9 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -1877,7 +1877,7 @@ def generate_rust_target(self, target: build.BuildTarget) -> None: self.generate_generator_list_rules(target) # dependencies need to cause a relink, they're not just for ordering - deps: T.List[str] = [] + deps: T.List[str] = [rustc.get_exe_file()] # Dependencies for rust-project.json project_deps: T.List[RustDep] = [] diff --git a/mesonbuild/compilers/rust.py b/mesonbuild/compilers/rust.py index f8d5e2939bba..faa340814fb1 100644 --- a/mesonbuild/compilers/rust.py +++ b/mesonbuild/compilers/rust.py @@ -81,6 +81,19 @@ def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoic if 'link' in self.linker.id: self.base_options.add(OptionKey('b_vscrt')) self.native_static_libs: T.List[str] = [] + # Resolve the real rustc executable. When using rustup, "rustc" in PATH + # is a wrapper that won't change when updating the toolchain, which + # means ninja would not rebuild rust targets after "rustup update". That + # can cause build issues because different rustc versions are generally + # uncompatible. This also means that once a Meson project has been + # configured, changing the default toolchain with e.g. + # "rustup default nightly" won't have any effect. + sysroot = self.get_sysroot() + real_rustc = os.path.join(sysroot, 'bin', 'rustc') + if os.path.exists(real_rustc): + exelist = [real_rustc] + exelist[1:] + self.exelist = exelist + self.exelist_no_ccache = exelist def needs_static_linker(self) -> bool: return False