summaryrefslogtreecommitdiff
path: root/mesonbuild/compilers/rust.py
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2025-11-13 11:38:08 -0800
committerDylan Baker <dylan@pnwbakers.com>2025-11-19 10:48:48 -0800
commit64535bbc821c0276ffe8c894502067a14229e10b (patch)
tree5c6c7902158ff3dc9d8dbb889275faa867297615 /mesonbuild/compilers/rust.py
parent299136511e224676b29a2406349b32d86d4f2dd9 (diff)
downloadmeson-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.
Diffstat (limited to 'mesonbuild/compilers/rust.py')
-rw-r--r--mesonbuild/compilers/rust.py17
1 files changed, 8 insertions, 9 deletions
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