Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rust: Rebuild targets when compiler got updated #12536

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
3 changes: 3 additions & 0 deletions mesonbuild/compilers/compilers.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,9 @@ def get_exelist(self, ccache: bool = True) -> T.List[str]:
def get_linker_exelist(self) -> T.List[str]:
return self.linker.get_exelist() if self.linker else self.get_exelist()

def get_exe_file(self) -> str:
return os.path.realpath(self.exelist_no_ccache[0])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This returns a bad value when only the executable name is passed (so shouldn't shutil.which() be used here?)


@abc.abstractmethod
def get_output_args(self, outputname: str) -> T.List[str]:
pass
Expand Down
16 changes: 16 additions & 0 deletions mesonbuild/compilers/rust.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import re
import typing as T

from functools import lru_cache

from .. import coredata
from ..mesonlib import EnvironmentException, MesonException, Popen_safe_logged, OptionKey
from .compilers import Compiler, rust_buildtype_args, clike_debug_args
Expand Down Expand Up @@ -79,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 Expand Up @@ -126,6 +141,7 @@ def get_dependency_gen_args(self, outtarget: str, outfile: str) -> T.List[str]:
def get_buildtype_args(self, buildtype: str) -> T.List[str]:
return rust_buildtype_args[buildtype]

@lru_cache(maxsize=None)
def get_sysroot(self) -> str:
cmd = self.get_exelist(ccache=False) + ['--print', 'sysroot']
p, stdo, stde = Popen_safe_logged(cmd)
Expand Down
1 change: 1 addition & 0 deletions mesonbuild/interpreter/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1519,6 +1519,7 @@ def add_languages_for(self, args: T.List[str], required: bool, for_machine: Mach
comp = compilers.detect_compiler_for(self.environment, lang, for_machine, skip_sanity_check)
if comp is None:
raise InvalidArguments(f'Tried to use unknown language "{lang}".')
self.add_build_def_file(comp.get_exe_file())
except mesonlib.MesonException:
if not required:
mlog.log('Compiler for language',
Expand Down