]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
rust: move strict lints handling to meson.build
authorPaolo Bonzini <pbonzini@redhat.com>
Thu, 13 Nov 2025 09:42:44 +0000 (10:42 +0100)
committerPaolo Bonzini <pbonzini@redhat.com>
Sat, 27 Dec 2025 09:11:09 +0000 (10:11 +0100)
Simplify rustc_args.py, and align its code with what Meson's own Cargo.toml
translator does in v1.10.

Bump unknown_lints to "forbid", so that it will certainly override Cargo.toml's
"allow" level.

Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
meson.build
scripts/rust/rustc_args.py

index 270181038bf1057d0be15578280200e1cf6f78f4..e6a11cefdb75c921e67467c1c2a89e5d9342ddc4 100644 (file)
@@ -128,14 +128,13 @@ if have_rust
   rustc_args = [find_program('scripts/rust/rustc_args.py'),
     '--rustc-version', rustc.version(),
     '--workspace', meson.project_source_root() / 'rust']
-  if get_option('strict_rust_lints')
-    rustc_args += ['--strict-lints']
-  endif
-
   rustfmt = find_program('rustfmt', required: false)
 
   rustc_lint_args = run_command(rustc_args, '--lints',
      capture: true, check: true).stdout().strip().splitlines()
+  if get_option('strict_rust_lints')
+    rustc_lint_args += ['-Dwarnings', '-Funknown_lints']
+  endif
 
   # Apart from procedural macros, our Rust executables will often link
   # with C code, so include all the libraries that C code needs.  This
index 63b0748e0d37892e47d51c67a24b58efd26a58a8..8098053720a6f4b13c935a76d77270537f3d9d47 100644 (file)
@@ -35,8 +35,6 @@ try:
 except ImportError:
     import tomli as tomllib
 
-STRICT_LINTS = {"unknown_lints", "warnings"}
-
 
 class CargoTOML:
     tomldata: Mapping[Any, Any]
@@ -82,7 +80,7 @@ class LintFlag:
     priority: int
 
 
-def generate_lint_flags(cargo_toml: CargoTOML, strict_lints: bool) -> Iterable[str]:
+def generate_lint_flags(cargo_toml: CargoTOML) -> Iterable[str]:
     """Converts Cargo.toml lints to rustc -A/-D/-F/-W flags."""
 
     toml_lints = cargo_toml.lints
@@ -103,13 +101,7 @@ def generate_lint_flags(cargo_toml: CargoTOML, strict_lints: bool) -> Iterable[s
                 flag = "-F"
             else:
                 raise Exception(f"invalid level {level} for {prefix}{lint}")
-
-            if not (strict_lints and lint in STRICT_LINTS):
-                lint_list.append(LintFlag(flags=[flag, prefix + lint], priority=priority))
-
-    if strict_lints:
-        for lint in STRICT_LINTS:
-            lint_list.append(LintFlag(flags=["-D", lint], priority=1000000))
+            lint_list.append(LintFlag(flags=[flag, prefix + lint], priority=priority))
 
     lint_list.sort(key=lambda x: x.priority)
     for lint in lint_list:
@@ -187,13 +179,6 @@ def main() -> None:
         required=False,
         default="1.0.0",
     )
-    parser.add_argument(
-        "--strict-lints",
-        action="store_true",
-        dest="strict_lints",
-        help="apply stricter checks (for nightly Rust)",
-        default=False,
-    )
     args = parser.parse_args()
     if args.verbose:
         logging.basicConfig(level=logging.DEBUG)
@@ -207,7 +192,7 @@ def main() -> None:
         cargo_toml = CargoTOML(args.cargo_toml, None)
 
     if args.lints:
-        for tok in generate_lint_flags(cargo_toml, args.strict_lints):
+        for tok in generate_lint_flags(cargo_toml):
             print(tok)
 
     if rustc_version >= (1, 80):