diff options
| author | Dylan Baker <dylan@pnwbakers.com> | 2025-11-13 11:38:08 -0800 |
|---|---|---|
| committer | Dylan Baker <dylan@pnwbakers.com> | 2025-11-19 10:48:48 -0800 |
| commit | 64535bbc821c0276ffe8c894502067a14229e10b (patch) | |
| tree | 5c6c7902158ff3dc9d8dbb889275faa867297615 | |
| parent | 299136511e224676b29a2406349b32d86d4f2dd9 (diff) | |
| download | meson-64535bbc821c0276ffe8c894502067a14229e10b.tar.gz | |
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.
| -rw-r--r-- | mesonbuild/compilers/compilers.py | 3 | ||||
| -rw-r--r-- | mesonbuild/compilers/rust.py | 17 | ||||
| -rw-r--r-- | mesonbuild/coredata.py | 2 |
3 files changed, 13 insertions, 9 deletions
diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py index 6b6dade7d..c09f5057a 100644 --- a/mesonbuild/compilers/compilers.py +++ b/mesonbuild/compilers/compilers.py @@ -496,6 +496,9 @@ class Compiler(HoldableObject, metaclass=abc.ABCMeta): # see :class:`Interpreter._redetect_machines()` return self.environment.machines[self.for_machine] + def init_from_options(self) -> None: + """Initializer compiler attributes that require options to be set.""" + def __repr__(self) -> str: repr_str = "<{0}: v{1} `{2}`>" return repr_str.format(self.__class__.__name__, self.version, 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 diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py index 021b3ebdc..f6c43ce70 100644 --- a/mesonbuild/coredata.py +++ b/mesonbuild/coredata.py @@ -448,6 +448,8 @@ class CoreData: if skey not in self.optstore: self.optstore.add_system_option(skey, copy.deepcopy(options.COMPILER_BASE_OPTIONS[key])) + comp.init_from_options() + self.emit_base_options_warnings() def emit_base_options_warnings(self) -> None: |
