From nobody Sat Nov 23 19:21:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1731089097; cv=none; d=zohomail.com; s=zohoarc; b=Lj3/0xAI4a8WqjcevLBZ3me2L+nq+kPgbYurZdTxxe6pXd0MepbA69AsD8ZweLNuTeGha5iIhSZ59it09r11Aw37spdxwxWwRck2Fr8lYyWmIjnaHD6YN2mc2gWphWPFzKvRWunUgzmpLAhk7CGGb7QzPpukoOeGc1GvQUBRI1I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1731089097; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=yfF+e4p7LcLCc9fG9LqtNbaVzXuoaKz8W1PB4KLYI+g=; b=cT5FWETy/uStgt5xeL95opL506FI9Cd8p/lVDG91gygdNlJqqB92iboqg1qbUB6nijaLnL4bKC/3th/KiiDb2LSjgYqN25+AGzb7oWTyGcxWSsc1LiJC9kqnDXJdd+q6z6/I6zg25i6iIrLqgoHWvIwyPUAB2/tuebSnYPUPMsU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 173108909700649.43822232629611; Fri, 8 Nov 2024 10:04:57 -0800 (PST) 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 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 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-43157e3521dso16470465e9.1 for ; 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 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) 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= X-MC-Unique: QKgX2lYNMjCjPJtPeFRVbw-1 X-Mimecast-MFC-AGG-ID: QKgX2lYNMjCjPJtPeFRVbw 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1731089099136116600 Content-Type: text/plain; charset="utf-8" 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: '>=3D1.5.0', 'b_staticpic=3Dfalse', 'stdsplit=3Dfalse', 'opti= mization=3D2', 'b_pie=3Dtrue'], version: files('VERSION')) =20 +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=3D= 1', 'SPEED=3Dslow']) add_test_setup('thorough', env: ['G_TEST_SLOW=3D1', 'SPEED=3Dthorough']) @@ -4089,7 +4091,7 @@ if have_rust bindings_rs =3D 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: ['>=3D0.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 =20 -use std::path::Path; +use std::{env, path::Path}; =20 use version_check as rustc; =20 fn main() { - if !Path::new("src/bindings.rs").exists() { - panic!( - "No generated C bindings found! Either build them manually wit= h bindgen or with meson \ - (`ninja bindings.rs`) and copy them to src/bindings.rs, or bu= ild through meson." - ); + // Placing bindings.rs.inc in the source directory is supported + // but not documented or encouraged. + let path =3D env::var("MESON_BUILD_ROOT") + .unwrap_or_else(|_| format!("{}/src", env!("CARGO_MANIFEST_DIR"))); + + let file =3D format!("{}/bindings.rs.inc", path); + if !Path::new(&file).exists() { + panic!(concat!( + "No generated C bindings found! If you want to run `cargo`, st= art a subshell\n", + "with `meson devenv`, or point MESON_BUILD_ROOT to the top of = the build tree." + )); } =20 + println!("cargo:rustc-env=3DBINDINGS_RS_INC=3D{}", file); + // Check for available rustc features if rustc::is_min_version("1.77.0").unwrap_or(false) { println!("cargo:rustc-cfg=3Dhas_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 =3D 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 @@ =20 #![cfg_attr(not(MESON), doc =3D include_str!("../README.md"))] =20 -#[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; =20 -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; --=20 2.47.0 From nobody Sat Nov 23 19:21:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1731089058; cv=none; d=zohomail.com; s=zohoarc; b=D3DR290aBOqxL7J5JOjSVRlKJX/qRx7dEQdutmbT79J6Oddcr2BqxceaetCm9ISm5X3B17VtgX/NcjrzRXPAmHerUQXwxe7PNb2C4+gap+x89jgtIYQufFB7a8Y60C1Quf6RkYKwqL683m3eo0gtGvBRXa9yd9tf5dF2DIn5pY4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1731089058; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=eX7uUTJtFkCsP2+rTSsbiyuX9JxoUOb2ob7tcl3vQYY=; b=B3EKQbTTz7DJyG78uO933pHU6zjMGcJj1R8caN6OR29NTRUdrSGj9wCGMrY44jgwfcMZIZDjktSNOL1idsGBjmHYEAtO8ZdZeqxuQjtrUeNEnRTRPdSW/JK6sBgx42xseh1GE8xWtbTR9exIdFJvqve96Q40IewdYikEAzCW9gk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1731089058880454.8586039680033; Fri, 8 Nov 2024 10:04:18 -0800 (PST) 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 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 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4315afcae6cso14195875e9.0 for ; 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-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) 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= X-MC-Unique: espbQXhHPrKlaL6u3Bwkzg-1 X-Mimecast-MFC-AGG-ID: espbQXhHPrKlaL6u3Bwkzg 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1731089061021116600 Content-Type: text/plain; charset="utf-8" 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 =20 if have_rust + rustc_args =3D find_program('scripts/rust/rustc_args.py') rustfmt =3D find_program('rustfmt', required: false) + + # Prohibit code that is forbidden in Rust 2024 + rustc_lint_args =3D ['-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 =3D=3D true ensures that + # we do not have misspelled allow() attributes. + if not get_option('strict_rust_lints') + rustc_lint_args +=3D ['-A', 'unknown_lints'] + endif + + # Apart from procedural macros, our Rust executables will often link + # with C code, so include all the libraries that C code needs. This + # is safe; https://github.com/rust-lang/rust/pull/54675 says that + # 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 =20 dtrace =3D not_found @@ -3399,36 +3421,8 @@ endif # Generated sources # ##################### =20 -genh +=3D configure_file(output: 'config-host.h', configuration: config_ho= st_data) - -if have_rust - rustc_args =3D 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 +=3D ['-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 =3D=3D true ensures that - # we do not have misspelled allow() attributes. - if not get_option('strict_rust_lints') - rustc_args +=3D ['-A', 'unknown_lints'] - endif - - # Apart from procedural macros, our Rust executables will often link - # with C code, so include all the libraries that C code needs. This - # is safe; https://github.com/rust-lang/rust/pull/54675 says that - # 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 =3D configure_file(output: 'config-host.h', configuration: c= onfig_host_data) +genh +=3D config_host_h =20 hxtool =3D find_program('scripts/hxtool') shaderinclude =3D 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('>=3D1.77.0') _qemu_api_cfg +=3D ['--cfg', 'has_offset_of'] endif =20 +_qemu_api_cfg +=3D run_command(rustc_args, + '--config-headers', config_host_h, + capture: true, check: true).stdout().strip().split() + _qemu_api_rs =3D static_library( 'qemu_api', structured_sources( --=20 2.47.0 From nobody Sat Nov 23 19:21:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1731089042; cv=none; d=zohomail.com; s=zohoarc; b=PW9hL7IM3rtl3KhE4A7OfoPuZYgWmk0Odrn5OQWJFC6zni0eIZ+LpOxVTxnVX25XTO08tS/K98ODOb6vGLrcYwrESTpCS9FJ+ZPHTY8vCZ15rtYQClI55vsQWBqO+dLW2N2iWUYMbUaAHb1/kCp2kpeIYP4I4tUjZtZ/GLrJxL8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1731089042; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=NtlWVHUs02V1J7NuepxEhAY1b+bPSGqGN7MAC+hr2Y4=; b=COSTrbUfdpunw+MTgOqhyFTpzNBjZIU9cEFUmK5iDe64rSCbjlHjrLOw1Tufwlg4LGUQgdYs5G+FZy3CYlLV2yOFoYT6lS3zqYHeP8DsiocjppXs42NfDf8/UGmG1F+9hR3UJXwsQnh0V6NR5OYGivro04YlwcsAOLmvzc2Bj9E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1731089042757945.018954030166; Fri, 8 Nov 2024 10:04:02 -0800 (PST) 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 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 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-431673032e6so15596495e9.0 for ; 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 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) 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= X-MC-Unique: Lu1_ClCbPJyiNsdfw2aoRw-1 X-Mimecast-MFC-AGG-ID: Lu1_ClCbPJyiNsdfw2aoRw 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1731089044832116600 Content-Type: text/plain; charset="utf-8" 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('>=3D1.77.0') endif =20 _qemu_api_cfg +=3D run_command(rustc_args, - '--config-headers', config_host_h, + '--config-headers', config_host_h, files('Cargo.toml'), capture: true, check: true).stdout().strip().split() =20 _qemu_api_rs =3D 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 @@ =20 import argparse import logging +from pathlib import Path +from typing import Any, Iterable, Mapping, Optional, Set =20 -from typing import List +try: + import tomllib +except ImportError: + import tomli as tomllib =20 =20 -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 =3D tomllib.load(f) + + self.check_cfg =3D set(self.find_check_cfg()) + + def find_check_cfg(self) -> Iterable[str]: + toml_lints =3D self.lints + rust_lints =3D toml_lints.get("rust", {}) + cfg_lint =3D 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 =3D 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.""" =20 - 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=3D"utf-8") as cfg: config =3D [l.split()[1:] for l in cfg if l.startswith("#define")] =20 cfg_list =3D [] for cfg in config: - name =3D cfg_name(cfg[0]) - if not name: + name =3D cfg[0] + if f'cfg({name})' not in cargo_toml.check_cfg: continue if len(cfg) >=3D 2 and cfg[1] !=3D "1": continue @@ -59,7 +80,6 @@ def cfg_name(name: str) -> str: =20 =20 def main() -> None: - # pylint: disable=3Dmissing-function-docstring parser =3D argparse.ArgumentParser() parser.add_argument("-v", "--verbose", action=3D"store_true") parser.add_argument( @@ -71,12 +91,21 @@ def main() -> None: required=3DFalse, default=3D[], ) + parser.add_argument( + metavar=3D"TOML_FILE", + action=3D"store", + dest=3D"cargo_toml", + help=3D"path to Cargo.toml file", + ) args =3D parser.parse_args() if args.verbose: logging.basicConfig(level=3Dlogging.DEBUG) logging.debug("args: %s", args) + + cargo_toml =3D 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) =20 =20 --=20 2.47.0 From nobody Sat Nov 23 19:21:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1731089104; cv=none; d=zohomail.com; s=zohoarc; b=J3IJ4yqS2lE0mYdbNo6igXs/27ZXH2+NyyooMjeZp1lBzxBfDgPr4xmYc29nqmd9u6HcpINteBkn+lkEM/gYUVI1LLc1PzEw2QbukHi4PvmXwipAZD39SRd6TLqFB+YsfbbgPPWDt5zFHVkTf/QJqirDBgPtn/s0VVtIOKQdyF0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1731089104; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=i9F6HrT6yGM1H4hD8DpIdP6B53mjE1AzSwSbMGZrK5g=; b=Qy6S7xK4b1w5BIReWe8HBuHAHcY/YbXvdmSWTq0BvJTijcqHZOZ1i4zr97UU7lcMa3LvFhI4terPIpFK+OnWV0DWq8Uyeq3WL1vjD54hXgyz2PcGjDYPcwpgQZdNxAxCQSTnU+MwmpBcSLioOr1xRao0BBjByEeM19r23N1EliA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1731089104342326.3342259622003; Fri, 8 Nov 2024 10:05:04 -0800 (PST) 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 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 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-37d5ca192b8so1416147f8f.1 for ; Fri, 08 Nov 2024 10:01:56 -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) 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= X-MC-Unique: w3FSyBS0NNmqzDJBzOx9_w-1 X-Mimecast-MFC-AGG-ID: w3FSyBS0NNmqzDJBzOx9_w 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1731089105129116600 Content-Type: text/plain; charset="utf-8" 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('>=3D1.77.0') endif =20 _qemu_api_cfg +=3D 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() =20 _qemu_api_rs =3D 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 @@ """ =20 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 =20 try: import tomllib @@ -61,6 +62,45 @@ def get_table(self, key: str) -> Mapping[Any, Any]: return table =20 =20 +@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 =3D cargo_toml.lints + + lint_list =3D [] + for k, v in toml_lints.items(): + prefix =3D "" if k =3D=3D "rust" else k + "::" + for lint, data in v.items(): + level =3D data if isinstance(data, str) else data["level"] + priority =3D 0 if isinstance(data, str) else data.get("priorit= y", 0) + if level =3D=3D "deny": + flag =3D "-D" + elif level =3D=3D "allow": + flag =3D "-A" + elif level =3D=3D "warn": + flag =3D "-W" + elif level =3D=3D "forbid": + flag =3D "-F" + else: + raise Exception(f"invalid level {level} for {prefix}{lint}= ") + + # This may change if QEMU ever invokes clippy-driver or rustdo= c by + # hand. For now, check the syntax but do not add non-rustc li= nts to + # the command line. + if k =3D=3D "rust": + lint_list.append(LintFlag(flags=3D[flag, prefix + lint], p= riority=3Dpriority)) + + lint_list.sort(key=3Dlambda 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.""" =20 @@ -97,13 +137,54 @@ def main() -> None: dest=3D"cargo_toml", help=3D"path to Cargo.toml file", ) + parser.add_argument( + "--features", + action=3D"store_true", + dest=3D"features", + help=3D"generate --check-cfg arguments for features", + required=3DFalse, + default=3DNone, + ) + parser.add_argument( + "--lints", + action=3D"store_true", + dest=3D"lints", + help=3D"generate arguments from [lints] table", + required=3DFalse, + default=3DNone, + ) + parser.add_argument( + "--rustc-version", + metavar=3D"VERSION", + dest=3D"rustc_version", + action=3D"store", + help=3D"version of rustc", + required=3DFalse, + default=3D"1.0.0", + ) args =3D parser.parse_args() if args.verbose: logging.basicConfig(level=3Dlogging.DEBUG) logging.debug("args: %s", args) =20 + rustc_version =3D tuple((int(x) for x in args.rustc_version.split('.')= [0:2])) cargo_toml =3D CargoTOML(args.cargo_toml) =20 + if args.lints: + for tok in generate_lint_flags(cargo_toml): + print(tok) + + if rustc_version >=3D (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 !=3D "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) --=20 2.47.0 From nobody Sat Nov 23 19:21:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1731089041; cv=none; d=zohomail.com; s=zohoarc; b=ByalPI4eh9XFOFq1K1CsXJahMxEYPlpvfNwD80EtLpw/797bjp8Oij4Zf65tXAsuRrrZ0ikaACsGeo+ETzJ8ofzY0lygDLVvB9464hZm2UvzXXKkxXuFojm6cuQj0ySwiAvuuydr+8znzEpedyCglK0F7SPrlqVlqH0cRnwpM4Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1731089041; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=fxhgCHPLQNWjm3q9UX6Y4fEbkNDm7Az8YB8FU2F2Ov0=; b=e8/ymBYYV/v6p2IpvYnlo68wlelnNRY2U4xY6AhLNh/qDWWftCh5grNpIUOvpo33YkXOgVMIVRJ1MLwjcl1AKA6jYpBcrxFtiFueYK/uuOF/ZOn27HKfj1ES3a9D/HN3Rr0VZLhuftecB/UC3ghHV0496gygLHWzfvfREi0Fuos= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1731089041257907.9444475314604; Fri, 8 Nov 2024 10:04:01 -0800 (PST) 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 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 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-43164f21063so15475645e9.2 for ; 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-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) 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= X-MC-Unique: ZGifC13FNsulRPECXw_6pw-1 X-Mimecast-MFC-AGG-ID: ZGifC13FNsulRPECXw_6pw 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1731089042855116600 Content-Type: text/plain; charset="utf-8" An extra benefit of workspaces is that they allow to place lint level settings in a single Cargo.toml; the settings are then inherited by packages in the workspace. Correspondingly, teach rustc_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 =20 if have_rust - rustc_args =3D find_program('scripts/rust/rustc_args.py') + rustc_args =3D [find_program('scripts/rust/rustc_args.py'), + '--workspace', meson.project_source_root() / 'rust'] rustfmt =3D find_program('rustfmt', required: false) =20 - # Prohibit code that is forbidden in Rust 2024 - rustc_lint_args =3D ['-D', 'unsafe_op_in_unsafe_fn'] + rustc_lint_args =3D run_command(rustc_args, + '--lints', files('rust/Cargo.toml'), + capture: true, check: true).stdout().strip().splitlines() =20 # Occasionally, we may need to silence warnings and clippy lints that # were only introduced in newer Rust compiler versions. Do not croak diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 0c94d5037da..0230b92a9fa 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -5,3 +5,11 @@ members =3D [ "qemu-api", "hw/char/pl011", ] + +[workspace.lints.rust] +unexpected_cfgs =3D { level =3D "warn", check-cfg =3D [ + 'cfg(MESON)', 'cfg(HAVE_GLIB_WITH_ALIGNED_ALLOC)', + 'cfg(has_offset_of)'] } + +# Prohibit code that is forbidden in Rust 2024 +unsafe_op_in_unsafe_fn =3D "deny" diff --git a/rust/hw/char/pl011/Cargo.toml b/rust/hw/char/pl011/Cargo.toml index a373906b9fb..58f3e859f7e 100644 --- a/rust/hw/char/pl011/Cargo.toml +++ b/rust/hw/char/pl011/Cargo.toml @@ -21,3 +21,6 @@ bilge =3D { version =3D "0.2.0" } bilge-impl =3D { version =3D "0.2.0" } qemu_api =3D { path =3D "../../../qemu-api" } qemu_api_macros =3D { path =3D "../../../qemu-api-macros" } + +[lints] +workspace =3D true diff --git a/rust/qemu-api-macros/Cargo.toml b/rust/qemu-api-macros/Cargo.t= oml index a8f7377106b..5a27b52ee6e 100644 --- a/rust/qemu-api-macros/Cargo.toml +++ b/rust/qemu-api-macros/Cargo.toml @@ -20,3 +20,6 @@ proc-macro =3D true proc-macro2 =3D "1" quote =3D "1" syn =3D { version =3D "2", features =3D ["extra-traits"] } + +[lints] +workspace =3D true diff --git a/rust/qemu-api/Cargo.toml b/rust/qemu-api/Cargo.toml index cc716d75d46..669f288d1cb 100644 --- a/rust/qemu-api/Cargo.toml +++ b/rust/qemu-api/Cargo.toml @@ -23,6 +23,5 @@ version_check =3D "~0.9" default =3D [] allocator =3D [] =20 -[lints.rust] -unexpected_cfgs =3D { level =3D "warn", check-cfg =3D ['cfg(MESON)', 'cfg(= HAVE_GLIB_WITH_ALIGNED_ALLOC)', - 'cfg(has_offset_of)'] } +[lints] +workspace =3D true diff --git a/rust/qemu-api/meson.build b/rust/qemu-api/meson.build index 4ba5607d66b..8013911a348 100644 --- a/rust/qemu-api/meson.build +++ b/rust/qemu-api/meson.build @@ -5,7 +5,7 @@ if rustc.version().version_compare('>=3D1.77.0') endif =20 _qemu_api_cfg +=3D run_command(rustc_args, - '--config-headers', config_host_h, '--features', '--lints', files('Cargo= .toml'), + '--config-headers', config_host_h, '--features', files('Cargo.toml'), capture: true, check: true).stdout().strip().splitlines() =20 _qemu_api_rs =3D 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 @@ =20 class CargoTOML: tomldata: Mapping[Any, Any] + workspace_data: Mapping[Any, Any] check_cfg: Set[str] =20 - def __init__(self, path: str): + def __init__(self, path: str, workspace: Optional[str]): with open(path, 'rb') as f: self.tomldata =3D tomllib.load(f) =20 + if workspace is not None: + with open(workspace, 'rb') as f: + self.workspace_data =3D tomllib.load(f) + if "workspace" not in self.workspace_data: + self.workspace_data["workspace"] =3D {} + self.check_cfg =3D set(self.find_check_cfg()) =20 def find_check_cfg(self) -> Iterable[str]: @@ -54,10 +61,12 @@ def find_check_cfg(self) -> Iterable[str]: =20 @property def lints(self) -> Mapping[Any, Any]: - return self.get_table("lints") + return self.get_table("lints", True) =20 - def get_table(self, key: str) -> Mapping[Any, Any]: + def get_table(self, key: str, can_be_workspace: bool =3D False) -> Map= ping[Any, Any]: table =3D self.tomldata.get(key, {}) + if can_be_workspace and table.get("workspace", False) is True: + table =3D self.workspace_data["workspace"].get(key, {}) =20 return table =20 @@ -136,6 +145,16 @@ def main() -> None: action=3D"store", dest=3D"cargo_toml", help=3D"path to Cargo.toml file", + nargs=3D'?', + ) + parser.add_argument( + "--workspace", + metavar=3D"DIR", + action=3D"store", + dest=3D"workspace", + help=3D"path to root of the workspace", + required=3DFalse, + default=3DNone, ) parser.add_argument( "--features", @@ -168,7 +187,11 @@ def main() -> None: logging.debug("args: %s", args) =20 rustc_version =3D tuple((int(x) for x in args.rustc_version.split('.')= [0:2])) - cargo_toml =3D CargoTOML(args.cargo_toml) + if args.workspace: + workspace_cargo_toml =3D Path(args.workspace, "Cargo.toml").resolv= e() + cargo_toml =3D CargoTOML(args.cargo_toml, str(workspace_cargo_toml= )) + else: + cargo_toml =3D CargoTOML(args.cargo_toml, None) =20 if args.lints: for tok in generate_lint_flags(cargo_toml): --=20 2.47.0 From nobody Sat Nov 23 19:21:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1731089005; cv=none; d=zohomail.com; s=zohoarc; b=Q3cT3VKgiV4C/53bPz1wh7AMD/dBpo50qohYTUlyRhcggUiFAQO4veQFOg3CZmW+3OblXxHzGDBxu7OIQOSg2uZexB3YrPFtB3qci0T4M1YoQ/5wtMnsQGu0Uy+v4AEljJeVYnt+/4+8RA6GeF18ruYlUbUVcXgkA6Z2M2a/MqY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1731089005; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=PdoMcphvzb4FCO/Yj14yAl+KR/E0sA02B9InmeKS0lc=; b=Q3lL0jx6t5XaFGXdM8V1tVEa+4z/+O/0zud+v7lo6l5cpbOWMsnNIIb0CZWs2Dh3YSkpi7ez/b1WecavAaUqRlI4ngToVCaknB1XS6NdLDVlUegJ4yoc3MDUTUKTSud4L1GA3gFX3RXPjjZGe1fyVlFnd7uT3O0we8VW/as1R88= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1731089005313115.98364861373352; Fri, 8 Nov 2024 10:03:25 -0800 (PST) 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 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 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4315afcae6cso14197195e9.0 for ; Fri, 08 Nov 2024 10:01:59 -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) 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= X-MC-Unique: T429-Gt2PomWSXnhWknRDA-1 X-Mimecast-MFC-AGG-ID: T429-Gt2PomWSXnhWknRDA 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1731089006803116600 Content-Type: text/plain; charset="utf-8" Make Cargo use unknown_lints =3D "allow" as well. This is more future proof as we might add new lints to rust/Cargo.toml that are not supported by older versions of rustc or clippy. Signed-off-by: Paolo Bonzini --- meson.build | 12 ++++-------- rust/Cargo.toml | 6 ++++++ scripts/rust/rustc_args.py | 19 ++++++++++++++++--- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/meson.build b/meson.build index 5726135b324..1239f5c48c1 100644 --- a/meson.build +++ b/meson.build @@ -122,20 +122,16 @@ endif if have_rust rustc_args =3D [find_program('scripts/rust/rustc_args.py'), '--workspace', meson.project_source_root() / 'rust'] + if get_option('strict_rust_lints') + rustc_args +=3D ['--strict-lints'] + endif + rustfmt =3D find_program('rustfmt', required: false) =20 rustc_lint_args =3D run_command(rustc_args, '--lints', files('rust/Cargo.toml'), capture: true, check: true).stdout().strip().splitlines() =20 - # Occasionally, we may need to silence warnings and clippy lints that - # were only introduced in newer Rust compiler versions. Do not croak - # in that case; a CI job with rust_strict_lints =3D=3D true ensures that - # we do not have misspelled allow() attributes. - if not get_option('strict_rust_lints') - rustc_lint_args +=3D ['-A', 'unknown_lints'] - endif - # Apart from procedural macros, our Rust executables will often link # with C code, so include all the libraries that C code needs. This # is safe; https://github.com/rust-lang/rust/pull/54675 says that diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 0230b92a9fa..1ff8f5c2781 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -11,5 +11,11 @@ unexpected_cfgs =3D { level =3D "warn", check-cfg =3D [ 'cfg(MESON)', 'cfg(HAVE_GLIB_WITH_ALIGNED_ALLOC)', 'cfg(has_offset_of)'] } =20 +# Occasionally, we may need to silence warnings and clippy lints that +# were only introduced in newer Rust compiler versions. Do not croak +# in that case; a CI job with rust_strict_lints =3D=3D true disables this +# and ensures that we do not have misspelled allow() attributes. +unknown_lints =3D "allow" + # Prohibit code that is forbidden in Rust 2024 unsafe_op_in_unsafe_fn =3D "deny" diff --git a/scripts/rust/rustc_args.py b/scripts/rust/rustc_args.py index 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 =20 +STRICT_LINTS =3D {"unknown_lints", "warnings"} + =20 class CargoTOML: tomldata: Mapping[Any, Any] @@ -77,7 +79,7 @@ class LintFlag: priority: int =20 =20 -def generate_lint_flags(cargo_toml: CargoTOML) -> Iterable[str]: +def generate_lint_flags(cargo_toml: CargoTOML, strict_lints: bool) -> Iter= able[str]: """Converts Cargo.toml lints to rustc -A/-D/-F/-W flags.""" =20 toml_lints =3D cargo_toml.lints @@ -102,9 +104,13 @@ def generate_lint_flags(cargo_toml: CargoTOML) -> Iter= able[str]: # This may change if QEMU ever invokes clippy-driver or rustdo= c by # hand. For now, check the syntax but do not add non-rustc li= nts to # the command line. - if k =3D=3D "rust": + if k =3D=3D "rust" and not (strict_lints and lint in STRICT_LI= NTS): lint_list.append(LintFlag(flags=3D[flag, prefix + lint], p= riority=3Dpriority)) =20 + if strict_lints: + for lint in STRICT_LINTS: + lint_list.append(LintFlag(flags=3D["-D", lint], priority=3D100= 0000)) + lint_list.sort(key=3Dlambda x: x.priority) for lint in lint_list: yield from lint.flags @@ -181,6 +187,13 @@ def main() -> None: required=3DFalse, default=3D"1.0.0", ) + parser.add_argument( + "--strict-lints", + action=3D"store_true", + dest=3D"strict_lints", + help=3D"apply stricter checks (for nightly Rust)", + default=3DFalse, + ) args =3D parser.parse_args() if args.verbose: logging.basicConfig(level=3Dlogging.DEBUG) @@ -194,7 +207,7 @@ def main() -> None: cargo_toml =3D CargoTOML(args.cargo_toml, None) =20 if args.lints: - for tok in generate_lint_flags(cargo_toml): + for tok in generate_lint_flags(cargo_toml, args.strict_lints): print(tok) =20 if rustc_version >=3D (1, 80): --=20 2.47.0 From nobody Sat Nov 23 19:21:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1731089086; cv=none; d=zohomail.com; s=zohoarc; b=BKQQ2ugUHq68FhSrEV3XiR6LeTa0EeOSGVL7jJXfvCGzNKtLVPyOJJt2802by37n8yppu965PTCzPTH8snLID5loAA+cQ3nWLVXwVSdBeaCKLK3DKcfeDsmRO5o47gHCZRLJKNQza5SyzWzKr19tZux/W735Zq8aGNN24wA2vLI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1731089086; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=XeSGVNmsvm8LjvUgxmz8ceo62A+bkZyrWMrM+uvspEY=; b=DMl5AL+qPMOK7mvzIAhcJ1xUdy4PztWR0b49Ze/3nckJWL9gCWjkqC5ETjTZKntNZvGm1m8FGgKOK/S/SnNDYPxbIB6LR/NuUT0CVzEBu1PCxEFlCM/A+n8UpWOvFTzgmjoAnEpxMOZvin+xub/mSnrSutdZvi0UbQPzJmE0/K0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1731089086983251.46986258327195; Fri, 8 Nov 2024 10:04:46 -0800 (PST) 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 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 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-43157e3521dso16472315e9.1 for ; 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-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) 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= X-MC-Unique: nRwnEMYJOHe6mJE1LV9HFQ-1 X-Mimecast-MFC-AGG-ID: nRwnEMYJOHe6mJE1LV9HFQ 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1731089088903116600 Content-Type: text/plain; charset="utf-8" These are reported as clippy::semicolon_inside_block and clippy::as_ptr_cas= t_mut. Signed-off-by: Paolo Bonzini Reviewed-by: Junjie Mao --- 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/devi= ce.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 =3D 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 !=3D 0)) }; + unsafe { + qemu_set_irq(*irq, i32::from(flags & i !=3D 0)); + } } } =20 @@ -601,7 +603,7 @@ pub fn post_load(&mut self, _version_id: u32) -> Result= <(), ()> { let sysbus: *mut SysBusDevice =3D dev.cast::(); =20 qdev_prop_set_chr(dev, c_str!("chardev").as_ptr(), chr); - sysbus_realize_and_unref(sysbus, addr_of!(error_fatal) as *mut *mu= t 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 a= fter it's been // initialized in realize(). let cb_ptr =3D 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); + } =20 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 { =20 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()); } } --=20 2.47.0 From nobody Sat Nov 23 19:21:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1731089001; cv=none; d=zohomail.com; s=zohoarc; b=T3I0t+rU3aMHT0eZierdl8Zy/xac+WN7Lhtl3yVlIqFY45YEYo6m7UsVwNJfxHg5GKzsSV6O8bAWf4CcOuCMLuLv4mqcNN+UrnvhQt4RAw2LPrdBiimBCPvXMR2bRD4ChUecPj4crt4pFE1VItIH1BN5/tAdfSWEbrdXY4Qb0YE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1731089001; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=hRie6B2XwMU0zHx1ZvLnYMj1lxmNXlFqwCtyK6n296w=; b=A8W+tChnDrs8qRHTPJYxyDN228+0NWZlZP9hfEgwSDNOLFKGfEwOpV0rX3ppEstuk0j2jyRvIm1ViM1Tja+eN5wTbE/OXrsVKH0DLJp28fM3iBQ62zHDh4Ii19Mn5i2wkM5GOV3mbKHk5VaIMzZEM2LwRtsN1DzQxVy5wmnE/00= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1731089001488890.7580154572463; Fri, 8 Nov 2024 10:03:21 -0800 (PST) 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 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 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4315e8e9b1cso14056755e9.1 for ; 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-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) 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= X-MC-Unique: H_q54tkUOLmHzzD-dEF6yA-1 X-Mimecast-MFC-AGG-ID: H_q54tkUOLmHzzD-dEF6yA 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1731089002868116600 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Junjie Mao --- 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 =3D "allow" =20 # Prohibit code that is forbidden in Rust 2024 unsafe_op_in_unsafe_fn =3D "deny" + +[workspace.lints.rustdoc] +broken_intra_doc_links =3D "deny" +invalid_html_tags =3D "deny" +invalid_rust_codeblocks =3D "deny" +bare_urls =3D "deny" +unescaped_backticks =3D "deny" +redundant_explicit_links =3D "deny" + +[workspace.lints.clippy] +# default-warn lints +result_unit_err =3D "allow" +too_many_arguments =3D "allow" +upper_case_acronyms =3D "allow" + +# default-allow lints +as_ptr_cast_mut =3D "deny" +as_underscore =3D "deny" +assertions_on_result_states =3D "deny" +bool_to_int_with_if =3D "deny" +borrow_as_ptr =3D "deny" +cast_lossless =3D "deny" +dbg_macro =3D "deny" +debug_assert_with_mut_call =3D "deny" +derive_partial_eq_without_eq =3D "deny" +doc_markdown =3D "deny" +empty_structs_with_brackets =3D "deny" +ignored_unit_patterns =3D "deny" +implicit_clone =3D "deny" +macro_use_imports =3D "deny" +missing_const_for_fn =3D "deny" +missing_safety_doc =3D "deny" +multiple_crate_versions =3D "deny" +mut_mut =3D "deny" +needless_bitwise_bool =3D "deny" +needless_pass_by_ref_mut =3D "deny" +no_effect_underscore_binding =3D "deny" +option_option =3D "deny" +or_fun_call =3D "deny" +ptr_as_ptr =3D "deny" +ptr_cast_constness =3D "deny" +pub_underscore_fields =3D "deny" +redundant_clone =3D "deny" +redundant_closure_for_method_calls =3D "deny" +redundant_else =3D "deny" +redundant_pub_crate =3D "deny" +ref_binding_to_reference =3D "deny" +ref_option_ref =3D "deny" +return_self_not_must_use =3D "deny" +same_name_method =3D "deny" +semicolon_inside_block =3D "deny" +significant_drop_in_scrutinee =3D "deny" +significant_drop_tightening =3D "deny" +suspicious_operation_groupings =3D "deny" +transmute_ptr_to_ptr =3D "deny" +transmute_undefined_repr =3D "deny" +type_repetition_in_bounds =3D "deny" +unused_self =3D "deny" +used_underscore_binding =3D "deny" + +# nice to have, but cannot be enabled yet +#wildcard_imports =3D "deny" + +# these may have false positives +#option_if_let_else =3D "deny" +cognitive_complexity =3D "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. =20 #![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)] =20 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 )] --=20 2.47.0 From nobody Sat Nov 23 19:21:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1731089076; cv=none; d=zohomail.com; s=zohoarc; b=E1iKRPNUJdOruIKXnCKra9j0a3XvorVNeon0iWGJc5oSfR9hryRqIwT1rpTnh0cKpuWBYJWT8pHjQqit1A1DAGjFQDMkC4FYIn1fi1lL5RIoghiG1f1BegspPZSvY7XU+iE88y0Q48vgrBD2Ds4UIeJa5ocncR4iPziWnrwODks= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1731089076; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=yguWnQXG15f2x+f4QNRnXEOFJJORIkMpafNaeGv6vH0=; b=BKWXZ+YfgJn6EPsJPPwcDeypmcc429E53yBa/hEPsh9OX9+eTUcC+wfUaLezAE45Z34sP6TIeSkhKETMyL/9XHt4mOkzSqptb1wahWnkO/FscB273OO61hLS3HGRw1RfwFevTKXRKTjOx1FQCxRA2O3Ddd5uaWok7O+VAQ+NYYc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1731089076575949.1582808557134; Fri, 8 Nov 2024 10:04:36 -0800 (PST) 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 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 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-43159603c92so16424105e9.2 for ; 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 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) 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= X-MC-Unique: QdOMtPJ3NEuQr7td3br4jQ-1 X-Mimecast-MFC-AGG-ID: QdOMtPJ3NEuQr7td3br4jQ 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1731089076888116600 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Junjie Mao --- 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') =20 subdir('hw') + +cargo =3D 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 =3D format!("{}/bindings.rs.inc", path); if !Path::new(&file).exists() { panic!(concat!( - "No generated C bindings found! If you want to run `cargo`, st= art 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 d= evenv`, or\n", + " point MESON_BUILD_ROOT to the top of the build tree." )); } =20 --=20 2.47.0 From nobody Sat Nov 23 19:21:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1731089001; cv=none; d=zohomail.com; s=zohoarc; b=DsM4fLOlU5rRuVsTd/T1cqsKsiahIf8OFMpqU0nu5c0b8Vrh1O4YbGBPk/csk2JlTWsK8B9GvERc5Nx+XuS+uq1u1oViR4kB/mRa+15Lh0wlBhq33oYDWF66HMafy4uz2WzlWpeTERCPoaNLNoKbSb5yDSz6D5jaPse6bH/oJsE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1731089001; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Hz7vl/ta7wDz7MWKeB1ZugqNvFL2k59T4+vboRZ4+nc=; b=JR0r71b+NNOKxbNIVTY15QBuSM7Ur79plPrTfTjds4R9OwUEO2XoVadCLL3pF/Dq/26uvNwPIQivEm+LpDznT4eEv1ujw3VfwCPaQ39bFc+fCaWLfryUM9oKOKYEBhWQe0Wx3GBIakUegTu/m34iOHutPe0FRFnpQNrOBfu82fI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1731089001593511.3635439999857; Fri, 8 Nov 2024 10:03:21 -0800 (PST) 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 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 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4315af466d9so16410575e9.3 for ; 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-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) 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= X-MC-Unique: kECcr5GJM7ePn3Pr94tGgw-1 X-Mimecast-MFC-AGG-ID: kECcr5GJM7ePn3Pr94tGgw 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1731089002722116600 Content-Type: text/plain; charset="utf-8" Allow "cargo test --doc" to pass. Signed-off-by: Paolo Bonzini Reviewed-by: Junjie Mao --- 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 =3D unsafe { -/// ::core::mem::MaybeUninit::<$crate::bindings::Property>::zeroed= ().assume_init() -/// }, +/// pub unsafe trait Zeroable: Default { +/// const ZERO: Self =3D unsafe { ::core::mem::MaybeUninit::::ze= roed().assume_init() }; +/// } /// ``` /// /// The need for a manual implementation is only because `zeroed()` cannot --=20 2.47.0 From nobody Sat Nov 23 19:21:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1731089106; cv=none; d=zohomail.com; s=zohoarc; b=mqxykY2CIvXilt2r3DUcGqMZpwYMQyaxqt6rEl2gUc/Tbj7NYGpsurybM9XOA8v183UM9VBIBrmwAFxeJgybHUH9ackKeBWJR/HAbLIPeyMthy3aPAHD4T4vTnaBvOTCGCMmtosYeLtFBdq8JozrAQ7mlkGy3aKeqOVUEkuJeeA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1731089106; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=uynPjKqvjPdBbc/TZoxPs1tE8K2Uir/0YKLh2NR6k6I=; b=YMxptpJ3GXXLXJaNPQzmcnXUAHwGl/z2c5LbOJ/YSDe5mhrGbqdw0fQFm8VDZVN9LHhYpkImh9H2ryq5gXyvLXOIkoDupBT5jCJj76qojLCyHsj3VECyxwB+1gOMocIVLOqX3FEKO/vtv8gZf8001apR6S52Hl+NPuUeUNAa6EY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 173108910680938.390733810469214; Fri, 8 Nov 2024 10:05:06 -0800 (PST) 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 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 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-37d49887a2cso1334385f8f.0 for ; Fri, 08 Nov 2024 10:02:12 -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) 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= X-MC-Unique: 5JU1HG3bNwyf9NtS4I212w-1 X-Mimecast-MFC-AGG-ID: 5JU1HG3bNwyf9NtS4I212w 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1731089107185116600 Content-Type: text/plain; charset="utf-8" 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-t= emplate.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=3D":" $MAKE_CHECK_ARGS - section_end test =20 +.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 =20 +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/do= cker/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=3D/usr/local/rustup CARGO_HOME=3D/usr/local/cargo ENV RUSTC=3D/usr/local/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/= bin/rustc +ENV CARGO=3D/usr/local/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/= bin/cargo RUN set -eux && \ rustArch=3D'x86_64-unknown-linux-gnu' && \ rustupSha256=3D'6aeece6993e902708983b209d04c0d1dbb14ebb405ddb87def578d41= f920f56d' && \ @@ -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" =3D "$(/usr/local/cargo/bin/rustup +nightly which cargo)" = && \ test "$RUSTC" =3D "$(/usr/local/cargo/bin/rustup +nightly which rustc)" ENV PATH=3D$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 =3D [ "RUN dnf install -y wget\n", "ENV RUSTUP_HOME=3D/usr/local/rustup CARGO_HOME=3D/usr/local/cargo\n", "ENV RUSTC=3D/usr/local/rustup/toolchains/nightly-x86_64-unknown-linux= -gnu/bin/rustc\n", + "ENV CARGO=3D/usr/local/rustup/toolchains/nightly-x86_64-unknown-linux= -gnu/bin/cargo\n", "RUN set -eux && \\\n", " rustArch=3D'x86_64-unknown-linux-gnu' && \\\n", " rustupSha256=3D'6aeece6993e902708983b209d04c0d1dbb14ebb405ddb87def5= 78d41f920f56d' && \\\n", @@ -131,10 +132,13 @@ fedora_rustup_nightly_extras =3D [ " ./rustup-init -y --no-modify-path --profile default --default-toolc= hain 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" =3D "$(/usr/local/cargo/bin/rustup +nightly which car= go)" && \\\n', ' test "$RUSTC" =3D "$(/usr/local/cargo/bin/rustup +nightly which rus= tc)"\n', 'ENV PATH=3D$CARGO_HOME/bin:$PATH\n', 'RUN /usr/local/cargo/bin/rustup run nightly cargo install bindgen-cli= \n', + 'RUN $CARGO --list\n', ] =20 ubuntu2204_bindgen_extras =3D [ --=20 2.47.0