From nobody Wed Apr 16 15:37:38 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1733934533; cv=none; d=zohomail.com; s=zohoarc; b=K0UR0mNOJ0gWHsSbLocm7sIRo9hawBAWPt96ijqErkpfghxXnCn/onWbYEWlgRcYUQSFLC01ecay75d7GNDA0FEmrnBmBpoEZ1GHHJKmfK4a8wTgcpUGfxlRQplQepu6vDuQA8nowuC/GLi6oWE9IfpPbTHpqccc/u6UweDPfR8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1733934533; h=Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To:Cc; bh=yd9TqaYM4lKJdZBLeFrSdM5kPuWm4QjUX5Xc6xf+7Y8=; b=i0QaYEzrzNYRfn2X8y6U7VBXkehcqZo4oWhSU+bPU7FTS+hKkdhkGhxfoDwtJ1WYe6AkIrLnIZG0ammD6kucdIX2bGi09bloCNYDc6KDIGkG3LZeS9f7XEm1cFTDb1NlWtom2JsxIcfpE0de0VBNTbd4P1AwHVdc0jMuMCrfydI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1733934533358332.39868046473464; Wed, 11 Dec 2024 08:28:53 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLPZG-000344-PU; Wed, 11 Dec 2024 11:28:07 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPZ7-00023s-JW for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:27:57 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLPZ5-0000Ik-MA for qemu-devel@nongnu.org; Wed, 11 Dec 2024 11:27:57 -0500 Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-424-IhZaCJlLM52sLSQWokl6eA-1; Wed, 11 Dec 2024 11:27:42 -0500 Received: by mail-ed1-f69.google.com with SMTP id 4fb4d7f45d1cf-5d3cdb9d4b1so1164323a12.1 for ; Wed, 11 Dec 2024 08:27:41 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d3eb109bc9sm5930514a12.42.2024.12.11.08.27.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 08:27:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733934471; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yd9TqaYM4lKJdZBLeFrSdM5kPuWm4QjUX5Xc6xf+7Y8=; b=eS7ZyBEF8jYBsKIRWSYhpuM40+PkmJLWBzI/NC1FZD3q69YoU4jl1RPdRvPHWmUvz4zf1f Tlp4HKvgMcZQy0C9g3qLqN85Tn8f9MAoyPW5VFnvhRYE4hxQFcVDvKoJKY+GV7mlqztFZr qoka5/Ay2sL/YKY/JATGmEu37KewlhQ= X-MC-Unique: IhZaCJlLM52sLSQWokl6eA-1 X-Mimecast-MFC-AGG-ID: IhZaCJlLM52sLSQWokl6eA X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733934460; x=1734539260; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yd9TqaYM4lKJdZBLeFrSdM5kPuWm4QjUX5Xc6xf+7Y8=; b=i//sYQmPeEn7Olh2d3f+qQYYaVYbOpyZqOMzF33tW3SnVRHwXfLdbkkYFKy1bQ7nuT Sg8/7fpFiFmYzBVRAH+JSTZjwb+n1x4zasKJo4MdJf3JGof20PExCWZ6XcEhIrT1dvwM yWkYmSAqJ6LbDCAqRgrDzsrrAMewhrc7J6co5hox1pPxzFYypcPe3IfPzMXTFxSVLuFE LXlhfAhNmIlbdGbsJBbnr6JNJ82ZmWYB8sBQLsXd4Hyase/PWnDWcGseCy+KgMDJrSB+ brEjSlxkm3LeuKxPMbgy4BImxT+rGHOLXfyK+nvo9gZJWFaG6bfA/5JPAJ+gm3wPI1Y+ LWPg== X-Gm-Message-State: AOJu0YwG7g1DXMwCUrwxAhRfjALT7AMV31GbVskeYO2aWEYs23jpWhTn YoFXhrBJt+PVTqFVcWmf+4rYMKYE82wqBZtfB9X57I5Kl3W1KJ9BuTxfOsF6DUo2KHpFK8be5LP gnxI9LMzvyCMLFgwoWHo6pietd+9LfvBkryCyULrvfs951P5ZgWSOlHeeU13wIi2Wykh5QPJ3fo QfEOOMK/IkVV2jZBaa2ZUUliey8nhq9nFJb4q/ X-Gm-Gg: ASbGncvrSkWeUl/L8ofCufLaUDw++rueuEVlTgyL5kTbw66KY/vZRDgC5pIN0UDaqx5 4aLIzwqZUOwsbY13X3TzNB5DoyAWWCqEG3QcMmWrjSRj65vpzeHzVU+WOJsFwJA2u49/8xrJz6J O0z8lRP0VQYshpGvvSGZn4Jnsvxinyr/uuwpei5bUMyUkqRDQZD56xyU4jVU01hCeHQ78fABgwe Cwniu2bGyAkZLP8ZXxHhyx4vGxkJA+ag67cWhfElWbVRhOpTGtGqrmS X-Received: by 2002:a05:6402:5215:b0:5d0:b1c4:7081 with SMTP id 4fb4d7f45d1cf-5d43317b4eamr3092289a12.4.1733934460027; Wed, 11 Dec 2024 08:27:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IFB3/zvg9TsUI5Su1pYoD7XrW/AD9beYNGnmv0FbFRt5CdREs7lBQXGhu4S1oCoJcMSbkzTdg== X-Received: by 2002:a05:6402:5215:b0:5d0:b1c4:7081 with SMTP id 4fb4d7f45d1cf-5d43317b4eamr3092247a12.4.1733934459504; Wed, 11 Dec 2024 08:27:39 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 08/49] rust: build: move strict lints handling to rustc_args.py Date: Wed, 11 Dec 2024 17:26:38 +0100 Message-ID: <20241211162720.320070-9-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241211162720.320070-1-pbonzini@redhat.com> References: <20241211162720.320070-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.472, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1733934535263116600 Content-Type: text/plain; charset="utf-8" Make Cargo use unknown_lints =3D "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 --- 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 218ae441e38..85f74854735 100644 --- a/meson.build +++ b/meson.build @@ -123,19 +123,15 @@ if have_rust rustc_args =3D [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 +=3D ['--strict-lints'] + endif + rustfmt =3D find_program('rustfmt', required: false) =20 rustc_lint_args =3D run_command(rustc_args, '--lints', capture: true, check: true).stdout().strip().splitlines() =20 - # 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 =3D=3D true ensures that - # we do not have misspelled allow() attributes. - if not get_option('strict_rust_lints') - rustc_lint_args +=3D ['-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 4bb52bf0bd5..358c517bc56 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -11,5 +11,11 @@ unexpected_cfgs =3D { level =3D "deny", check-cfg =3D [ 'cfg(MESON)', 'cfg(HAVE_GLIB_WITH_ALIGNED_ALLOC)', 'cfg(has_offset_of)'] } =20 +# 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 =3D=3D true disables this +# and ensures that we do not have misspelled allow() attributes. +unknown_lints =3D "allow" + # Prohibit code that is forbidden in Rust 2024 unsafe_op_in_unsafe_fn =3D "deny" diff --git a/scripts/rust/rustc_args.py b/scripts/rust/rustc_args.py index 9df131a02bd..5525b3886fa 100644 --- a/scripts/rust/rustc_args.py +++ b/scripts/rust/rustc_args.py @@ -35,6 +35,8 @@ except ImportError: import tomli as tomllib =20 +STRICT_LINTS =3D {"unknown_lints", "warnings"} + =20 class CargoTOML: tomldata: Mapping[Any, Any] @@ -80,7 +82,7 @@ class LintFlag: priority: int =20 =20 -def generate_lint_flags(cargo_toml: CargoTOML) -> Iterable[str]: +def generate_lint_flags(cargo_toml: CargoTOML, strict_lints: bool) -> Iter= able[str]: """Converts Cargo.toml lints to rustc -A/-D/-F/-W flags.""" =20 toml_lints =3D cargo_toml.lints @@ -105,9 +107,13 @@ def generate_lint_flags(cargo_toml: CargoTOML) -> Iter= able[str]: # This may change if QEMU ever invokes clippy-driver or rustdo= c by # hand. For now, check the syntax but do not add non-rustc li= nts to # the command line. - if k =3D=3D "rust": + if k =3D=3D "rust" and not (strict_lints and lint in STRICT_LI= NTS): lint_list.append(LintFlag(flags=3D[flag, prefix + lint], p= riority=3Dpriority)) =20 + if strict_lints: + for lint in STRICT_LINTS: + lint_list.append(LintFlag(flags=3D["-D", lint], priority=3D100= 0000)) + lint_list.sort(key=3Dlambda x: x.priority) for lint in lint_list: yield from lint.flags @@ -184,6 +190,13 @@ def main() -> None: required=3DFalse, default=3D"1.0.0", ) + parser.add_argument( + "--strict-lints", + action=3D"store_true", + dest=3D"strict_lints", + help=3D"apply stricter checks (for nightly Rust)", + default=3DFalse, + ) args =3D parser.parse_args() if args.verbose: logging.basicConfig(level=3Dlogging.DEBUG) @@ -197,7 +210,7 @@ def main() -> None: cargo_toml =3D CargoTOML(args.cargo_toml, None) =20 if args.lints: - for tok in generate_lint_flags(cargo_toml): + for tok in generate_lint_flags(cargo_toml, args.strict_lints): print(tok) =20 if rustc_version >=3D (1, 80): --=20 2.47.1