From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: manos.pitsidianakis@linaro.org, kwolf@redhat.com,
junjie.mao@hotmail.com, zhao1.liu@intel.com,
qemu-rust@nondevel.org
Subject: [RFC PATCH 06/11] rust: build: move strict lints handling to rustc_args.py
Date: Fri, 8 Nov 2024 19:01:34 +0100 [thread overview]
Message-ID: <20241108180139.117112-7-pbonzini@redhat.com> (raw)
In-Reply-To: <20241108180139.117112-1-pbonzini@redhat.com>
Make Cargo use unknown_lints = "allow" as well. This is more future
proof as we might add new lints to rust/Cargo.toml that are not supported
by older versions of rustc or clippy.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
meson.build | 12 ++++--------
rust/Cargo.toml | 6 ++++++
scripts/rust/rustc_args.py | 19 ++++++++++++++++---
3 files changed, 26 insertions(+), 11 deletions(-)
diff --git a/meson.build b/meson.build
index 5726135b324..1239f5c48c1 100644
--- a/meson.build
+++ b/meson.build
@@ -122,20 +122,16 @@ endif
if have_rust
rustc_args = [find_program('scripts/rust/rustc_args.py'),
'--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', files('rust/Cargo.toml'),
capture: true, check: true).stdout().strip().splitlines()
- # Occasionally, we may need to silence warnings and clippy lints that
- # were only introduced in newer Rust compiler versions. Do not croak
- # in that case; a CI job with rust_strict_lints == true ensures that
- # we do not have misspelled allow() attributes.
- if not get_option('strict_rust_lints')
- rustc_lint_args += ['-A', 'unknown_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
# is safe; https://github.com/rust-lang/rust/pull/54675 says that
diff --git a/rust/Cargo.toml b/rust/Cargo.toml
index 0230b92a9fa..1ff8f5c2781 100644
--- a/rust/Cargo.toml
+++ b/rust/Cargo.toml
@@ -11,5 +11,11 @@ unexpected_cfgs = { level = "warn", check-cfg = [
'cfg(MESON)', 'cfg(HAVE_GLIB_WITH_ALIGNED_ALLOC)',
'cfg(has_offset_of)'] }
+# Occasionally, we may need to silence warnings and clippy lints that
+# were only introduced in newer Rust compiler versions. Do not croak
+# in that case; a CI job with rust_strict_lints == true disables this
+# and ensures that we do not have misspelled allow() attributes.
+unknown_lints = "allow"
+
# Prohibit code that is forbidden in Rust 2024
unsafe_op_in_unsafe_fn = "deny"
diff --git a/scripts/rust/rustc_args.py b/scripts/rust/rustc_args.py
index 26733439ed4..1f8b05b8001 100644
--- a/scripts/rust/rustc_args.py
+++ b/scripts/rust/rustc_args.py
@@ -35,6 +35,8 @@
except ImportError:
import tomli as tomllib
+STRICT_LINTS = {"unknown_lints", "warnings"}
+
class CargoTOML:
tomldata: Mapping[Any, Any]
@@ -77,7 +79,7 @@ class LintFlag:
priority: int
-def generate_lint_flags(cargo_toml: CargoTOML) -> Iterable[str]:
+def generate_lint_flags(cargo_toml: CargoTOML, strict_lints: bool) -> Iterable[str]:
"""Converts Cargo.toml lints to rustc -A/-D/-F/-W flags."""
toml_lints = cargo_toml.lints
@@ -102,9 +104,13 @@ def generate_lint_flags(cargo_toml: CargoTOML) -> Iterable[str]:
# This may change if QEMU ever invokes clippy-driver or rustdoc by
# hand. For now, check the syntax but do not add non-rustc lints to
# the command line.
- if k == "rust":
+ if k == "rust" and 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.sort(key=lambda x: x.priority)
for lint in lint_list:
yield from lint.flags
@@ -181,6 +187,13 @@ 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)
@@ -194,7 +207,7 @@ def main() -> None:
cargo_toml = CargoTOML(args.cargo_toml, None)
if args.lints:
- for tok in generate_lint_flags(cargo_toml):
+ for tok in generate_lint_flags(cargo_toml, args.strict_lints):
print(tok)
if rustc_version >= (1, 80):
--
2.47.0
next prev parent reply other threads:[~2024-11-08 18:03 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-08 18:01 [RFC PATCH 00/11] rust: improved integration with cargo Paolo Bonzini
2024-11-08 18:01 ` [RFC PATCH 01/11] rust: qemu_api: do not disable lints outside bindgen-generated code Paolo Bonzini
2024-11-12 2:25 ` Junjie Mao
2024-11-12 5:33 ` Paolo Bonzini
2024-11-12 10:10 ` Junjie Mao
2024-11-12 18:47 ` Paolo Bonzini
2024-11-13 6:46 ` Junjie Mao
2024-11-13 10:41 ` Paolo Bonzini
2024-11-08 18:01 ` [RFC PATCH 02/11] rust: build: move rustc_args.py invocation to individual crates Paolo Bonzini
2024-11-12 3:02 ` Junjie Mao
2024-11-08 18:01 ` [RFC PATCH 03/11] rust: build: restrict --cfg generation to only required symbols Paolo Bonzini
2024-11-08 18:01 ` [RFC PATCH 04/11] rust: build: generate warning flags from Cargo.toml Paolo Bonzini
2024-11-08 18:01 ` [RFC PATCH 05/11] rust: cargo: store desired warning levels in workspace Cargo.toml Paolo Bonzini
2024-11-12 3:12 ` Junjie Mao
2024-11-12 5:28 ` Paolo Bonzini
2024-11-12 5:40 ` Junjie Mao
2024-11-08 18:01 ` Paolo Bonzini [this message]
2024-11-08 18:01 ` [RFC PATCH 07/11] rust: fix a couple style issues from clippy Paolo Bonzini
2024-11-13 6:59 ` Junjie Mao
2024-11-08 18:01 ` [RFC PATCH 08/11] rust: build: establish a baseline of lints across all crates Paolo Bonzini
2024-11-13 7:14 ` Junjie Mao
2024-11-13 10:02 ` Paolo Bonzini
2024-11-13 10:13 ` Junjie Mao
2024-11-08 18:01 ` [RFC PATCH 09/11] rust: build: add "make clippy", "make rustfmt" Paolo Bonzini
2024-11-13 7:20 ` Junjie Mao
2024-11-08 18:01 ` [RFC PATCH 10/11] rust: fix doc test syntax Paolo Bonzini
2024-11-13 7:22 ` Junjie Mao
2024-11-08 18:01 ` [RFC PATCH 11/11] rust: ci: add job that runs Rust tools Paolo Bonzini
2024-11-08 18:12 ` Daniel P. Berrangé
2024-11-14 13:07 ` [RFC PATCH 00/11] rust: improved integration with cargo Alex Bennée
2024-11-14 13:11 ` Paolo Bonzini
2024-11-14 15:22 ` Alex Bennée
2024-11-14 15:38 ` Paolo Bonzini
2024-11-14 17:27 ` Alex Bennée
2024-11-14 18:18 ` Paolo Bonzini
2024-11-14 21:13 ` Alex Bennée
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241108180139.117112-7-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=junjie.mao@hotmail.com \
--cc=kwolf@redhat.com \
--cc=manos.pitsidianakis@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-rust@nondevel.org \
--cc=zhao1.liu@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).