Skip to content

Commit

Permalink
rust: Rebuild targets when compiler got updated
Browse files Browse the repository at this point in the history
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: mesonbuild#10706
  • Loading branch information
xclaesse committed Nov 22, 2023
1 parent b2943de commit 73257b0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mesonbuild/backend/ninjabackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] = []
Expand Down
13 changes: 13 additions & 0 deletions mesonbuild/compilers/rust.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 73257b0

Please sign in to comment.