From nobody Sat Nov 23 19:53:36 2024 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=1731688927; cv=none; d=zohomail.com; s=zohoarc; b=furTJgxPhgZmLXgxEc/30faCG5Rvlpa3kKljTz2b0VbWCbmgNVevA5Sig50+g3yOE+JiRfXcg2nOq93N/v8p5P4c/oF3lbk+whaQOwOMqytjWzN9n5Q3KuT3ufAlCQOy4Nh2SRDtwym8l9SwN7ykZOpDiNo9uFHsEXHIEctQ6I4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1731688927; h=Content-Transfer-Encoding:Cc:Cc: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; bh=lbZfDGVI8qqVsTKqZdaFZ6xvk03TszV2nYSfM9yNsD8=; b=agQSJho6PrBJNDdKZ7izMt6K63+XQsid0MoCHzwRpt5vm3TcmznGamLKJwedZ5yKtJSWA6e0ULzHP/8TwKsk6N94tc5y9NKEG+W5vvee4zwy4oUianMnjOBe5ZmC23p5itdWcKbu2TCvsxmnc9rmjLefmYYsDPLJah5/G+E7T3A= 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 1731688927966751.4245343423974; Fri, 15 Nov 2024 08:42:07 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tBzOB-0006tA-Jo; Fri, 15 Nov 2024 11:41:45 -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 1tBzNV-0006Kk-RL for qemu-devel@nongnu.org; Fri, 15 Nov 2024 11:41:06 -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 1tBzNS-0002LQ-RP for qemu-devel@nongnu.org; Fri, 15 Nov 2024 11:41:00 -0500 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-246-otmxhjtqPTKXdRFs8CmPRQ-1; Fri, 15 Nov 2024 11:40:55 -0500 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-43163a40ee0so13295095e9.0 for ; Fri, 15 Nov 2024 08:40:55 -0800 (PST) Received: from [192.168.10.3] ([151.49.84.243]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-432da29ffe9sm63379635e9.44.2024.11.15.08.40.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 08:40:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1731688856; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lbZfDGVI8qqVsTKqZdaFZ6xvk03TszV2nYSfM9yNsD8=; b=ViKvGUQTsDW7VN7OSjVo/8XUB+q9Sf4HwJxA7127/xmPV+fT6emnZj7raLBKzreHwoctH6 1LAyG75m0V5RFhYe6WIP4ZfSJT3PJnbypZCwR0mYc6z9r1bfp6Xh7HF10uy0Jc2vZUTrpI zZIRg7K3+4vuKiG8VLfv3S2f3jEcLT8= X-MC-Unique: otmxhjtqPTKXdRFs8CmPRQ-1 X-Mimecast-MFC-AGG-ID: otmxhjtqPTKXdRFs8CmPRQ X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731688852; x=1732293652; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lbZfDGVI8qqVsTKqZdaFZ6xvk03TszV2nYSfM9yNsD8=; b=GAPDz7Mqi2s/CBR8lAGhpUrcrBZjlKzb1IcIyMsoTtqib6MTOP3Ua91N79vjLM52cy gOeaja/w1byqFUsFK3QuxOh1+yt//t2L2GQWtlrEgzlweV+LqptXS7G5E96P0E3TUo5r OSz0cfUK9DZ8ay7acieF0XNus5bbX+5+rICmzCippWEqxFQue7u2/5CaPQlhqPk9COtZ TfttJaHhTlVf0gBOrkI3/njVFK5AxXEkWKzKRh3JqCTnmW76PkRJ/A6iLDqJGwF7MS6L DMRdkXZIhE3IUghYE3C6NQtaKWNfJ8oeAbV+9OrTAYeLnmAlvZKPff+JI6IKeEiMbX+E Nvsw== X-Gm-Message-State: AOJu0Yxk9HDULAOMxz1umntGiedwjWcGdoUzooAj7YN4nLfpyNA6eR/g vEH1CZBhf3GNvGSfAna45zhmwGTcv46aDOqn9llS5s9Ikt7AYtADutVqU244rdkB5UbK9RAUCW9 LS737tRCCOt2Mfg3fP7KAsxYO1Dq0bKW3NZSfdlQHxRb2OZmxVzJgJdmlD+xvMHFrn5pqjuUPeh I82M3Up3FyABmRx/LFGpZaBfLi7IEgluCCErAmagU= X-Received: by 2002:a05:600c:cc4:b0:431:40ca:ce6e with SMTP id 5b1f17b1804b1-432df791da4mr29207125e9.31.1731688852289; Fri, 15 Nov 2024 08:40:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IEPE235lKKtHkSitgD1Vq1+M6hakvsORC3AamjxpSikVwAiPuc+b+sSHNLkap53hOKc5FZPrQ== X-Received: by 2002:a05:600c:cc4:b0:431:40ca:ce6e with SMTP id 5b1f17b1804b1-432df791da4mr29206865e9.31.1731688851849; Fri, 15 Nov 2024 08:40:51 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: qemu-rust@nongnu.org, berrange@redhat.com, junjie.mao@hotmail.com, manos.pitsidianakis@linaro.org, kwolf@redhat.com Subject: [PATCH 06/12] rust: cargo: store desired warning levels in workspace Cargo.toml Date: Fri, 15 Nov 2024 17:40:19 +0100 Message-ID: <20241115164025.1917618-6-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241115163944.1917393-1-pbonzini@redhat.com> References: <20241115163944.1917393-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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.12, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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: 1731688929507116600 Content-Type: text/plain; charset="utf-8" An extra benefit of workspaces is that they allow to place lint level settings in a single Cargo.toml; the settings are then inherited by packages in the workspace. Correspondingly, teach rustc_args.py to get the unexpected_cfgs configuration from the workspace Cargo.toml. Note that it is still possible to allow or deny warnings per crate or module, via the #![] attribute syntax. The rust/qemu-api/src/bindings.rs file is an example. Signed-off-by: Paolo Bonzini --- meson.build | 7 +++--- rust/Cargo.toml | 8 +++++++ rust/hw/char/pl011/Cargo.toml | 3 +++ rust/qemu-api-macros/Cargo.toml | 3 +++ rust/qemu-api/Cargo.toml | 5 ++--- rust/qemu-api/meson.build | 2 +- scripts/rust/rustc_args.py | 38 +++++++++++++++++++++++++++------ 7 files changed, 53 insertions(+), 13 deletions(-) diff --git a/meson.build b/meson.build index 231fccf3928..21e2a332d6c 100644 --- a/meson.build +++ b/meson.build @@ -121,11 +121,12 @@ endif =20 if have_rust rustc_args =3D [find_program('scripts/rust/rustc_args.py'), - '--rustc-version', rustc.version()] + '--rustc-version', rustc.version(), + '--workspace', meson.project_source_root() / 'rust'] rustfmt =3D find_program('rustfmt', required: false) =20 - # Prohibit code that is forbidden in Rust 2024 - rustc_lint_args =3D ['-D', 'unsafe_op_in_unsafe_fn'] + 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 diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 0c94d5037da..4bb52bf0bd5 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -5,3 +5,11 @@ members =3D [ "qemu-api", "hw/char/pl011", ] + +[workspace.lints.rust] +unexpected_cfgs =3D { level =3D "deny", check-cfg =3D [ + 'cfg(MESON)', 'cfg(HAVE_GLIB_WITH_ALIGNED_ALLOC)', + 'cfg(has_offset_of)'] } + +# Prohibit code that is forbidden in Rust 2024 +unsafe_op_in_unsafe_fn =3D "deny" diff --git a/rust/hw/char/pl011/Cargo.toml b/rust/hw/char/pl011/Cargo.toml index a373906b9fb..58f3e859f7e 100644 --- a/rust/hw/char/pl011/Cargo.toml +++ b/rust/hw/char/pl011/Cargo.toml @@ -21,3 +21,6 @@ bilge =3D { version =3D "0.2.0" } bilge-impl =3D { version =3D "0.2.0" } qemu_api =3D { path =3D "../../../qemu-api" } qemu_api_macros =3D { path =3D "../../../qemu-api-macros" } + +[lints] +workspace =3D true diff --git a/rust/qemu-api-macros/Cargo.toml b/rust/qemu-api-macros/Cargo.t= oml index a8f7377106b..5a27b52ee6e 100644 --- a/rust/qemu-api-macros/Cargo.toml +++ b/rust/qemu-api-macros/Cargo.toml @@ -20,3 +20,6 @@ proc-macro =3D true proc-macro2 =3D "1" quote =3D "1" syn =3D { version =3D "2", features =3D ["extra-traits"] } + +[lints] +workspace =3D true diff --git a/rust/qemu-api/Cargo.toml b/rust/qemu-api/Cargo.toml index cc716d75d46..669f288d1cb 100644 --- a/rust/qemu-api/Cargo.toml +++ b/rust/qemu-api/Cargo.toml @@ -23,6 +23,5 @@ version_check =3D "~0.9" default =3D [] allocator =3D [] =20 -[lints.rust] -unexpected_cfgs =3D { level =3D "warn", check-cfg =3D ['cfg(MESON)', 'cfg(= HAVE_GLIB_WITH_ALIGNED_ALLOC)', - 'cfg(has_offset_of)'] } +[lints] +workspace =3D true diff --git a/rust/qemu-api/meson.build b/rust/qemu-api/meson.build index 1ed79672cc9..d719c13f46d 100644 --- a/rust/qemu-api/meson.build +++ b/rust/qemu-api/meson.build @@ -1,5 +1,5 @@ _qemu_api_cfg =3D run_command(rustc_args, - '--config-headers', config_host_h, '--features', '--lints', files('Cargo= .toml'), + '--config-headers', config_host_h, '--features', files('Cargo.toml'), capture: true, check: true).stdout().strip().splitlines() =20 # _qemu_api_cfg +=3D ['--cfg', 'feature=3D"allocator"'] diff --git a/scripts/rust/rustc_args.py b/scripts/rust/rustc_args.py index 9b9778a1cac..9df131a02bd 100644 --- a/scripts/rust/rustc_args.py +++ b/scripts/rust/rustc_args.py @@ -38,11 +38,21 @@ =20 class CargoTOML: tomldata: Mapping[Any, Any] + workspace_data: Mapping[Any, Any] check_cfg: Set[str] =20 - def __init__(self, path: str): - with open(path, 'rb') as f: - self.tomldata =3D tomllib.load(f) + def __init__(self, path: Optional[str], workspace: Optional[str]): + if path is not None: + with open(path, 'rb') as f: + self.tomldata =3D tomllib.load(f) + else: + self.tomldata =3D {"lints": {"workspace": True}} + + if workspace is not None: + with open(workspace, 'rb') as f: + self.workspace_data =3D tomllib.load(f) + if "workspace" not in self.workspace_data: + self.workspace_data["workspace"] =3D {} =20 self.check_cfg =3D set(self.find_check_cfg()) =20 @@ -54,10 +64,12 @@ def find_check_cfg(self) -> Iterable[str]: =20 @property def lints(self) -> Mapping[Any, Any]: - return self.get_table("lints") + return self.get_table("lints", True) =20 - def get_table(self, key: str) -> Mapping[Any, Any]: + def get_table(self, key: str, can_be_workspace: bool =3D False) -> Map= ping[Any, Any]: table =3D self.tomldata.get(key, {}) + if can_be_workspace and table.get("workspace", False) is True: + table =3D self.workspace_data["workspace"].get(key, {}) =20 return table =20 @@ -136,6 +148,16 @@ def main() -> None: action=3D"store", dest=3D"cargo_toml", help=3D"path to Cargo.toml file", + nargs=3D'?', + ) + parser.add_argument( + "--workspace", + metavar=3D"DIR", + action=3D"store", + dest=3D"workspace", + help=3D"path to root of the workspace", + required=3DFalse, + default=3DNone, ) parser.add_argument( "--features", @@ -168,7 +190,11 @@ def main() -> None: logging.debug("args: %s", args) =20 rustc_version =3D tuple((int(x) for x in args.rustc_version.split('.')= [0:2])) - cargo_toml =3D CargoTOML(args.cargo_toml) + if args.workspace: + workspace_cargo_toml =3D Path(args.workspace, "Cargo.toml").resolv= e() + cargo_toml =3D CargoTOML(args.cargo_toml, str(workspace_cargo_toml= )) + else: + cargo_toml =3D CargoTOML(args.cargo_toml, None) =20 if args.lints: for tok in generate_lint_flags(cargo_toml): --=20 2.47.0