summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Claessens <xclaessens@netflix.com>2025-10-20 14:29:52 -0400
committerXavier Claessens <xclaesse@gmail.com>2025-10-23 17:42:00 +0100
commitaf4886d59cffa673305d94e19e40112a126c6e52 (patch)
tree4f5db1689ed1762452987c41e148a3f339f46364
parent81cf25fc0b6615f20b777cca4099b854c4cf2c3b (diff)
downloadmeson-af4886d59cffa673305d94e19e40112a126c6e52.tar.gz
rust: Add rust_nightly feature option
This is used for project to require a nightly Rust compiler, and also for Meson to enable nightly feature if available.
-rw-r--r--docs/markdown/Builtin-options.md1
-rw-r--r--mesonbuild/compilers/rust.py15
2 files changed, 16 insertions, 0 deletions
diff --git a/docs/markdown/Builtin-options.md b/docs/markdown/Builtin-options.md
index 9ab2066fc..da9fc8d44 100644
--- a/docs/markdown/Builtin-options.md
+++ b/docs/markdown/Builtin-options.md
@@ -305,6 +305,7 @@ or compiler being used:
| cpp_winlibs | see below | free-form comma-separated list | Standard Windows libs to link against |
| fortran_std | none | [none, legacy, f95, f2003, f2008, f2018] | Fortran language standard to use |
| rust_dynamic_std | false | true, false | Whether to link dynamically to the Rust standard library *(Added in 1.9.0)* |
+| rust_nightly | auto | enabled, disabled, auto | Nightly Rust compiler (enabled=required, disabled=don't use nightly feature, auto=use nightly feature if available) *(Added in 1.10.0)* |
| cuda_ccbindir | | filesystem path | CUDA non-default toolchain directory to use (-ccbin) *(Added in 0.57.1)* |
The default values of `c_winlibs` and `cpp_winlibs` are in
diff --git a/mesonbuild/compilers/rust.py b/mesonbuild/compilers/rust.py
index c0acf92ad..39280d584 100644
--- a/mesonbuild/compilers/rust.py
+++ b/mesonbuild/compilers/rust.py
@@ -104,6 +104,7 @@ 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 needs_static_linker(self) -> bool:
@@ -144,6 +145,14 @@ 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(environment, [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', environment, 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
@@ -288,6 +297,12 @@ class RustCompiler(Compiler):
'Whether to link Rust build targets to a dynamic libstd',
False)
+ key = self.form_compileropt_key('nightly')
+ opts[key] = options.UserFeatureOption(
+ self.make_option_name(key),
+ "Nightly Rust compiler (enabled=required, disabled=don't use nightly feature, auto=use nightly feature if available)",
+ 'auto')
+
return opts
def get_dependency_compile_args(self, dep: 'Dependency') -> T.List[str]: