From 64535bbc821c0276ffe8c894502067a14229e10b Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Thu, 13 Nov 2025 11:38:08 -0800 Subject: compilers/rust: make use the fact we have an Environment to cleanup This adds a second stage initialization, which allows us to use options for setting attributes on the compiler. This is called during the detect phase, so the Compiler is never used in a partially initialized state. --- mesonbuild/compilers/rust.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'mesonbuild/compilers/rust.py') diff --git a/mesonbuild/compilers/rust.py b/mesonbuild/compilers/rust.py index bae072375..6d456357b 100644 --- a/mesonbuild/compilers/rust.py +++ b/mesonbuild/compilers/rust.py @@ -87,6 +87,8 @@ class RustCompiler(Compiler): 'everything': ['-W', 'warnings'], } + allow_nightly: bool + # libcore can be compiled with either static or dynamic CRT, so disable # both of them just in case. MSVCRT_ARGS: T.Mapping[str, T.List[str]] = { @@ -109,9 +111,14 @@ class RustCompiler(Compiler): self.native_static_libs: T.List[str] = [] self.is_beta = '-beta' in full_version self.is_nightly = '-nightly' in full_version - self.allow_nightly = False # Will be set in sanity_check() self.has_check_cfg = version_compare(version, '>=1.80.0') + def init_from_options(self) -> None: + nightly_opt = self.get_compileropt_value('nightly', None) + if nightly_opt == 'enabled' and not self.is_nightly: + raise EnvironmentException(f'Rust compiler {self.name_string()} is not a nightly compiler as required by the "nightly" option.') + self.allow_nightly = nightly_opt != 'disabled' and self.is_nightly + def needs_static_linker(self) -> bool: return False @@ -150,14 +157,6 @@ class RustCompiler(Compiler): raise EnvironmentException(f'Rust compiler {self.name_string()} cannot compile programs.') self._native_static_libs(work_dir, source_name) self.run_sanity_check([output_name], work_dir) - # Check if we are allowed to use nightly features. - # This is done here because it's the only place we have access to - # environment object, and sanity_check() is called after the compiler - # options have been initialized. - nightly_opt = self.get_compileropt_value('nightly', None) - if nightly_opt == 'enabled' and not self.is_nightly: - raise EnvironmentException(f'Rust compiler {self.name_string()} is not a nightly compiler as required by the "nightly" option.') - self.allow_nightly = nightly_opt != 'disabled' and self.is_nightly def _native_static_libs(self, work_dir: str, source_name: str) -> None: # Get libraries needed to link with a Rust staticlib -- cgit v1.2.3