From patchwork Fri Nov 8 18:01:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13868828 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CD5ECD64072 for ; Fri, 8 Nov 2024 18:04:56 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t9TJ5-0001uf-VP; Fri, 08 Nov 2024 13:02:03 -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 1t9TIw-0001oF-E6 for qemu-devel@nongnu.org; Fri, 08 Nov 2024 13:01:54 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t9TIu-0001v3-Ih for qemu-devel@nongnu.org; Fri, 08 Nov 2024 13:01:54 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1731088911; 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=yfF+e4p7LcLCc9fG9LqtNbaVzXuoaKz8W1PB4KLYI+g=; b=BqIcAv5L+FxKPEAvYEiILWEh9P5fCpcLjNW/PHQ9AUk/9FNeuNKSwMxSE1PVhb/ycD5maI hksPOnVKyXz8x/ZhPDKb1Lu/LKrWGSl7GT+Nw3FHAlvqpA/qnJ7Xtp5HpZoafumq3VkLeL wLPfeMV7SISuKJhE0iScyozpoqK5VIk= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-367-QKgX2lYNMjCjPJtPeFRVbw-1; Fri, 08 Nov 2024 13:01:47 -0500 X-MC-Unique: QKgX2lYNMjCjPJtPeFRVbw-1 X-Mimecast-MFC-AGG-ID: QKgX2lYNMjCjPJtPeFRVbw Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-43157e3521dso16470465e9.1 for ; Fri, 08 Nov 2024 10:01:47 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731088906; x=1731693706; 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=yfF+e4p7LcLCc9fG9LqtNbaVzXuoaKz8W1PB4KLYI+g=; b=sTBriisjjkwlbwD1E2lzDseDOjGLgJFtFacFUNGtPOmHWP2UoqdMh7G/NVVo9n1kNi qfV/7TYM+TCmow1nlVJfpUfTh7ZsgUVCJ7PEwub5/HXU82vmt/e3ZgJrff3yEkv0CWg0 sSPGLw3ahvXb/YI5vggmHyf0Qw0SMzSBXXK+XANUgCbbqANnjUrwe4mhn/UcHRjlBvF2 UNFJdrgphxcX5B6UfK04kcRqXZrvLxd4H/mET+16seqsp0tSEdo1XqieG0oqTYGDhPjo hkKLnXKBedUxZX5Da337JfWRCB5lD/Lb2QsORhaof4+bcLSWhQ3Y2vvc/+SwHce5KaRu NCWg== X-Gm-Message-State: AOJu0YzZDXLPfeSVE+OImpx5ReDDoUDZc9+//VTwyQsBv6zBi/3lGHcq zhBEWwgg1T+VAWKO0v6tB8Q3YHkL+qWcAAvGPiRaLIdoX5JzSrYb2Wng/+GT6e0BGaG+8VCetNP Y4SzEbHOWfpqTsgIr7g8zmW1dAzhi34wVllyzW0e/unI04Lu1eTlRszyjO17qFDmD5gR8DnrRis nRlSodPAdVDiwdF+cz47IcWbW8CnbkMtd34uAIAGo= X-Received: by 2002:a05:600c:3514:b0:42e:8d0d:bca5 with SMTP id 5b1f17b1804b1-432b74fdb3cmr30403925e9.2.1731088905633; Fri, 08 Nov 2024 10:01:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IFhyluaPVV70eSO6iZo+1ACQh5JSnFU/paTGFP0efep//4xuscJhgzNAkyMzq0Bbn5Afs4T3A== X-Received: by 2002:a05:600c:3514:b0:42e:8d0d:bca5 with SMTP id 5b1f17b1804b1-432b74fdb3cmr30403495e9.2.1731088905123; Fri, 08 Nov 2024 10:01:45 -0800 (PST) Received: from [192.168.10.47] ([151.49.84.243]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-381ed970d1bsm5555560f8f.16.2024.11.08.10.01.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Nov 2024 10:01:43 -0800 (PST) From: Paolo Bonzini 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 01/11] rust: qemu_api: do not disable lints outside bindgen-generated code Date: Fri, 8 Nov 2024 19:01:29 +0100 Message-ID: <20241108180139.117112-2-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241108180139.117112-1-pbonzini@redhat.com> References: <20241108180139.117112-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org rust/qemu-api/src/lib.rs is disabling lints that cause problems with code generated by bindgen. Instead, include the bindgen code via include!(...) and move the #![allow()] directives into the bindings module. Add MESON_BUILD_ROOT to the devenv, so that it's easy for build.rs to find the include file. Signed-off-by: Paolo Bonzini --- meson.build | 4 +++- rust/qemu-api/.gitignore | 2 +- rust/qemu-api/build.rs | 20 ++++++++++++++------ rust/qemu-api/meson.build | 1 + rust/qemu-api/src/bindings.rs | 29 +++++++++++++++++++++++++++++ rust/qemu-api/src/lib.rs | 22 ---------------------- 6 files changed, 48 insertions(+), 30 deletions(-) create mode 100644 rust/qemu-api/src/bindings.rs diff --git a/meson.build b/meson.build index e0b880e4e13..a7342c6edbd 100644 --- a/meson.build +++ b/meson.build @@ -3,6 +3,8 @@ project('qemu', ['c'], meson_version: '>=1.5.0', 'b_staticpic=false', 'stdsplit=false', 'optimization=2', 'b_pie=true'], version: files('VERSION')) +meson.add_devenv({ 'MESON_BUILD_ROOT' : meson.project_build_root() }) + add_test_setup('quick', exclude_suites: ['slow', 'thorough'], is_default: true) add_test_setup('slow', exclude_suites: ['thorough'], env: ['G_TEST_SLOW=1', 'SPEED=slow']) add_test_setup('thorough', env: ['G_TEST_SLOW=1', 'SPEED=thorough']) @@ -4089,7 +4091,7 @@ if have_rust bindings_rs = rust.bindgen( input: 'rust/wrapper.h', dependencies: common_ss.all_dependencies(), - output: 'bindings.rs', + output: 'bindings.rs.inc', include_directories: include_directories('.', 'include'), bindgen_version: ['>=0.60.0'], args: bindgen_args, diff --git a/rust/qemu-api/.gitignore b/rust/qemu-api/.gitignore index b9e7e004c86..2accb8745dc 100644 --- a/rust/qemu-api/.gitignore +++ b/rust/qemu-api/.gitignore @@ -1,2 +1,2 @@ # Ignore generated bindings file overrides. -src/bindings.rs +/src/bindings.rs.inc diff --git a/rust/qemu-api/build.rs b/rust/qemu-api/build.rs index 20f8f718b90..e4eab718553 100644 --- a/rust/qemu-api/build.rs +++ b/rust/qemu-api/build.rs @@ -2,18 +2,26 @@ // Author(s): Manos Pitsidianakis // SPDX-License-Identifier: GPL-2.0-or-later -use std::path::Path; +use std::{env, path::Path}; use version_check as rustc; fn main() { - if !Path::new("src/bindings.rs").exists() { - panic!( - "No generated C bindings found! Either build them manually with bindgen or with meson \ - (`ninja bindings.rs`) and copy them to src/bindings.rs, or build through meson." - ); + // Placing bindings.rs.inc in the source directory is supported + // but not documented or encouraged. + let path = env::var("MESON_BUILD_ROOT") + .unwrap_or_else(|_| format!("{}/src", env!("CARGO_MANIFEST_DIR"))); + + let file = format!("{}/bindings.rs.inc", path); + if !Path::new(&file).exists() { + panic!(concat!( + "No generated C bindings found! If you want to run `cargo`, start a subshell\n", + "with `meson devenv`, or point MESON_BUILD_ROOT to the top of the build tree." + )); } + println!("cargo:rustc-env=BINDINGS_RS_INC={}", file); + // Check for available rustc features if rustc::is_min_version("1.77.0").unwrap_or(false) { println!("cargo:rustc-cfg=has_offset_of"); diff --git a/rust/qemu-api/meson.build b/rust/qemu-api/meson.build index 6f637af7b1b..e3870e901e3 100644 --- a/rust/qemu-api/meson.build +++ b/rust/qemu-api/meson.build @@ -9,6 +9,7 @@ _qemu_api_rs = static_library( structured_sources( [ 'src/lib.rs', + 'src/bindings.rs', 'src/c_str.rs', 'src/definitions.rs', 'src/device_class.rs', diff --git a/rust/qemu-api/src/bindings.rs b/rust/qemu-api/src/bindings.rs new file mode 100644 index 00000000000..1dac310594d --- /dev/null +++ b/rust/qemu-api/src/bindings.rs @@ -0,0 +1,29 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +#![allow( + dead_code, + improper_ctypes_definitions, + improper_ctypes, + non_camel_case_types, + non_snake_case, + non_upper_case_globals, + unsafe_op_in_unsafe_fn, + clippy::missing_const_for_fn, + clippy::too_many_arguments, + clippy::approx_constant, + clippy::use_self, + clippy::useless_transmute, + clippy::missing_safety_doc +)] + +#[cfg(MESON)] +include!("bindings.rs.inc"); + +#[cfg(not(MESON))] +include!(env!("BINDINGS_RS_INC")); + +unsafe impl Send for Property {} +unsafe impl Sync for Property {} +unsafe impl Sync for TypeInfo {} +unsafe impl Sync for VMStateDescription {} +unsafe impl Sync for VMStateField {} +unsafe impl Sync for VMStateInfo {} diff --git a/rust/qemu-api/src/lib.rs b/rust/qemu-api/src/lib.rs index aa8d16ec94b..440aff3817d 100644 --- a/rust/qemu-api/src/lib.rs +++ b/rust/qemu-api/src/lib.rs @@ -4,31 +4,9 @@ #![cfg_attr(not(MESON), doc = include_str!("../README.md"))] -#[allow( - dead_code, - improper_ctypes_definitions, - improper_ctypes, - non_camel_case_types, - non_snake_case, - non_upper_case_globals, - unsafe_op_in_unsafe_fn, - clippy::missing_const_for_fn, - clippy::too_many_arguments, - clippy::approx_constant, - clippy::use_self, - clippy::useless_transmute, - clippy::missing_safety_doc, -)] #[rustfmt::skip] pub mod bindings; -unsafe impl Send for bindings::Property {} -unsafe impl Sync for bindings::Property {} -unsafe impl Sync for bindings::TypeInfo {} -unsafe impl Sync for bindings::VMStateDescription {} -unsafe impl Sync for bindings::VMStateField {} -unsafe impl Sync for bindings::VMStateInfo {} - pub mod c_str; pub mod definitions; pub mod device_class; From patchwork Fri Nov 8 18:01:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13868825 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9AA0CD64072 for ; Fri, 8 Nov 2024 18:04:18 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t9TJ2-0001pI-55; Fri, 08 Nov 2024 13:02:01 -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 1t9TIw-0001o5-7F for qemu-devel@nongnu.org; Fri, 08 Nov 2024 13:01:54 -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 1t9TIu-0001v4-G1 for qemu-devel@nongnu.org; Fri, 08 Nov 2024 13:01:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1731088911; 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=eX7uUTJtFkCsP2+rTSsbiyuX9JxoUOb2ob7tcl3vQYY=; b=LxFgeZFrGDlfyKMGivTcd+X5OOratG+RcehuJDuWrrHrrOchlI8YAOwVSiA8Ci+4QV+CzR 93GgImHw/BZzub18J+RWiSM2c/jkGoKF+nO82SVXfFM7GOKycUgpBEpzwrcudJ9a/3q6jC zu2SH6Ll+hDiu+eoyofNUvRCPxLGrps= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-456-espbQXhHPrKlaL6u3Bwkzg-1; Fri, 08 Nov 2024 13:01:50 -0500 X-MC-Unique: espbQXhHPrKlaL6u3Bwkzg-1 X-Mimecast-MFC-AGG-ID: espbQXhHPrKlaL6u3Bwkzg Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4315afcae6cso14195875e9.0 for ; Fri, 08 Nov 2024 10:01:50 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731088908; x=1731693708; 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=eX7uUTJtFkCsP2+rTSsbiyuX9JxoUOb2ob7tcl3vQYY=; b=DidVcYlzsjC/VGR2/jlMwrE7Y1KUywiHYysIEhN4thZ0Z7ieQMH3oYpieAAM8WD4kq T2gWk6Qx8jiKtiWjG4G3HE/NzynOojQ61IL4dVLhCW2aFo0xYFqSjYNVBbaeIcUSI1zz QX3hKWkNBY84vhcQvJTqVBmYHcN0i08fCoNwOS5uWPy96bjkccM35XsDrqTeVnXY6cGg UZhUXBuZtdE9KludSBqsK8wGxczMeFRICJZrPl5aN3AEyj80CunQqj+Ep9O9qODhcbGC lxKiaZ3qurdvzLINU+dbUWiPhcI1FLvnRcsuDg9wSnwlL/1kPQ34DoyLzOTkhtIWqzzu 62jg== X-Gm-Message-State: AOJu0YzGoHygYoL+hlJpxN0g7OBBxii89+hmX/zj5+ZL1jhKwMhSAA6i FXO6bYaQfT1mSGijLodFoZuCUIvsU+rrVm+dutaA5vLBhRylXfNa6YZDX045gmpq/T0YsKQog6b LJi8PDXpL+RtLFCyBJONApBg3fcV/a9uC3kkUTGR6NvyMzlaEOFNIMTIf5gKrstuaFg3+rBmJYy bpEO1as/tJRNJEEHi5pXg7cXlJxuf47u5U/XIV0tw= X-Received: by 2002:a05:600c:35c9:b0:431:4e33:98b6 with SMTP id 5b1f17b1804b1-432b744eb43mr33058135e9.5.1731088908385; Fri, 08 Nov 2024 10:01:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IEFwtqVHHAOdjFWs6lX6Rk2Gc37fRg1QVcCrWVI39JEvaYjJc0xice8UqHMPWJbQl6S1+99xw== X-Received: by 2002:a05:600c:35c9:b0:431:4e33:98b6 with SMTP id 5b1f17b1804b1-432b744eb43mr33057545e9.5.1731088907740; Fri, 08 Nov 2024 10:01:47 -0800 (PST) Received: from [192.168.10.47] ([151.49.84.243]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-432aa70a23fsm121326055e9.33.2024.11.08.10.01.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Nov 2024 10:01:47 -0800 (PST) From: Paolo Bonzini 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 02/11] rust: build: move rustc_args.py invocation to individual crates Date: Fri, 8 Nov 2024 19:01:30 +0100 Message-ID: <20241108180139.117112-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241108180139.117112-1-pbonzini@redhat.com> References: <20241108180139.117112-1-pbonzini@redhat.com> MIME-Version: 1.0 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: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, 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_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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Only qemu-api needs access to the symbols in config-host.h. Remove the temptation to use them by limiting the --cfg arguments to the qemu-api crate. Signed-off-by: Paolo Bonzini --- meson.build | 54 +++++++++++++++++---------------------- rust/qemu-api/meson.build | 4 +++ 2 files changed, 28 insertions(+), 30 deletions(-) diff --git a/meson.build b/meson.build index a7342c6edbd..7a9a523467b 100644 --- a/meson.build +++ b/meson.build @@ -120,7 +120,29 @@ if have_rust endif if have_rust + rustc_args = find_program('scripts/rust/rustc_args.py') rustfmt = find_program('rustfmt', required: false) + + # Prohibit code that is forbidden in Rust 2024 + rustc_lint_args = ['-D', 'unsafe_op_in_unsafe_fn'] + + # 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 + # passing -nodefaultlibs to the linker "was more ideological to + # start with than anything". + add_project_arguments(rustc_lint_args + ['-C', 'default-linker-libraries'], + native: false, language: 'rust') + + add_project_arguments(rustc_lint_args, native: true, language: 'rust') endif dtrace = not_found @@ -3399,36 +3421,8 @@ endif # Generated sources # ##################### -genh += configure_file(output: 'config-host.h', configuration: config_host_data) - -if have_rust - rustc_args = run_command( - find_program('scripts/rust/rustc_args.py'), - '--config-headers', meson.project_build_root() / 'config-host.h', - capture : true, - check: true).stdout().strip().split() - - # Prohibit code that is forbidden in Rust 2024 - rustc_args += ['-D', 'unsafe_op_in_unsafe_fn'] - - # 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_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 - # passing -nodefaultlibs to the linker "was more ideological to - # start with than anything". - add_project_arguments(rustc_args + ['-C', 'default-linker-libraries'], - native: false, language: 'rust') - - add_project_arguments(rustc_args, native: true, language: 'rust') -endif +config_host_h = configure_file(output: 'config-host.h', configuration: config_host_data) +genh += config_host_h hxtool = find_program('scripts/hxtool') shaderinclude = find_program('scripts/shaderinclude.py') diff --git a/rust/qemu-api/meson.build b/rust/qemu-api/meson.build index e3870e901e3..f84f85b88c6 100644 --- a/rust/qemu-api/meson.build +++ b/rust/qemu-api/meson.build @@ -4,6 +4,10 @@ if rustc.version().version_compare('>=1.77.0') _qemu_api_cfg += ['--cfg', 'has_offset_of'] endif +_qemu_api_cfg += run_command(rustc_args, + '--config-headers', config_host_h, + capture: true, check: true).stdout().strip().split() + _qemu_api_rs = static_library( 'qemu_api', structured_sources( From patchwork Fri Nov 8 18:01:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13868824 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 96C0AD64072 for ; Fri, 8 Nov 2024 18:04:02 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t9TJ4-0001so-6c; Fri, 08 Nov 2024 13:02:02 -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 1t9TIy-0001oj-Qm for qemu-devel@nongnu.org; Fri, 08 Nov 2024 13:01:58 -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 1t9TIx-0001vh-85 for qemu-devel@nongnu.org; Fri, 08 Nov 2024 13:01:56 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1731088914; 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=NtlWVHUs02V1J7NuepxEhAY1b+bPSGqGN7MAC+hr2Y4=; b=BemJddRb2NV/4RkOk3PJSrX4eDWa+WS8N9K4RRtwLFMMSW4TcW03qQq1XPmYIXGoH4GfO0 SAnq/VX4aaIciZx09M21CIaMHkutYTKmkSScCfe0KGOGIElrvJ7B7pEHqf7r8Xq1tX4lxB ztRMa87ppfbUXnDL6zorb1Zoc/vCM60= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-538-Lu1_ClCbPJyiNsdfw2aoRw-1; Fri, 08 Nov 2024 13:01:53 -0500 X-MC-Unique: Lu1_ClCbPJyiNsdfw2aoRw-1 X-Mimecast-MFC-AGG-ID: Lu1_ClCbPJyiNsdfw2aoRw Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-431673032e6so15596495e9.0 for ; Fri, 08 Nov 2024 10:01:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731088911; x=1731693711; 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=NtlWVHUs02V1J7NuepxEhAY1b+bPSGqGN7MAC+hr2Y4=; b=JxYcMTZ4L4Uio6O3IG/KwnP4/Rmtd1iVWuJqJON0OfKzjXrOVGpy0mMWUEMpn103Qm +Yxit4eKalM2PfokBAwAtIURxvme4RdnB2Yem5aQhhtJjLuU+f1E8pWXV2Kg2ccFvo2z lcmI/uZFvdVRXjkqgK1LD7gnwgcVe0U/2pNYq6VWHhOHTYlYUmThceBHDeObt+Qu4qs9 e1EkkH42Jb9UNZuAiqc1xtXuf2Y/+EXdwgPWMesm6SQUtIp+9R27Kd0QXZRgzIC6Mw2v /oxUWKpQlJmra1/LRc2mHuRC9TMHBsXeJ3xcnYFeffEESKQtKys6jombHcLQNy3TYsCw Yi6Q== X-Gm-Message-State: AOJu0YwbNEzx4NSt77QHKfUYXL7pNn6KyANH2rHV7oOxmhl2huAqQMQB gP7tQA3H1PlxMikXrF2RRZWaM9rbfMqZsfJVGgX1GT2HC7xhijUqcWBXLXPjUOlcbG5KUaTs8LL vok3BSENZ6YalHOTgYBNoqW77TTIaSEHgD2b5k4UpMoIARuT/z8NlsxP8Vh8vcz1K9YBn8DnVl8 1Q+0Lt3r0JH4mlmD7dIhTpW1KZdK88rWSKaCh7D2g= X-Received: by 2002:a5d:5f93:0:b0:37c:ddab:a626 with SMTP id ffacd0b85a97d-381f18270b9mr3455486f8f.7.1731088911224; Fri, 08 Nov 2024 10:01:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IHXpELzcUPuq1aHn/ar1IEsvO024hFlT6xiueWWzvOMBU+egxqHhCsJJmsob2IeLdpsLN+guQ== X-Received: by 2002:a5d:5f93:0:b0:37c:ddab:a626 with SMTP id ffacd0b85a97d-381f18270b9mr3455431f8f.7.1731088910636; Fri, 08 Nov 2024 10:01:50 -0800 (PST) Received: from [192.168.10.47] ([151.49.84.243]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-432aa6b2a3bsm113584455e9.11.2024.11.08.10.01.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Nov 2024 10:01:49 -0800 (PST) From: Paolo Bonzini 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 03/11] rust: build: restrict --cfg generation to only required symbols Date: Fri, 8 Nov 2024 19:01:31 +0100 Message-ID: <20241108180139.117112-4-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241108180139.117112-1-pbonzini@redhat.com> References: <20241108180139.117112-1-pbonzini@redhat.com> MIME-Version: 1.0 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: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, 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_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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Parse the Cargo.toml file, looking for the unexpected_cfgs configuration. When generating --cfg options from the config-host.h file, only use those that are included in the configuration. Signed-off-by: Paolo Bonzini --- rust/qemu-api/meson.build | 2 +- scripts/rust/rustc_args.py | 61 ++++++++++++++++++++++++++++---------- 2 files changed, 46 insertions(+), 17 deletions(-) diff --git a/rust/qemu-api/meson.build b/rust/qemu-api/meson.build index f84f85b88c6..bb2ed2844dc 100644 --- a/rust/qemu-api/meson.build +++ b/rust/qemu-api/meson.build @@ -5,7 +5,7 @@ if rustc.version().version_compare('>=1.77.0') endif _qemu_api_cfg += run_command(rustc_args, - '--config-headers', config_host_h, + '--config-headers', config_host_h, files('Cargo.toml'), capture: true, check: true).stdout().strip().split() _qemu_api_rs = static_library( diff --git a/scripts/rust/rustc_args.py b/scripts/rust/rustc_args.py index e4cc9720e16..942dd2b2bab 100644 --- a/scripts/rust/rustc_args.py +++ b/scripts/rust/rustc_args.py @@ -26,30 +26,51 @@ import argparse import logging +from pathlib import Path +from typing import Any, Iterable, Mapping, Optional, Set -from typing import List +try: + import tomllib +except ImportError: + import tomli as tomllib -def generate_cfg_flags(header: str) -> List[str]: +class CargoTOML: + tomldata: Mapping[Any, Any] + check_cfg: Set[str] + + def __init__(self, path: str): + with open(path, 'rb') as f: + self.tomldata = tomllib.load(f) + + self.check_cfg = set(self.find_check_cfg()) + + def find_check_cfg(self) -> Iterable[str]: + toml_lints = self.lints + rust_lints = toml_lints.get("rust", {}) + cfg_lint = rust_lints.get("unexpected_cfgs", {}) + return cfg_lint.get("check-cfg", []) + + @property + def lints(self) -> Mapping[Any, Any]: + return self.get_table("lints") + + def get_table(self, key: str) -> Mapping[Any, Any]: + table = self.tomldata.get(key, {}) + + return table + + +def generate_cfg_flags(header: str, cargo_toml: CargoTOML) -> Iterable[str]: """Converts defines from config[..].h headers to rustc --cfg flags.""" - def cfg_name(name: str) -> str: - """Filter function for C #defines""" - if ( - name.startswith("CONFIG_") - or name.startswith("TARGET_") - or name.startswith("HAVE_") - ): - return name - return "" - with open(header, encoding="utf-8") as cfg: config = [l.split()[1:] for l in cfg if l.startswith("#define")] cfg_list = [] for cfg in config: - name = cfg_name(cfg[0]) - if not name: + name = cfg[0] + if f'cfg({name})' not in cargo_toml.check_cfg: continue if len(cfg) >= 2 and cfg[1] != "1": continue @@ -59,7 +80,6 @@ def cfg_name(name: str) -> str: def main() -> None: - # pylint: disable=missing-function-docstring parser = argparse.ArgumentParser() parser.add_argument("-v", "--verbose", action="store_true") parser.add_argument( @@ -71,12 +91,21 @@ def main() -> None: required=False, default=[], ) + parser.add_argument( + metavar="TOML_FILE", + action="store", + dest="cargo_toml", + help="path to Cargo.toml file", + ) args = parser.parse_args() if args.verbose: logging.basicConfig(level=logging.DEBUG) logging.debug("args: %s", args) + + cargo_toml = CargoTOML(args.cargo_toml) + for header in args.config_headers: - for tok in generate_cfg_flags(header): + for tok in generate_cfg_flags(header, cargo_toml): print(tok) From patchwork Fri Nov 8 18:01:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13868829 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0E00DD64074 for ; Fri, 8 Nov 2024 18:05:04 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t9TJ6-0001vI-DW; Fri, 08 Nov 2024 13:02:04 -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 1t9TJ1-0001pD-QP for qemu-devel@nongnu.org; Fri, 08 Nov 2024 13:01:59 -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 1t9TJ0-0001vu-8x for qemu-devel@nongnu.org; Fri, 08 Nov 2024 13:01:59 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1731088917; 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=i9F6HrT6yGM1H4hD8DpIdP6B53mjE1AzSwSbMGZrK5g=; b=G/39kxUE6mjjX+6ke0d76bJwqg2bepqJYwim5+LKhGuV9HLrtXLk2kt8jZPMQds63RjF+0 dSL71h/vpl1LAhyuEKUHYP4b2BpIEREFUC7UE6BUzbXaYEaZvxtCy0Q5V1jU89abfHlW78 prwVwDqSgs1AVpbhkY+VAjZoMMCrekQ= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-642-w3FSyBS0NNmqzDJBzOx9_w-1; Fri, 08 Nov 2024 13:01:56 -0500 X-MC-Unique: w3FSyBS0NNmqzDJBzOx9_w-1 X-Mimecast-MFC-AGG-ID: w3FSyBS0NNmqzDJBzOx9_w Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-37d5ca192b8so1416147f8f.1 for ; Fri, 08 Nov 2024 10:01:56 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731088915; x=1731693715; 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=i9F6HrT6yGM1H4hD8DpIdP6B53mjE1AzSwSbMGZrK5g=; b=aj47GmraBmUBVZGgW+W/HHEH+8BH8tRnvm8XI/htKANvssxmDRTqDyBlKHzZA/U3Ah 0w2j+Jvy+VCl32vwn1y6r/EPAWknorAJP1xYHouR+yvIFM1wwvUJrHrj3zPApiI1iG36 93OXKnCGyDaUjU6FYtLrxyLvBeWoRnkG44jnP5F4ZLIW9OZ0nQ1NyMbg7v191nHU0OeK GqnTRxkvdr4nV7uITEjY8Z3+K9Bt4YnEfBSGLCLOTduQ+W3jrLimgvH6g23V4ew/TKdK EEEMg0qMrJ3ryVewNjD3ElweY0j+zxtYo9O67mJ72va/qZa5kyQSKdpdnR6J45yRAogl kRsA== X-Gm-Message-State: AOJu0YxRYHMxSGOoPAAOdsdMUOtViolq3ysLL2Fva/7/lyqNAieg+g4B NZhfzwCAn9ggqKw7skpKhGrwc/G6fNi7NcWH6k9OWItmEHsTujP6zpe/C3cyYoD0/jceLBXE8iM z73h8Z616DcWC90bzfQvnpqrLVDZo8iDHLnEPhSra7fo2nv22DIlN8TLk1jaEUzop0XZQJpPj6W zHpdZVulqP0g4QTga1k1QA6OBunkoMYamMXPovDdg= X-Received: by 2002:a05:6000:a07:b0:37d:4610:dca with SMTP id ffacd0b85a97d-381f1c934bbmr2798154f8f.31.1731088914807; Fri, 08 Nov 2024 10:01:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IHAr7KAt4sUs/liSregzTDi1Dju8hECZKju/oHpVQnPMmkx+E9pSaC3qy/KZf9/upC3EVJslA== X-Received: by 2002:a05:6000:a07:b0:37d:4610:dca with SMTP id ffacd0b85a97d-381f1c934bbmr2798047f8f.31.1731088913489; Fri, 08 Nov 2024 10:01:53 -0800 (PST) Received: from [192.168.10.47] ([151.49.84.243]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-381ed974d60sm5691697f8f.2.2024.11.08.10.01.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Nov 2024 10:01:52 -0800 (PST) From: Paolo Bonzini 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 04/11] rust: build: generate warning flags from Cargo.toml Date: Fri, 8 Nov 2024 19:01:32 +0100 Message-ID: <20241108180139.117112-5-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241108180139.117112-1-pbonzini@redhat.com> References: <20241108180139.117112-1-pbonzini@redhat.com> MIME-Version: 1.0 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: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, 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_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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Cargo.toml makes it possible to describe the desired lint level settings in a nice format. We can extend this to Meson-built crates, by teaching rustc_args.py to fetch lint and --check-cfg arguments from Cargo.toml. Start with qemu-api, since it already has a [lints.rust] table and an invocation of rustc_args.py. Signed-off-by: Paolo Bonzini --- rust/qemu-api/meson.build | 4 +- scripts/rust/rustc_args.py | 83 +++++++++++++++++++++++++++++++++++++- 2 files changed, 84 insertions(+), 3 deletions(-) diff --git a/rust/qemu-api/meson.build b/rust/qemu-api/meson.build index bb2ed2844dc..4ba5607d66b 100644 --- a/rust/qemu-api/meson.build +++ b/rust/qemu-api/meson.build @@ -5,8 +5,8 @@ if rustc.version().version_compare('>=1.77.0') endif _qemu_api_cfg += run_command(rustc_args, - '--config-headers', config_host_h, files('Cargo.toml'), - capture: true, check: true).stdout().strip().split() + '--config-headers', config_host_h, '--features', '--lints', files('Cargo.toml'), + capture: true, check: true).stdout().strip().splitlines() _qemu_api_rs = static_library( 'qemu_api', diff --git a/scripts/rust/rustc_args.py b/scripts/rust/rustc_args.py index 942dd2b2bab..9b9778a1cac 100644 --- a/scripts/rust/rustc_args.py +++ b/scripts/rust/rustc_args.py @@ -25,9 +25,10 @@ """ import argparse +from dataclasses import dataclass import logging from pathlib import Path -from typing import Any, Iterable, Mapping, Optional, Set +from typing import Any, Iterable, List, Mapping, Optional, Set try: import tomllib @@ -61,6 +62,45 @@ def get_table(self, key: str) -> Mapping[Any, Any]: return table +@dataclass +class LintFlag: + flags: List[str] + priority: int + + +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 + + lint_list = [] + for k, v in toml_lints.items(): + prefix = "" if k == "rust" else k + "::" + for lint, data in v.items(): + level = data if isinstance(data, str) else data["level"] + priority = 0 if isinstance(data, str) else data.get("priority", 0) + if level == "deny": + flag = "-D" + elif level == "allow": + flag = "-A" + elif level == "warn": + flag = "-W" + elif level == "forbid": + flag = "-F" + else: + raise Exception(f"invalid level {level} for {prefix}{lint}") + + # 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": + lint_list.append(LintFlag(flags=[flag, prefix + lint], priority=priority)) + + lint_list.sort(key=lambda x: x.priority) + for lint in lint_list: + yield from lint.flags + + def generate_cfg_flags(header: str, cargo_toml: CargoTOML) -> Iterable[str]: """Converts defines from config[..].h headers to rustc --cfg flags.""" @@ -97,13 +137,54 @@ def main() -> None: dest="cargo_toml", help="path to Cargo.toml file", ) + parser.add_argument( + "--features", + action="store_true", + dest="features", + help="generate --check-cfg arguments for features", + required=False, + default=None, + ) + parser.add_argument( + "--lints", + action="store_true", + dest="lints", + help="generate arguments from [lints] table", + required=False, + default=None, + ) + parser.add_argument( + "--rustc-version", + metavar="VERSION", + dest="rustc_version", + action="store", + help="version of rustc", + required=False, + default="1.0.0", + ) args = parser.parse_args() if args.verbose: logging.basicConfig(level=logging.DEBUG) logging.debug("args: %s", args) + rustc_version = tuple((int(x) for x in args.rustc_version.split('.')[0:2])) cargo_toml = CargoTOML(args.cargo_toml) + if args.lints: + for tok in generate_lint_flags(cargo_toml): + print(tok) + + if rustc_version >= (1, 80): + if args.lints: + for cfg in sorted(cargo_toml.check_cfg): + print("--check-cfg") + print(cfg) + if args.features: + for feature in cargo_toml.get_table("features"): + if feature != "default": + print("--check-cfg") + print(f'cfg(feature,values("{feature}"))') + for header in args.config_headers: for tok in generate_cfg_flags(header, cargo_toml): print(tok) From patchwork Fri Nov 8 18:01:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13868823 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1457FD64074 for ; Fri, 8 Nov 2024 18:04:01 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t9TJ6-0001uv-1e; Fri, 08 Nov 2024 13:02:04 -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 1t9TJ2-0001pQ-U0 for qemu-devel@nongnu.org; Fri, 08 Nov 2024 13:02:01 -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 1t9TJ1-0001w3-5G for qemu-devel@nongnu.org; Fri, 08 Nov 2024 13:02:00 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1731088918; 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=fxhgCHPLQNWjm3q9UX6Y4fEbkNDm7Az8YB8FU2F2Ov0=; b=OPPPGpKYUQfl1ym0alDSuzt856nO9c0xqslhieiiJPXX64EaM2Jr9EvU0HXqxGDQHKcpvW m0lWVlV5t3cPqVtxKK6z5YeDfhAaTzrFHCAI4XuMWjBo4a0ih2kXS1FN5zCN8B0M9Wb1iD As1hKxs0EV4E4+nbAsf7V6Dbpsntjn4= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-664-ZGifC13FNsulRPECXw_6pw-1; Fri, 08 Nov 2024 13:01:57 -0500 X-MC-Unique: ZGifC13FNsulRPECXw_6pw-1 X-Mimecast-MFC-AGG-ID: ZGifC13FNsulRPECXw_6pw Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-43164f21063so15475645e9.2 for ; Fri, 08 Nov 2024 10:01:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731088916; x=1731693716; 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=fxhgCHPLQNWjm3q9UX6Y4fEbkNDm7Az8YB8FU2F2Ov0=; b=e0IPELXU+tV2meOe81aABTk6+EqCZhqRNwdEEAWJYWuZTyLOTTsBdz/ejiczxfMoZo l+xSxBNopwc4LGzsYpZofDeWB9tb32S01CzrRg+LdS9U9ovV648Fz+6QlcL4P45Ra2It vvTzQV6+tngOgnhZLu0U5ucE8rhHkte8ndIpxuesfcOeU/BXDOpMPrNULH4VuQTeWEly 3x9tQDskkO/4X/OMUXBrAhtfCCaF3k0qlFyYz77P0UgDsjKwvs6t+ZX116K9S+o+QcqC bsBxCnMzdoJxVpQQnIQAsnA/o3xmwRV7na7nl5ve+O7rsyrc+05ywOavxLNxvAMQBoyP Vvpw== X-Gm-Message-State: AOJu0Ywp1bWml5inhFT/oO3/JHXZIaNufdLzJxUJnggFmYoJksOfF81A kghcy9edTuntMDKirWLOJvPmbz3H6u0eBxFZzNgPCA+1laddus7j1peNNnSycFf1aC10G9y1j+r NMeTrMzFTCbjnzu5B5e8MsgJNfjirv2s7zVk8AwZWKIM/6vru9yyjdHhJvSvpGjV7cvO34vgmta j9gWg7pysH6IeP7JHIIxlnsJjAOiQaceUjPympjFo= X-Received: by 2002:a05:600c:5251:b0:431:5f1c:8352 with SMTP id 5b1f17b1804b1-432b74fc842mr30874945e9.5.1731088915642; Fri, 08 Nov 2024 10:01:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IEoWfFl7m81wcIo5aOMoYnPF8LluVD0b+f9XkvT+VYIrAT4pTuM0QmDN0pWZqo2PgN5FjXJqw== X-Received: by 2002:a05:600c:5251:b0:431:5f1c:8352 with SMTP id 5b1f17b1804b1-432b74fc842mr30874485e9.5.1731088915106; Fri, 08 Nov 2024 10:01:55 -0800 (PST) Received: from [192.168.10.47] ([151.49.84.243]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-432bbf436ffsm12527375e9.44.2024.11.08.10.01.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Nov 2024 10:01:54 -0800 (PST) From: Paolo Bonzini 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 05/11] rust: cargo: store desired warning levels in workspace Cargo.toml Date: Fri, 8 Nov 2024 19:01:33 +0100 Message-ID: <20241108180139.117112-6-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241108180139.117112-1-pbonzini@redhat.com> References: <20241108180139.117112-1-pbonzini@redhat.com> MIME-Version: 1.0 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: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, 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_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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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_build_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 | 8 +++++--- 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 | 31 +++++++++++++++++++++++++++---- 7 files changed, 49 insertions(+), 11 deletions(-) diff --git a/meson.build b/meson.build index 7a9a523467b..5726135b324 100644 --- a/meson.build +++ b/meson.build @@ -120,11 +120,13 @@ if have_rust endif if have_rust - rustc_args = find_program('scripts/rust/rustc_args.py') + rustc_args = [find_program('scripts/rust/rustc_args.py'), + '--workspace', meson.project_source_root() / 'rust'] rustfmt = find_program('rustfmt', required: false) - # Prohibit code that is forbidden in Rust 2024 - rustc_lint_args = ['-D', 'unsafe_op_in_unsafe_fn'] + 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 diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 0c94d5037da..0230b92a9fa 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -5,3 +5,11 @@ members = [ "qemu-api", "hw/char/pl011", ] + +[workspace.lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = [ + '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 = "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 = { version = "0.2.0" } bilge-impl = { version = "0.2.0" } qemu_api = { path = "../../../qemu-api" } qemu_api_macros = { path = "../../../qemu-api-macros" } + +[lints] +workspace = true diff --git a/rust/qemu-api-macros/Cargo.toml b/rust/qemu-api-macros/Cargo.toml index a8f7377106b..5a27b52ee6e 100644 --- a/rust/qemu-api-macros/Cargo.toml +++ b/rust/qemu-api-macros/Cargo.toml @@ -20,3 +20,6 @@ proc-macro = true proc-macro2 = "1" quote = "1" syn = { version = "2", features = ["extra-traits"] } + +[lints] +workspace = 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 = "~0.9" default = [] allocator = [] -[lints.rust] -unexpected_cfgs = { level = "warn", check-cfg = ['cfg(MESON)', 'cfg(HAVE_GLIB_WITH_ALIGNED_ALLOC)', - 'cfg(has_offset_of)'] } +[lints] +workspace = true diff --git a/rust/qemu-api/meson.build b/rust/qemu-api/meson.build index 4ba5607d66b..8013911a348 100644 --- a/rust/qemu-api/meson.build +++ b/rust/qemu-api/meson.build @@ -5,7 +5,7 @@ if rustc.version().version_compare('>=1.77.0') endif _qemu_api_cfg += 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() _qemu_api_rs = static_library( diff --git a/scripts/rust/rustc_args.py b/scripts/rust/rustc_args.py index 9b9778a1cac..26733439ed4 100644 --- a/scripts/rust/rustc_args.py +++ b/scripts/rust/rustc_args.py @@ -38,12 +38,19 @@ class CargoTOML: tomldata: Mapping[Any, Any] + workspace_data: Mapping[Any, Any] check_cfg: Set[str] - def __init__(self, path: str): + def __init__(self, path: str, workspace: Optional[str]): with open(path, 'rb') as f: self.tomldata = tomllib.load(f) + if workspace is not None: + with open(workspace, 'rb') as f: + self.workspace_data = tomllib.load(f) + if "workspace" not in self.workspace_data: + self.workspace_data["workspace"] = {} + self.check_cfg = set(self.find_check_cfg()) def find_check_cfg(self) -> Iterable[str]: @@ -54,10 +61,12 @@ def find_check_cfg(self) -> Iterable[str]: @property def lints(self) -> Mapping[Any, Any]: - return self.get_table("lints") + return self.get_table("lints", True) - def get_table(self, key: str) -> Mapping[Any, Any]: + def get_table(self, key: str, can_be_workspace: bool = False) -> Mapping[Any, Any]: table = self.tomldata.get(key, {}) + if can_be_workspace and table.get("workspace", False) is True: + table = self.workspace_data["workspace"].get(key, {}) return table @@ -136,6 +145,16 @@ def main() -> None: action="store", dest="cargo_toml", help="path to Cargo.toml file", + nargs='?', + ) + parser.add_argument( + "--workspace", + metavar="DIR", + action="store", + dest="workspace", + help="path to root of the workspace", + required=False, + default=None, ) parser.add_argument( "--features", @@ -168,7 +187,11 @@ def main() -> None: logging.debug("args: %s", args) rustc_version = tuple((int(x) for x in args.rustc_version.split('.')[0:2])) - cargo_toml = CargoTOML(args.cargo_toml) + if args.workspace: + workspace_cargo_toml = Path(args.workspace, "Cargo.toml").resolve() + cargo_toml = CargoTOML(args.cargo_toml, str(workspace_cargo_toml)) + else: + cargo_toml = CargoTOML(args.cargo_toml, None) if args.lints: for tok in generate_lint_flags(cargo_toml): From patchwork Fri Nov 8 18:01:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13868822 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 20475D64074 for ; Fri, 8 Nov 2024 18:03:25 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t9TJG-0001y0-9M; Fri, 08 Nov 2024 13:02:14 -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 1t9TJ5-0001us-Vi for qemu-devel@nongnu.org; Fri, 08 Nov 2024 13:02:03 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t9TJ4-0001wN-3P for qemu-devel@nongnu.org; Fri, 08 Nov 2024 13:02:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1731088921; 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=PdoMcphvzb4FCO/Yj14yAl+KR/E0sA02B9InmeKS0lc=; b=gD6FYhYpmCPVlEv6EYSctpjFRt4m26VQcbIyzOJe0nUjpw4h1jE1L1Y59FNqnTuZA0BVyG rHLvcopQMjPgdeCPZxk2FUMCsq9Z/d3L1ZO/fV6keYoKEYuH92It0dRxE1wtiaHmLEPdpc LUS2GpRh7Q+F/n9NfOnVmgg7shV7OFA= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-53-T429-Gt2PomWSXnhWknRDA-1; Fri, 08 Nov 2024 13:02:00 -0500 X-MC-Unique: T429-Gt2PomWSXnhWknRDA-1 X-Mimecast-MFC-AGG-ID: T429-Gt2PomWSXnhWknRDA Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4315afcae6cso14197195e9.0 for ; Fri, 08 Nov 2024 10:01:59 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731088918; x=1731693718; 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=PdoMcphvzb4FCO/Yj14yAl+KR/E0sA02B9InmeKS0lc=; b=AmEFwom3yMzZyIn17eIY/1tHD7eZgTJs8wpPH/NxcgsWgp/lK7rstIh51WwIgPrIjD 34TRD5ig9ckXfQmXjbQ38X3b5AIoDGsdKraBV6DqJySKzVNSqvJs92AeAqYAf3ijl55S vzYlF31UPjKZzdem6zYCDX+v7uxqR5b4xD40nEvKHpCTK7Q06ocepl5kuIe9VefLO+Uh i25A+Ok3PQZJqw1KoSR+EcTr9t0QRB2wGRIeL11XgaaXglM1DdqCze6bHZzb1CF7e4Im 2qBYZSbC5O9TlIi05gbI6tOoReMnnSjo+SJEAHooC+m7e89sCQL4SvC6jFMjz7j/Q/Tq lwFw== X-Gm-Message-State: AOJu0YzvIv62XlryS5dcfYtjl4bly2kfMb9zK6OBJ5HT4Z6bUktARE6m 8RXB30mRQ7YDaQ2aCRbySjZ1XXFDTstErTHEOOJdZgtK48SC7U7JYT7RA0sgFKIYKyBdk0S/YaP ZMju56vjbTpwa6OfLyJiJfy4KQG5gVlaaeb+esVy6UVhStgN8/P9t75FjfYAktjjhL0RlP4M2AM K2sDJwAsrCw2rznRo5Wy37VB76aOqQ6zL9vLsmRNI= X-Received: by 2002:a05:600c:1f93:b0:42c:b8c9:16c8 with SMTP id 5b1f17b1804b1-432b74c0f85mr31658965e9.10.1731088917893; Fri, 08 Nov 2024 10:01:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IGj7aT8Q063crw88yC0aKXCGIzp0hTxGWu1PxRM4J+7kfe0o9SCGejKh0ylEFebChKsFXkwqg== X-Received: by 2002:a05:600c:1f93:b0:42c:b8c9:16c8 with SMTP id 5b1f17b1804b1-432b74c0f85mr31658365e9.10.1731088917317; Fri, 08 Nov 2024 10:01:57 -0800 (PST) Received: from [192.168.10.47] ([151.49.84.243]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-432b053069fsm80657835e9.4.2024.11.08.10.01.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Nov 2024 10:01:56 -0800 (PST) From: Paolo Bonzini 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 Message-ID: <20241108180139.117112-7-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241108180139.117112-1-pbonzini@redhat.com> References: <20241108180139.117112-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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 --- 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): From patchwork Fri Nov 8 18:01:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13868827 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CA192D64074 for ; Fri, 8 Nov 2024 18:04:46 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t9TJK-00024w-2d; Fri, 08 Nov 2024 13:02:18 -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 1t9TJ7-0001w0-Ro for qemu-devel@nongnu.org; Fri, 08 Nov 2024 13:02:13 -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 1t9TJ6-0001wa-2h for qemu-devel@nongnu.org; Fri, 08 Nov 2024 13:02:05 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1731088923; 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=XeSGVNmsvm8LjvUgxmz8ceo62A+bkZyrWMrM+uvspEY=; b=BS6KwieEI2L6fksuG3MsAXkqkk6CLvhumZ5jCjZwOYeZefqwvOZsZHR041b0A+9W4sA+dB aBM2tL7M2rbYxrlhD7C91x/rBYmM6esViJu29tU5CVtXTfxCzIumgdzgKTbQyZjB3UvTlU QSJQEX9Puv3GIdT+NrScob9totVWbHw= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-556-nRwnEMYJOHe6mJE1LV9HFQ-1; Fri, 08 Nov 2024 13:02:02 -0500 X-MC-Unique: nRwnEMYJOHe6mJE1LV9HFQ-1 X-Mimecast-MFC-AGG-ID: nRwnEMYJOHe6mJE1LV9HFQ Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-43157e3521dso16472315e9.1 for ; Fri, 08 Nov 2024 10:02:02 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731088921; x=1731693721; 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=XeSGVNmsvm8LjvUgxmz8ceo62A+bkZyrWMrM+uvspEY=; b=ThjLFBBr11BsHlNJw1wJ6f9MbU+T84/VP5BKXP5M6OH/YCRTUce94UwujQ+qV04iFe Ag/Ds3zY3Sry5aefb7MKwyHn6HrN2ftcLf1+pllV4uAyGGhwhZfp4WNaZ/s/fIiqXn1l F8fAdGC/fXF/ztviuP9sieubSew4Cdg0HcghXwC0ABo6tH2dleajfF0mSJohqfd8lCOT GGJ/yb+fShSkCsrdy02aac1kfvuvf28EfNtbnNli3zueG9nCM2J2iQ2D62u0NLHepYfK 6mLCp52f6ER9w2kU44HHw8lWD6IGVuWAddAVOB+wVrFKhYrMy421WjaaHZ8aQVhR6pn0 eRcQ== X-Gm-Message-State: AOJu0YydUeRLSdZVU7BtlR51tdDVZDzuApe/3KSN9o+/+WltFfuA5JTs GI1KQuHqmix9MCp28slnEH3SxfF9J9+PtEzW0uGyUJ7ChOn230oQdChDUkZRo6xULiNLE8q02OU 60KfqypwvRf+FgzBaARjkxRHBT9Xi8HG/ZvSmV8tQuPl+viQjde4OZ7kGaEJUtXM1QRFMamwse0 rm5sFRrcIAjnzIqWKfMnAAzEx+VZGCbRCbq6ZSpCs= X-Received: by 2002:a5d:5f54:0:b0:37d:4cd5:ffec with SMTP id ffacd0b85a97d-381f18632f7mr3182738f8f.2.1731088920709; Fri, 08 Nov 2024 10:02:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IE6MqM3XTfMyjxqmlzETlnQUy/HeyRMRGH1cmQXnh4xpMFRmbqcFDS5aOLRww384l+1I8Gakw== X-Received: by 2002:a5d:5f54:0:b0:37d:4cd5:ffec with SMTP id ffacd0b85a97d-381f18632f7mr3182685f8f.2.1731088920024; Fri, 08 Nov 2024 10:02:00 -0800 (PST) Received: from [192.168.10.47] ([151.49.84.243]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-381ed97c976sm5513147f8f.28.2024.11.08.10.01.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Nov 2024 10:01:59 -0800 (PST) From: Paolo Bonzini 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 07/11] rust: fix a couple style issues from clippy Date: Fri, 8 Nov 2024 19:01:35 +0100 Message-ID: <20241108180139.117112-8-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241108180139.117112-1-pbonzini@redhat.com> References: <20241108180139.117112-1-pbonzini@redhat.com> MIME-Version: 1.0 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: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, 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_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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org These are reported as clippy::semicolon_inside_block and clippy::as_ptr_cast_mut. Signed-off-by: Paolo Bonzini --- rust/hw/char/pl011/src/device.rs | 6 ++++-- rust/hw/char/pl011/src/memory_ops.rs | 4 +++- rust/qemu-api/tests/tests.rs | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs index 2a85960b81f..7f40e7f71fa 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -499,7 +499,9 @@ pub fn update(&self) { let flags = self.int_level & self.int_enabled; for (irq, i) in self.interrupts.iter().zip(IRQMASK) { // SAFETY: self.interrupts have been initialized in init(). - unsafe { qemu_set_irq(*irq, i32::from(flags & i != 0)) }; + unsafe { + qemu_set_irq(*irq, i32::from(flags & i != 0)); + } } } @@ -601,7 +603,7 @@ pub fn post_load(&mut self, _version_id: u32) -> Result<(), ()> { let sysbus: *mut SysBusDevice = dev.cast::(); qdev_prop_set_chr(dev, c_str!("chardev").as_ptr(), chr); - sysbus_realize_and_unref(sysbus, addr_of!(error_fatal) as *mut *mut Error); + sysbus_realize_and_unref(sysbus, addr_of!(error_fatal).cast_mut()); sysbus_mmio_map(sysbus, 0, addr); sysbus_connect_irq(sysbus, 0, irq); dev diff --git a/rust/hw/char/pl011/src/memory_ops.rs b/rust/hw/char/pl011/src/memory_ops.rs index 169d485a4d2..c4e8599ba43 100644 --- a/rust/hw/char/pl011/src/memory_ops.rs +++ b/rust/hw/char/pl011/src/memory_ops.rs @@ -33,7 +33,9 @@ // SAFETY: self.char_backend is a valid CharBackend instance after it's been // initialized in realize(). let cb_ptr = unsafe { core::ptr::addr_of_mut!(state.as_mut().char_backend) }; - unsafe { qemu_chr_fe_accept_input(cb_ptr) }; + unsafe { + qemu_chr_fe_accept_input(cb_ptr); + } val } diff --git a/rust/qemu-api/tests/tests.rs b/rust/qemu-api/tests/tests.rs index 43a4827de12..925f5a3c77b 100644 --- a/rust/qemu-api/tests/tests.rs +++ b/rust/qemu-api/tests/tests.rs @@ -74,6 +74,6 @@ impl Class for DummyClass { unsafe { module_call_init(module_init_type::MODULE_INIT_QOM); - object_unref(object_new(DummyState::TYPE_NAME.as_ptr()) as *mut _); + object_unref(object_new(DummyState::TYPE_NAME.as_ptr()).cast()); } } From patchwork Fri Nov 8 18:01:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13868820 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3B7CFD64077 for ; Fri, 8 Nov 2024 18:03:21 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t9TJL-00027G-PB; Fri, 08 Nov 2024 13:02:19 -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 1t9TJB-0001wG-CR for qemu-devel@nongnu.org; Fri, 08 Nov 2024 13:02:13 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t9TJ9-0001x9-9s for qemu-devel@nongnu.org; Fri, 08 Nov 2024 13:02:08 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1731088926; 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=hRie6B2XwMU0zHx1ZvLnYMj1lxmNXlFqwCtyK6n296w=; b=gb5OtWoZUZAmm6LnplGKp4Vqmuv3yYq9IIDGjr2yKFjxbQP/O9iAMeiacUM4eXcUXp/dor dczz7yy7JdfkN+jYzbNAqgl1R5SAQg8elnXrUsZ9blEEmBWwZG9ktdN0aLKJPNDTSEM2g7 JrrOd56NalB6q5Ez5/Q8gfIddvSyQxg= 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-689-H_q54tkUOLmHzzD-dEF6yA-1; Fri, 08 Nov 2024 13:02:05 -0500 X-MC-Unique: H_q54tkUOLmHzzD-dEF6yA-1 X-Mimecast-MFC-AGG-ID: H_q54tkUOLmHzzD-dEF6yA Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4315e8e9b1cso14056755e9.1 for ; Fri, 08 Nov 2024 10:02:05 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731088924; x=1731693724; 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=hRie6B2XwMU0zHx1ZvLnYMj1lxmNXlFqwCtyK6n296w=; b=kWQVCRR3blvwIp8FlwUBYMBTpCowt5ZGDfhJxHpV1W2bGqmqLhJvEcRo/fKUm9QfH6 22rBOIHQReY804N+knChxYvPvOej2dC5jb61cL6VelHV6/2GfARrn4y2OE/i0qo9NxEl ONlxcTd3qF+GC4RRb9maYF7Ce5CIi7koyFXctwzObh+ToZLb4h3X35u2anQ9rKNqn/Gb mmvsOcynoRJg4okGeYpqynsMhD4C5EwRqtrg/k+DaALRRNrqRU51w5JbNOKKKSHqA8jP GiP2UXPjWe8KHLLObB1XAPoUIPzRzarW9wF/Gea+kAH30Bg/I4r97yA1qZNL1XhcjIHy 9PGg== X-Gm-Message-State: AOJu0YwDgrK1YC4ancHFufY2MyC1wFsCo0K9hbX/Kg3SwRURWsiMKiW/ UCCDMwll2+nno0k5G9JkF58tQOA8uMMObBxztpFxGWiorWWqp6XJ0Qh7lHXn+WYpqhjs12Sxq4S 9+azKAhj9NjW79mOPekLd5zekGli8hcaLb9lmv3Y2CW66mjjvPciYy0S9+nRwy7vFBPm+JkCKOV 1ARcoVifXUwxPjyeXZ6o+qb3ubIfAGw1g2a7Vw4cQ= X-Received: by 2002:a05:600c:4ecf:b0:431:7ccd:ff8a with SMTP id 5b1f17b1804b1-432b74ce3d1mr30667225e9.14.1731088923547; Fri, 08 Nov 2024 10:02:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IEM866rkMICirYWcCwnUjyUaInIOr2ho1v2OsM8Rf6FAwsNub8IXTuUByiv9YwghmNglIabqA== X-Received: by 2002:a05:600c:4ecf:b0:431:7ccd:ff8a with SMTP id 5b1f17b1804b1-432b74ce3d1mr30666585e9.14.1731088922821; Fri, 08 Nov 2024 10:02:02 -0800 (PST) Received: from [192.168.10.47] ([151.49.84.243]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-381ed9707d3sm5523154f8f.19.2024.11.08.10.02.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Nov 2024 10:02:02 -0800 (PST) From: Paolo Bonzini 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 08/11] rust: build: establish a baseline of lints across all crates Date: Fri, 8 Nov 2024 19:01:36 +0100 Message-ID: <20241108180139.117112-9-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241108180139.117112-1-pbonzini@redhat.com> References: <20241108180139.117112-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Many lints that default to allow can be helpful in detecting bugs or keeping the code style homogeneous. Add them liberally, though perhaps not as liberally as in hw/char/pl011/src/lib.rs. In particular, enabling entire groups can be problematic because of bitrot when new links are added in the future. For Clippy, this is actually a feature that is only present in Cargo 1.74.0 but, since we are not using Cargo to *build* QEMU, only developers will need a new-enough cargo and only to run tools such as clippy. The requirement does not apply to distros that are building QEMU. Signed-off-by: Paolo Bonzini --- rust/Cargo.toml | 66 +++++++++++++++++++++++++++++++++++ rust/hw/char/pl011/src/lib.rs | 18 ++-------- rust/qemu-api/src/bindings.rs | 6 ++-- 3 files changed, 71 insertions(+), 19 deletions(-) diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 1ff8f5c2781..43cca33a8d8 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -19,3 +19,69 @@ unknown_lints = "allow" # Prohibit code that is forbidden in Rust 2024 unsafe_op_in_unsafe_fn = "deny" + +[workspace.lints.rustdoc] +broken_intra_doc_links = "deny" +invalid_html_tags = "deny" +invalid_rust_codeblocks = "deny" +bare_urls = "deny" +unescaped_backticks = "deny" +redundant_explicit_links = "deny" + +[workspace.lints.clippy] +# default-warn lints +result_unit_err = "allow" +too_many_arguments = "allow" +upper_case_acronyms = "allow" + +# default-allow lints +as_ptr_cast_mut = "deny" +as_underscore = "deny" +assertions_on_result_states = "deny" +bool_to_int_with_if = "deny" +borrow_as_ptr = "deny" +cast_lossless = "deny" +dbg_macro = "deny" +debug_assert_with_mut_call = "deny" +derive_partial_eq_without_eq = "deny" +doc_markdown = "deny" +empty_structs_with_brackets = "deny" +ignored_unit_patterns = "deny" +implicit_clone = "deny" +macro_use_imports = "deny" +missing_const_for_fn = "deny" +missing_safety_doc = "deny" +multiple_crate_versions = "deny" +mut_mut = "deny" +needless_bitwise_bool = "deny" +needless_pass_by_ref_mut = "deny" +no_effect_underscore_binding = "deny" +option_option = "deny" +or_fun_call = "deny" +ptr_as_ptr = "deny" +ptr_cast_constness = "deny" +pub_underscore_fields = "deny" +redundant_clone = "deny" +redundant_closure_for_method_calls = "deny" +redundant_else = "deny" +redundant_pub_crate = "deny" +ref_binding_to_reference = "deny" +ref_option_ref = "deny" +return_self_not_must_use = "deny" +same_name_method = "deny" +semicolon_inside_block = "deny" +significant_drop_in_scrutinee = "deny" +significant_drop_tightening = "deny" +suspicious_operation_groupings = "deny" +transmute_ptr_to_ptr = "deny" +transmute_undefined_repr = "deny" +type_repetition_in_bounds = "deny" +unused_self = "deny" +used_underscore_binding = "deny" + +# nice to have, but cannot be enabled yet +#wildcard_imports = "deny" + +# these may have false positives +#option_if_let_else = "deny" +cognitive_complexity = "deny" diff --git a/rust/hw/char/pl011/src/lib.rs b/rust/hw/char/pl011/src/lib.rs index cd0a49acb91..3fa178cded0 100644 --- a/rust/hw/char/pl011/src/lib.rs +++ b/rust/hw/char/pl011/src/lib.rs @@ -14,28 +14,14 @@ //! the [`registers`] module for register types. #![deny( - rustdoc::broken_intra_doc_links, - rustdoc::redundant_explicit_links, clippy::correctness, clippy::suspicious, clippy::complexity, clippy::perf, clippy::cargo, clippy::nursery, - clippy::style, - // restriction group - clippy::dbg_macro, - clippy::as_underscore, - clippy::assertions_on_result_states, - // pedantic group - clippy::doc_markdown, - clippy::borrow_as_ptr, - clippy::cast_lossless, - clippy::option_if_let_else, - clippy::missing_const_for_fn, - clippy::cognitive_complexity, - clippy::missing_safety_doc, - )] + clippy::style +)] #![allow(clippy::result_unit_err)] extern crate bilge; diff --git a/rust/qemu-api/src/bindings.rs b/rust/qemu-api/src/bindings.rs index 1dac310594d..972b1f1ee90 100644 --- a/rust/qemu-api/src/bindings.rs +++ b/rust/qemu-api/src/bindings.rs @@ -7,10 +7,10 @@ non_snake_case, non_upper_case_globals, unsafe_op_in_unsafe_fn, + clippy::pedantic, + clippy::restriction, + clippy::style, clippy::missing_const_for_fn, - clippy::too_many_arguments, - clippy::approx_constant, - clippy::use_self, clippy::useless_transmute, clippy::missing_safety_doc )] From patchwork Fri Nov 8 18:01:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13868826 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 646A8D64074 for ; Fri, 8 Nov 2024 18:04:36 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t9TJI-000224-6z; Fri, 08 Nov 2024 13:02:16 -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 1t9TJE-0001wS-RI for qemu-devel@nongnu.org; Fri, 08 Nov 2024 13:02:13 -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 1t9TJB-0001xJ-65 for qemu-devel@nongnu.org; Fri, 08 Nov 2024 13:02:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1731088928; 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=yguWnQXG15f2x+f4QNRnXEOFJJORIkMpafNaeGv6vH0=; b=CqECri+hqeXvWkaICgd2V3sFrPZ2pxuon8uqa78nHxw4EM/UUIRKuVEQS1sRWLLTa0n61O rzAQt1HpD+D0HzqjumIalHo7LQOKABiBjpLvcxtEm6q42GWeqHU0RgcS0bf5mqBaZRcsnr +aLsoQtFCU6bF5HwXZZPIb2kWLx8Bo0= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-652-QdOMtPJ3NEuQr7td3br4jQ-1; Fri, 08 Nov 2024 13:02:07 -0500 X-MC-Unique: QdOMtPJ3NEuQr7td3br4jQ-1 X-Mimecast-MFC-AGG-ID: QdOMtPJ3NEuQr7td3br4jQ Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-43159603c92so16424105e9.2 for ; Fri, 08 Nov 2024 10:02:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731088926; x=1731693726; 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=yguWnQXG15f2x+f4QNRnXEOFJJORIkMpafNaeGv6vH0=; b=VC5Gahk84xYvcrUiB85QXD/GxPoOrzRvkxgR4IrIhoSlZASQ1/Ly/e5t2cHzYw9dRE G9rpYuaCascW6ncsUht7mwQcBQhD/tTEsEDDfaFYgDTg/7aoguJ00FQSfYe6ePTzTmIv 2ojeszryw4Ngh6cPcOQXtpKQ8fD9/vOfKUN0czVDtbBR2kW2Vne3tkfghLCiRqeamo2V gmEAWFkN1e/jqA4o4A5fMg6aC4UXSSgj9qBG+yMLH2srWayly1PWim+HT6YNaEAuLOwk rJXy5LSa7jkB3lAz+SFFk2aeVLigsviI0IOv7hMmaEXbkq5aL2LhK4EW6H2k2KtNJsdj Z+UA== X-Gm-Message-State: AOJu0YwH2KDldrQdErDzmczj3Qg48gFq0sY0L0A8h8jPF4j2bCG28P45 tDn0aiIRFNbf5KQvy1XVqoGowtghidOlafZQLlmwSrQmaIESHWCq/qnfebghSx0cr/kvovvTrz1 V8aJxuBAatulOr2ynJDtTR07jxtKAeORs+qXMpMe2vcKW3YiPRHnzaZL5O77atjmOtRXzaB+ZZw 2FBJEjmDdnh2lpT4VU3hcoP2DsYGosQePFW2TW1+E= X-Received: by 2002:a05:6000:1869:b0:381:f0ce:d09e with SMTP id ffacd0b85a97d-381f18635f4mr3179841f8f.7.1731088925924; Fri, 08 Nov 2024 10:02:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IHI1VHnlt4sb0wupEKO0ihKDfs7+WzKbqgIge8H1VNg5+78Gte/1/HoI29L4264/OuICIyW1A== X-Received: by 2002:a05:6000:1869:b0:381:f0ce:d09e with SMTP id ffacd0b85a97d-381f18635f4mr3179788f8f.7.1731088925418; Fri, 08 Nov 2024 10:02:05 -0800 (PST) Received: from [192.168.10.47] ([151.49.84.243]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-381ed99a34bsm5458399f8f.54.2024.11.08.10.02.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Nov 2024 10:02:05 -0800 (PST) From: Paolo Bonzini 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 09/11] rust: build: add "make clippy", "make rustfmt" Date: Fri, 8 Nov 2024 19:01:37 +0100 Message-ID: <20241108180139.117112-10-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241108180139.117112-1-pbonzini@redhat.com> References: <20241108180139.117112-1-pbonzini@redhat.com> MIME-Version: 1.0 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: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, 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_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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Abstract common invocations of "cargo", that do not require copying the generated bindgen file or setting up MESON_BUILD_ROOT. In the future these could also do completely without cargo and invoke the underlying programs directly. Signed-off-by: Paolo Bonzini --- rust/meson.build | 14 ++++++++++++++ rust/qemu-api/build.rs | 8 ++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/rust/meson.build b/rust/meson.build index def77389cdd..6fa0fd54527 100644 --- a/rust/meson.build +++ b/rust/meson.build @@ -2,3 +2,17 @@ subdir('qemu-api-macros') subdir('qemu-api') subdir('hw') + +cargo = find_program('cargo') + +run_target('clippy', + command: [config_host['MESON'], 'devenv', + '--workdir', '@CURRENT_SOURCE_DIR@', + cargo, 'clippy', '--tests'], + depends: bindings_rs) + +run_target('rustfmt', + command: [config_host['MESON'], 'devenv', + '--workdir', '@CURRENT_SOURCE_DIR@', + cargo, 'fmt'], + depends: bindings_rs) diff --git a/rust/qemu-api/build.rs b/rust/qemu-api/build.rs index e4eab718553..d7b6d76828b 100644 --- a/rust/qemu-api/build.rs +++ b/rust/qemu-api/build.rs @@ -15,8 +15,12 @@ fn main() { let file = format!("{}/bindings.rs.inc", path); if !Path::new(&file).exists() { panic!(concat!( - "No generated C bindings found! If you want to run `cargo`, start a subshell\n", - "with `meson devenv`, or point MESON_BUILD_ROOT to the top of the build tree." + "\n", + " No generated C bindings found! To run clippy or rustfmt, you can use\n", + " `make clippy` or `make rustfmt`.\n", + "\n", + " For other uses of `cargo`, start a subshell with `meson devenv`, or\n", + " point MESON_BUILD_ROOT to the top of the build tree." )); } From patchwork Fri Nov 8 18:01:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13868819 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 182BED64074 for ; Fri, 8 Nov 2024 18:03:21 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t9TJN-00028f-Eq; Fri, 08 Nov 2024 13:02:21 -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 1t9TJG-0001yC-Gu for qemu-devel@nongnu.org; Fri, 08 Nov 2024 13:02:14 -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 1t9TJE-0001xW-Ka for qemu-devel@nongnu.org; Fri, 08 Nov 2024 13:02:14 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1731088930; 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=Hz7vl/ta7wDz7MWKeB1ZugqNvFL2k59T4+vboRZ4+nc=; b=SvkWkm6cQMlfDdxokW6spIJ+RzM5jiLSDKBRbre09MyEpXA5KZZ7A/giGigsEJb3RFGjQ0 ejNG5lCjOCKMHJVE6gikPiHjeCAGOctwQGjsw5pJRI5mWS/9a+hAJop/lnfaqftLbAKvng QGM2YfZMvn9OVqRolwFaB11AGBiXv9A= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-690-kECcr5GJM7ePn3Pr94tGgw-1; Fri, 08 Nov 2024 13:02:09 -0500 X-MC-Unique: kECcr5GJM7ePn3Pr94tGgw-1 X-Mimecast-MFC-AGG-ID: kECcr5GJM7ePn3Pr94tGgw Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4315af466d9so16410575e9.3 for ; Fri, 08 Nov 2024 10:02:09 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731088928; x=1731693728; 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=Hz7vl/ta7wDz7MWKeB1ZugqNvFL2k59T4+vboRZ4+nc=; b=XOJZ6T5xmLZsnZm3rMrZe4KfCC8RX8va5seFVPcC0+v0sP/cW/w8RLLcMtBIu0hc9b 1a0GbgzmQnNKD/7cZYgBMMHCskUbdDkRInyTGDVAYcSfE7Seu2yiXcpPM5rsyFoVYa3l S5u0BTC0UDRbQ7r53/u4Yc02EE2bhbkcOScho55ZekjH5gb89QF7QfgJoIGoxr0pSTtZ 9iup1LdBBwuxk4BYmFbzcz/VmN6ZbaohVG5DMr25cVleXcM2XnqdNMKhTDEAuQ81695L +CvqoQDL1b8DP1H3lfFMYxiFXfr/WcwDDzXvXTvadlOPQd77AOIjtIXTFMN0WqOVFSbT imNw== X-Gm-Message-State: AOJu0YyjZDerlgQIRs3kUnS1EDNIDFeoVkXWH+dSB5jupkcTQ6bOYY0u Qdrs29gv+VpqNlv+bZ28CHN06DJt2fGkPUQSVKgn33sN+CL5RQl5Rqh1Q6Yuy9VEc2wEGcPyNaR pwjyMUACHXAZQn/4lsBwde+SnG4I5Iai+uoWLa407mAQBPDJ77dDl9pE9SAttqlhUzuctNcLqar JX4Pk9kN5LXU+c9cGGUedtNO5v+MSVXpHHCLXjsLg= X-Received: by 2002:a05:600c:4f83:b0:42a:a6d2:3270 with SMTP id 5b1f17b1804b1-432b7517aa4mr30347085e9.21.1731088927894; Fri, 08 Nov 2024 10:02:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IFhgB0HgK/Kfy8Dc2UtI0nUDMgVvzXK7o0cV9tPZ48JounXGUUudIS5GShYGA0zbj9l50H0QA== X-Received: by 2002:a05:600c:4f83:b0:42a:a6d2:3270 with SMTP id 5b1f17b1804b1-432b7517aa4mr30346575e9.21.1731088927412; Fri, 08 Nov 2024 10:02:07 -0800 (PST) Received: from [192.168.10.47] ([151.49.84.243]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-432aa6b35b3sm109272695e9.18.2024.11.08.10.02.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Nov 2024 10:02:06 -0800 (PST) From: Paolo Bonzini 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 10/11] rust: fix doc test syntax Date: Fri, 8 Nov 2024 19:01:38 +0100 Message-ID: <20241108180139.117112-11-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241108180139.117112-1-pbonzini@redhat.com> References: <20241108180139.117112-1-pbonzini@redhat.com> MIME-Version: 1.0 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: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, 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_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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Allow "cargo test --doc" to pass. Signed-off-by: Paolo Bonzini --- rust/qemu-api/src/zeroable.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rust/qemu-api/src/zeroable.rs b/rust/qemu-api/src/zeroable.rs index 13cdb2ccba5..6125aeed8b4 100644 --- a/rust/qemu-api/src/zeroable.rs +++ b/rust/qemu-api/src/zeroable.rs @@ -7,9 +7,9 @@ /// behavior. This trait in principle could be implemented as just: /// /// ``` -/// const ZERO: Self = unsafe { -/// ::core::mem::MaybeUninit::<$crate::bindings::Property>::zeroed().assume_init() -/// }, +/// pub unsafe trait Zeroable: Default { +/// const ZERO: Self = unsafe { ::core::mem::MaybeUninit::::zeroed().assume_init() }; +/// } /// ``` /// /// The need for a manual implementation is only because `zeroed()` cannot From patchwork Fri Nov 8 18:01:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13868830 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9C9A8D64074 for ; Fri, 8 Nov 2024 18:05:06 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t9TJO-00029E-Ff; Fri, 08 Nov 2024 13:02:22 -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 1t9TJJ-00023a-9d for qemu-devel@nongnu.org; Fri, 08 Nov 2024 13:02:17 -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 1t9TJH-0001xs-MF for qemu-devel@nongnu.org; Fri, 08 Nov 2024 13:02:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1731088933; 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=uynPjKqvjPdBbc/TZoxPs1tE8K2Uir/0YKLh2NR6k6I=; b=E6wwbHqqqWbDD/OxyZfBXjVcPO8RUucALaLNvgt/JmP6iefMwzqul8uu3+aqs3M3aXE71/ gvopVav94J4+jwdXrq6XBx3CecOvU+04SV1l+dpfip1VZ+1535reNv33dky6FiBPrrgeLG ZHCCdTH5lU4hZPwAefL7gsmxD6ma5qE= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-94-5JU1HG3bNwyf9NtS4I212w-1; Fri, 08 Nov 2024 13:02:12 -0500 X-MC-Unique: 5JU1HG3bNwyf9NtS4I212w-1 X-Mimecast-MFC-AGG-ID: 5JU1HG3bNwyf9NtS4I212w Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-37d49887a2cso1334385f8f.0 for ; Fri, 08 Nov 2024 10:02:12 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731088930; x=1731693730; 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=uynPjKqvjPdBbc/TZoxPs1tE8K2Uir/0YKLh2NR6k6I=; b=AqtOTGbEsOF6Vq1JYkyUhT94MAnh/UOLwfqomiTjvoGJ8g81bd2em1i+imEIDSQPNx cZzENzLylOdIkm7wEzaoZTvXSmWmiWkXARtV84jszczCsxVhNW4LipZ+F/lASxSe+yuI 0MzRudnv3btsBb09y63cS/CR3xWDlEXbq6t7IKGo+Sya51XEcHB1GXFpRoIVYqCLeFo6 Tuyok6RSOklcnvZMTymtKHtE/JXZMHOrX3376/Qp8fLwksD+0Hps3bpU8WHuLqk6+lpA cbqnLUy2oya1u5vGVtg2LRV6PFyUsC0rA6FSe7CFePXsT3mKfOcOHA2vjxtb0sBPc5uC wGrg== X-Gm-Message-State: AOJu0YxTAyV7+S/bVODHtEmjYGBSytj5WY940OHNWVyzGKoE74+MYQ45 /HG5YkqCgBt/DcdT83B1i6iJnjodYULFOwnaHIlALf0plgUFSGTQpLan9Mi/up8wYwZ1JpXvK3S hJyQMkSouonAMNPtthos/agL+ojDX1s4HhAY+0UQfvORE1aWAjJh83kuP39mpdiKDwQcbpZ31GE h4E5jrlPwJteMdcXsqXFpY/My/+zr3j6Yvfi2mM9c= X-Received: by 2002:a5d:64a1:0:b0:37d:460d:2d07 with SMTP id ffacd0b85a97d-381f0f5849amr4484979f8f.10.1731088930406; Fri, 08 Nov 2024 10:02:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IHsZ4wZZY5P6H1a5W18sCQR59R0+5Giwiagz0mJ7cx4Pisoaa2JQ90AMCbQmi5qvooHA0scmg== X-Received: by 2002:a5d:64a1:0:b0:37d:460d:2d07 with SMTP id ffacd0b85a97d-381f0f5849amr4484918f8f.10.1731088929917; Fri, 08 Nov 2024 10:02:09 -0800 (PST) Received: from [192.168.10.47] ([151.49.84.243]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-432b05e5f77sm79887345e9.43.2024.11.08.10.02.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Nov 2024 10:02:08 -0800 (PST) From: Paolo Bonzini 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 11/11] rust: ci: add job that runs Rust tools Date: Fri, 8 Nov 2024 19:01:39 +0100 Message-ID: <20241108180139.117112-12-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241108180139.117112-1-pbonzini@redhat.com> References: <20241108180139.117112-1-pbonzini@redhat.com> MIME-Version: 1.0 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: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, 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_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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Code checks, as well as documentation generation, are not yet tied to "make check" because they need new version of the Rust toolchain (even nightly in the case of "rustfmt"). Run them in CI using the existing nightly-Rust container. Signed-off-by: Paolo Bonzini --- .gitlab-ci.d/buildtest-template.yml | 14 ++++++++++++++ .gitlab-ci.d/buildtest.yml | 14 ++++++++++++++ .../docker/dockerfiles/fedora-rust-nightly.docker | 4 ++++ tests/lcitool/refresh | 4 ++++ 4 files changed, 36 insertions(+) diff --git a/.gitlab-ci.d/buildtest-template.yml b/.gitlab-ci.d/buildtest-template.yml index 39da7698b09..612e968ff19 100644 --- a/.gitlab-ci.d/buildtest-template.yml +++ b/.gitlab-ci.d/buildtest-template.yml @@ -79,6 +79,20 @@ - $MAKE NINJA=":" $MAKE_CHECK_ARGS - section_end test +.rust_test_job_template: + extends: .base_job_template + stage: test + image: $CI_REGISTRY_IMAGE/qemu/$IMAGE:$QEMU_CI_CONTAINER_TAG + script: + - source scripts/ci/gitlab-ci-section + - section_start test "Running Rust code checks" + - cd build + - pyvenv/bin/meson devenv -w ../rust ${CARGO-cargo} fmt --check + - make clippy + - pyvenv/bin/meson devenv -w ../rust ${CARGO-cargo} doc --no-deps + - pyvenv/bin/meson devenv -w ../rust ${CARGO-cargo} test --doc + - section_end test + .native_test_job_template: extends: .common_test_job_template artifacts: diff --git a/.gitlab-ci.d/buildtest.yml b/.gitlab-ci.d/buildtest.yml index 336223484d8..5250b61f089 100644 --- a/.gitlab-ci.d/buildtest.yml +++ b/.gitlab-ci.d/buildtest.yml @@ -142,6 +142,20 @@ check-system-fedora: IMAGE: fedora MAKE_CHECK_ARGS: check +check-rust-fedora-rust-nightly: + extends: .rust_test_job_template + needs: + - job: build-system-fedora-rust-nightly + artifacts: true + variables: + IMAGE: fedora-rust-nightly + MAKE_CHECK_ARGS: check + artifacts: + when: on_success + expire_in: 2 days + paths: + - rust/target/doc + functional-system-fedora: extends: .functional_test_job_template needs: diff --git a/tests/docker/dockerfiles/fedora-rust-nightly.docker b/tests/docker/dockerfiles/fedora-rust-nightly.docker index 9180c8b5222..a8e4fb279a7 100644 --- a/tests/docker/dockerfiles/fedora-rust-nightly.docker +++ b/tests/docker/dockerfiles/fedora-rust-nightly.docker @@ -155,6 +155,7 @@ ENV PYTHON "/usr/bin/python3" RUN dnf install -y wget ENV RUSTUP_HOME=/usr/local/rustup CARGO_HOME=/usr/local/cargo ENV RUSTC=/usr/local/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc +ENV CARGO=/usr/local/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/cargo RUN set -eux && \ rustArch='x86_64-unknown-linux-gnu' && \ rustupSha256='6aeece6993e902708983b209d04c0d1dbb14ebb405ddb87def578d41f920f56d' && \ @@ -165,10 +166,13 @@ RUN set -eux && \ ./rustup-init -y --no-modify-path --profile default --default-toolchain nightly --default-host ${rustArch} && \ chmod -R a+w $RUSTUP_HOME $CARGO_HOME && \ /usr/local/cargo/bin/rustup --version && \ + /usr/local/cargo/bin/rustup run nightly cargo --version && \ /usr/local/cargo/bin/rustup run nightly rustc --version && \ + test "$CARGO" = "$(/usr/local/cargo/bin/rustup +nightly which cargo)" && \ test "$RUSTC" = "$(/usr/local/cargo/bin/rustup +nightly which rustc)" ENV PATH=$CARGO_HOME/bin:$PATH RUN /usr/local/cargo/bin/rustup run nightly cargo install bindgen-cli +RUN $CARGO --list # As a final step configure the user (if env is defined) ARG USER ARG UID diff --git a/tests/lcitool/refresh b/tests/lcitool/refresh index 51012783c0f..6720516b942 100755 --- a/tests/lcitool/refresh +++ b/tests/lcitool/refresh @@ -121,6 +121,7 @@ fedora_rustup_nightly_extras = [ "RUN dnf install -y wget\n", "ENV RUSTUP_HOME=/usr/local/rustup CARGO_HOME=/usr/local/cargo\n", "ENV RUSTC=/usr/local/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc\n", + "ENV CARGO=/usr/local/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/cargo\n", "RUN set -eux && \\\n", " rustArch='x86_64-unknown-linux-gnu' && \\\n", " rustupSha256='6aeece6993e902708983b209d04c0d1dbb14ebb405ddb87def578d41f920f56d' && \\\n", @@ -131,10 +132,13 @@ fedora_rustup_nightly_extras = [ " ./rustup-init -y --no-modify-path --profile default --default-toolchain nightly --default-host ${rustArch} && \\\n", " chmod -R a+w $RUSTUP_HOME $CARGO_HOME && \\\n", " /usr/local/cargo/bin/rustup --version && \\\n", + " /usr/local/cargo/bin/rustup run nightly cargo --version && \\\n", " /usr/local/cargo/bin/rustup run nightly rustc --version && \\\n", + ' test "$CARGO" = "$(/usr/local/cargo/bin/rustup +nightly which cargo)" && \\\n', ' test "$RUSTC" = "$(/usr/local/cargo/bin/rustup +nightly which rustc)"\n', 'ENV PATH=$CARGO_HOME/bin:$PATH\n', 'RUN /usr/local/cargo/bin/rustup run nightly cargo install bindgen-cli\n', + 'RUN $CARGO --list\n', ] ubuntu2204_bindgen_extras = [