From patchwork Tue Oct 22 10:09:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13845488 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C4622D1CDCB for ; Tue, 22 Oct 2024 10:13:18 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t3Bq8-0004qY-LR; Tue, 22 Oct 2024 06:10:12 -0400 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 1t3Bq6-0004pK-Hs for qemu-devel@nongnu.org; Tue, 22 Oct 2024 06:10:10 -0400 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 1t3Bq4-0004Mh-R9 for qemu-devel@nongnu.org; Tue, 22 Oct 2024 06:10:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729591807; 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=wbBj01caC6lJt2jK3U2GIrbaj1k0y4qahoaWSgkgdlg=; b=PUHrMeskO0+SWuOZFxhz1iXYaqKyfcJvKrxwx+9PEPkR/Ye6vNcAjP3/oq/dnUTyQx6qG5 /dbCpnWi38AHbr5TVZCiDcCYA2XNcanEye4dRkavrtM9TlBcnoLaik+deOmUFXA8xnmkvg MU53fq4pNti1ThSmzJ/AdFd5KbfH5kU= 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-323-pztrLJLRPbm3S_bPACgvYw-1; Tue, 22 Oct 2024 06:10:05 -0400 X-MC-Unique: pztrLJLRPbm3S_bPACgvYw-1 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4316e350d6aso19324655e9.3 for ; Tue, 22 Oct 2024 03:10:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729591804; x=1730196604; 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=wbBj01caC6lJt2jK3U2GIrbaj1k0y4qahoaWSgkgdlg=; b=Ffk1JYO+dRtnj7Dzv9/X2KhkdtzlrDk+MTjNmbCY8Yv/VFuzUHn5GfTB5vCvx8KqZP CiXKAvzkpV2pEIORXR7FxWxG1VDA0gut5M7O3PrCWJ+PYq8ve1d6mZA7aVkaRIZt+ruB 2FHoJCPz6pC8zWBEz43NYjcMKSXFtJgy3M6GlyTSikX2yJeq18qBSOiWr+dTPIBlZro2 cUna4bhLDBIbqetJMiGS7llwLglfkuIlPBB4vKnTv7TfZ/4VuIsscfeVSPf9sl9IZ1t+ fdkkkEQ7rNntIdlLpoPoB/LJE71BA01f41Jo/I+4hj88mZynAGmKbkS8b8qEZ+tuJJww J81g== X-Gm-Message-State: AOJu0Yw1lITSWVqf+inamYTzd3XkQvjAj3B/xVuisFlCPzy5KVQPSrSY +/IckGmsvMXNsNgrO9OV5iYwNQdvciaNaNs/x4Cs6+sxw/ECrfHJCo/yN59gGYh7J8d7c/9zG4t q6udUUcq8KiZeqAnut0MuM7dxQhZMFN6Wy69xr//oWR+zziPwQ/S/JBpqsrPwkGbR4mOm7fBn2A DbR0VC4dbUfLLIXLfc86Jw65p5yucJf/HLqIck/3Q= X-Received: by 2002:a7b:ce07:0:b0:431:251a:9dc9 with SMTP id 5b1f17b1804b1-4317ed25874mr11360845e9.25.1729591803826; Tue, 22 Oct 2024 03:10:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFDj51YiXUYWxiG6Ym1Hu15udjnbMb0pqij8oKFiKRX2OJ1LRaQYKCnThPzMhv/tJL+PiO5gw== X-Received: by 2002:a7b:ce07:0:b0:431:251a:9dc9 with SMTP id 5b1f17b1804b1-4317ed25874mr11360535e9.25.1729591803366; Tue, 22 Oct 2024 03:10:03 -0700 (PDT) Received: from avogadro.local ([151.95.144.54]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4316f57fdb2sm82969035e9.20.2024.10.22.03.10.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Oct 2024 03:10:00 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: berrange@redhat.com, kwolf@redhat.com, junjie.mao@hotmail.com, manos.pitsidianakis@linaro.org, Zhao Liu Subject: [PATCH v2 01/14] rust: patch bilge-impl to allow compilation with 1.63.0 Date: Tue, 22 Oct 2024 12:09:42 +0200 Message-ID: <20241022100956.196657-2-pbonzini@redhat.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241022100956.196657-1-pbonzini@redhat.com> References: <20241022100956.196657-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.421, 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=-1.699, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Apply a patch that removes "let ... else" constructs, replacing them with "if let ... else" or "let ... = match ...". "let ... else" was stabilized in Rust 1.65.0. Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini Reviewed-by: Junjie Mao --- .gitattributes | 2 + subprojects/bilge-impl-0.2-rs.wrap | 1 + subprojects/packagefiles/.gitattributes | 1 + .../packagefiles/bilge-impl-1.63.0.patch | 45 +++++++++++++++++++ 4 files changed, 49 insertions(+) create mode 100644 subprojects/packagefiles/.gitattributes create mode 100644 subprojects/packagefiles/bilge-impl-1.63.0.patch diff --git a/.gitattributes b/.gitattributes index 6dc6383d3d1..9ce7a19581a 100644 --- a/.gitattributes +++ b/.gitattributes @@ -5,3 +5,5 @@ *.rs diff=rust *.rs.inc diff=rust Cargo.lock diff=toml merge=binary + +*.patch -text -whitespace diff --git a/subprojects/bilge-impl-0.2-rs.wrap b/subprojects/bilge-impl-0.2-rs.wrap index eefb10c36c2..b24c34a9043 100644 --- a/subprojects/bilge-impl-0.2-rs.wrap +++ b/subprojects/bilge-impl-0.2-rs.wrap @@ -5,3 +5,4 @@ source_filename = bilge-impl-0.2.0.tar.gz source_hash = feb11e002038ad243af39c2068c8a72bcf147acf05025dcdb916fcc000adb2d8 #method = cargo patch_directory = bilge-impl-0.2-rs +diff_files = bilge-impl-1.63.0.patch diff --git a/subprojects/packagefiles/.gitattributes b/subprojects/packagefiles/.gitattributes new file mode 100644 index 00000000000..bf5b766d75d --- /dev/null +++ b/subprojects/packagefiles/.gitattributes @@ -0,0 +1 @@ +/*.patch -text diff --git a/subprojects/packagefiles/bilge-impl-1.63.0.patch b/subprojects/packagefiles/bilge-impl-1.63.0.patch new file mode 100644 index 00000000000..987428a6d65 --- /dev/null +++ b/subprojects/packagefiles/bilge-impl-1.63.0.patch @@ -0,0 +1,45 @@ +--- a/src/shared/discriminant_assigner.rs ++++ b/src/shared/discriminant_assigner.rs +@@ -26,20 +26,20 @@ + let discriminant_expr = &discriminant.1; + let variant_name = &variant.ident; + +- let Expr::Lit(ExprLit { lit: Lit::Int(int), .. }) = discriminant_expr else { ++ if let Expr::Lit(ExprLit { lit: Lit::Int(int), .. }) = discriminant_expr { ++ let discriminant_value: u128 = int.base10_parse().unwrap_or_else(unreachable); ++ if discriminant_value > self.max_value() { ++ abort!(variant, "Value of variant exceeds the given number of bits") ++ } ++ ++ Some(discriminant_value) ++ } else { + abort!( + discriminant_expr, + "variant `{}` is not a number", variant_name; + help = "only literal integers currently supported" + ) +- }; +- +- let discriminant_value: u128 = int.base10_parse().unwrap_or_else(unreachable); +- if discriminant_value > self.max_value() { +- abort!(variant, "Value of variant exceeds the given number of bits") + } +- +- Some(discriminant_value) + } + + fn assign(&mut self, variant: &Variant) -> u128 { +--- a/src/shared/fallback.rs ++++ b/src/shared/fallback.rs +@@ -22,8 +22,9 @@ + } + Unnamed(fields) => { + let variant_fields = fields.unnamed.iter(); +- let Ok(fallback_value) = variant_fields.exactly_one() else { +- abort!(variant, "fallback variant must have exactly one field"; help = "use only one field or change to a unit variant") ++ let fallback_value = match variant_fields.exactly_one() { ++ Ok(ok) => ok, ++ _ => abort!(variant, "fallback variant must have exactly one field"; help = "use only one field or change to a unit variant") + }; + + if !is_last_variant { From patchwork Tue Oct 22 10:09:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13845474 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F0929D1CDCF for ; Tue, 22 Oct 2024 10:10:55 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t3BqE-0004rI-Aw; Tue, 22 Oct 2024 06:10:18 -0400 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 1t3BqC-0004r8-CK for qemu-devel@nongnu.org; Tue, 22 Oct 2024 06:10:16 -0400 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 1t3BqA-0004NE-SO for qemu-devel@nongnu.org; Tue, 22 Oct 2024 06:10:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729591814; 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=u45iLCwaL6UDPFZFrxkclA/Jz3UXse/PWIiVqr58mZQ=; b=RR61zs4pLORMz20pcKLFZMssjZQjKQZcDlo5TJtVmV4gdV8/zoPCLcp/GkEy7gW1v+nG2O wo7a4oYf787mRzkOgx4ONqD7Im9wmfS0CaaZwD6HFVkhX6ho/kQDQtjljxgm2/cMOFb2bk lbZklHvVL4tcohToyQUGA2rHhzBD0JU= 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-225-_hK7ADmUNLm6XC5qoDbmlw-1; Tue, 22 Oct 2024 06:10:09 -0400 X-MC-Unique: _hK7ADmUNLm6XC5qoDbmlw-1 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4315afcae6cso29594755e9.0 for ; Tue, 22 Oct 2024 03:10:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729591807; x=1730196607; 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=u45iLCwaL6UDPFZFrxkclA/Jz3UXse/PWIiVqr58mZQ=; b=Lpy/Yd9hK+UHIl1/8EQW0n19srpPIGyx0POB8Iw5zp5WHI8sU1YNDsIio7iACbfWyO etcC6hG/rulEiwjrp9n5aJnm94xfApVtc+fNPEvUEEmln94x0ZLzgeFAPfmlU+uReu2W 3jeC0QLfrR8l2Mqoc/+5+GGCDgkPh9kYYwK15HGg3K/78Pu6E6Fy17D8S+oltaUtMtTJ CQfgXNd4SUi7AFZfTVanT3TWMzJE0JwEx9eEGrkKUTpT6F+LRyOI58m+r8eE+lS7jgLL /12He+U2xSBYlcGnnU6s562JmHwbhVDpESSeWLsfgioktlJFxijAMMd4243a6kqIHPiP dhYg== X-Gm-Message-State: AOJu0Yz0fhMazyr1wKDl1gLg6c2sXqfBmlVlf76GSAzYSsFiOu5yI0/d hvegL05yOUEYCpdXnPy5nHipJXCOWSHq1KkGxXlCtaSWOdcvAbLD0uReaz8tx++X4UUj8LjAA7/ 6wZZyOoj+7Onof/C+HwKP5FJ4D7EKRL5DCl/IAfk98CInEGru2h8keGn1ZCnHJA2ldaQMPV/mAu AbRbdzzqCqW96GacVzh4R2x+8WR4zlYG6egJ8A+xU= X-Received: by 2002:a05:600c:1994:b0:42c:b8c9:16c8 with SMTP id 5b1f17b1804b1-4317bd8e3c4mr17016705e9.10.1729591807574; Tue, 22 Oct 2024 03:10:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGH60NolRXgjd8lCXnosS+yJVsDidGmozsXZ3YAcdeEYVg2JuEcF+eJ+c4J62IzOGesgIEaaQ== X-Received: by 2002:a05:600c:1994:b0:42c:b8c9:16c8 with SMTP id 5b1f17b1804b1-4317bd8e3c4mr17016445e9.10.1729591807125; Tue, 22 Oct 2024 03:10:07 -0700 (PDT) Received: from avogadro.local ([151.95.144.54]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4316f58adffsm83761815e9.22.2024.10.22.03.10.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Oct 2024 03:10:05 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: berrange@redhat.com, kwolf@redhat.com, junjie.mao@hotmail.com, manos.pitsidianakis@linaro.org Subject: [PATCH v2 02/14] rust: fix cfgs of proc-macro2 for 1.63.0 Date: Tue, 22 Oct 2024 12:09:43 +0200 Message-ID: <20241022100956.196657-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241022100956.196657-1-pbonzini@redhat.com> References: <20241022100956.196657-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.421, 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=-1.699, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Replay the configuration that would be computed by build.rs when compiling on a 1.63.0 compiler. Signed-off-by: Paolo Bonzini Reviewed-by: Junjie Mao --- subprojects/packagefiles/proc-macro2-1-rs/meson.build | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/subprojects/packagefiles/proc-macro2-1-rs/meson.build b/subprojects/packagefiles/proc-macro2-1-rs/meson.build index 818ec59336b..8e601b50ccc 100644 --- a/subprojects/packagefiles/proc-macro2-1-rs/meson.build +++ b/subprojects/packagefiles/proc-macro2-1-rs/meson.build @@ -15,7 +15,9 @@ _proc_macro2_rs = static_library( rust_abi: 'rust', rust_args: [ '--cfg', 'feature="proc-macro"', - '--cfg', 'span_locations', + '--cfg', 'no_literal_byte_character', + '--cfg', 'no_literal_c_string', + '--cfg', 'no_source_text', '--cfg', 'wrap_proc_macro', ], dependencies: [ From patchwork Tue Oct 22 10:09:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13845487 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8DA87D1CDCB for ; Tue, 22 Oct 2024 10:12:49 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t3BqN-0004sE-Vf; Tue, 22 Oct 2024 06:10:27 -0400 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 1t3BqH-0004rg-Hn for qemu-devel@nongnu.org; Tue, 22 Oct 2024 06:10:21 -0400 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 1t3BqF-0004NT-KF for qemu-devel@nongnu.org; Tue, 22 Oct 2024 06:10:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729591818; 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=QP7e8UEKzoE0KB/7pMJdUtY48ENaf+OvkadNUEq9q/I=; b=i5ClNuk8EW9YOCsPXla+Ysdqq5sspTwHqfA7+m7CDx8lwiHvpFk07zfvvGe21VFhDPE6ni 8AHqER5Jxs40kDt4CQy/4xHViqc/z27zcyBbIFE/WZG27SaymKUafQGFsrGyu7NcAA5iNG pS4mEpurjlZR+PgfPKAlTAgo445qn+I= 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-290-72yTXa1zMeCcGtSN-8kvGQ-1; Tue, 22 Oct 2024 06:10:14 -0400 X-MC-Unique: 72yTXa1zMeCcGtSN-8kvGQ-1 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4315af466d9so37788005e9.3 for ; Tue, 22 Oct 2024 03:10:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729591811; x=1730196611; 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=QP7e8UEKzoE0KB/7pMJdUtY48ENaf+OvkadNUEq9q/I=; b=bgVs2Mge0SV76PshRipqKu4MbPWKIo81pGbcGOvU87bS5eWAMU4whSpcFBgMEY8KLw GDK8+CxsrM8yRBuB2L+yaSMoXlbXjwTxQhHI+nOzGfN60BWdtCHfapMHS6/pzEckFPgG Y/YonjPg1eKV46KML8SwQJxLypdR1R6p4tGX77w/whIfsxak13bU+YOnyewOMGU1zzOB wz1T77HxBO74HrQU6yVM8Dze9Wb7Sv7oNAumh3JiOLVnIAWOWZMTqOHMas2uBerm95KE x7NUBTqVdKn/yyiZPdH2W9PUqdW5xdCgPQiw3P1rmKHm0aRf+NblO1Hc5ZyQgIQ9pjKk t8Ag== X-Gm-Message-State: AOJu0YzrprFsY3IZ0NKg1LYYBIWMcHy9Tq0p0qN3guZ9ZsUUdGDVL1j9 x/vfxxqh7AplIfAUJh7qxELUFXWd/RqmCOL6B54tWjR8yZ9A0HBtf0QXEgqMUS7KQzV6f0EXBgb ThJuc+ORaupuvad3lNMqTN/ZxaiYNa20rkZvY6BmCfIRyl+Ft8+YjJKLCyZR0UeUtGiFx43DlPf iXbCLMLb03198PLmDlpJWUgWqzEtW1clfSHJ2S7c8= X-Received: by 2002:a05:600c:5121:b0:431:4b88:d408 with SMTP id 5b1f17b1804b1-4316163520emr125197345e9.5.1729591810586; Tue, 22 Oct 2024 03:10:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHJv4+Fr3Onxrgwi+Sa76xEiyaIS92rbONOREWRZWq3Lwox9lcdRK9+O73Eb9AYtVl+pPT6Yg== X-Received: by 2002:a05:600c:5121:b0:431:4b88:d408 with SMTP id 5b1f17b1804b1-4316163520emr125197025e9.5.1729591810012; Tue, 22 Oct 2024 03:10:10 -0700 (PDT) Received: from avogadro.local ([151.95.144.54]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4316f58f0efsm84440045e9.26.2024.10.22.03.10.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Oct 2024 03:10:09 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: berrange@redhat.com, kwolf@redhat.com, junjie.mao@hotmail.com, manos.pitsidianakis@linaro.org, Zhao Liu Subject: [PATCH v2 03/14] rust: use std::os::raw instead of core::ffi Date: Tue, 22 Oct 2024 12:09:44 +0200 Message-ID: <20241022100956.196657-4-pbonzini@redhat.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241022100956.196657-1-pbonzini@redhat.com> References: <20241022100956.196657-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.421, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org core::ffi::c_* types were introduced in Rust 1.64.0. Use the older types in std::os::raw, which are now aliases of the types in core::ffi. There is no need to compile QEMU as no_std, so this is acceptable as long as we support a version of Debian with Rust 1.63.0. Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini --- meson.build | 3 +-- rust/hw/char/pl011/src/device.rs | 20 +++++++++++--------- rust/hw/char/pl011/src/lib.rs | 2 +- rust/hw/char/pl011/src/memory_ops.rs | 10 ++++++---- rust/qemu-api/src/definitions.rs | 2 +- rust/qemu-api/src/device_class.rs | 8 ++++---- rust/qemu-api/src/lib.rs | 11 +++++++---- rust/qemu-api/tests/tests.rs | 9 ++++----- 8 files changed, 35 insertions(+), 30 deletions(-) diff --git a/meson.build b/meson.build index 3c71d129494..94f30033f68 100644 --- a/meson.build +++ b/meson.build @@ -3933,14 +3933,13 @@ if have_rust and have_system bindgen_args = [ '--disable-header-comment', '--raw-line', '// @generated', - '--ctypes-prefix', 'core::ffi', + '--ctypes-prefix', 'std::os::raw', '--formatter', 'rustfmt', '--generate-block', '--generate-cstr', '--impl-debug', '--merge-extern-blocks', '--no-doc-comments', - '--use-core', '--with-derive-default', '--no-layout-tests', '--no-prepend-enum-name', diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs index b3d8bc004e0..7be21769ae4 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -2,9 +2,11 @@ // Author(s): Manos Pitsidianakis // SPDX-License-Identifier: GPL-2.0-or-later -use core::{ - ffi::{c_int, c_uchar, c_uint, c_void, CStr}, - ptr::{addr_of, addr_of_mut, NonNull}, +use core::ptr::{addr_of, addr_of_mut, NonNull}; + +use std::{ + ffi::CStr, + os::raw::{c_int, c_uchar, c_uint, c_void} }; use qemu_api::{ @@ -89,10 +91,10 @@ pub struct PL011Class { impl qemu_api::definitions::Class for PL011Class { const CLASS_INIT: Option< - unsafe extern "C" fn(klass: *mut ObjectClass, data: *mut core::ffi::c_void), + unsafe extern "C" fn(klass: *mut ObjectClass, data: *mut c_void), > = Some(crate::device_class::pl011_class_init); const CLASS_BASE_INIT: Option< - unsafe extern "C" fn(klass: *mut ObjectClass, data: *mut core::ffi::c_void), + unsafe extern "C" fn(klass: *mut ObjectClass, data: *mut c_void), > = None; } @@ -151,7 +153,7 @@ pub unsafe fn init(&mut self) { pub fn read( &mut self, offset: hwaddr, - _size: core::ffi::c_uint, + _size: c_uint, ) -> std::ops::ControlFlow { use RegisterOffset::*; @@ -530,9 +532,9 @@ pub fn update(&self) { /// /// The buffer and size arguments must also be valid. pub unsafe extern "C" fn pl011_receive( - opaque: *mut core::ffi::c_void, + opaque: *mut c_void, buf: *const u8, - size: core::ffi::c_int, + size: c_int, ) { unsafe { debug_assert!(!opaque.is_null()); @@ -552,7 +554,7 @@ pub fn update(&self) { /// We expect the FFI user of this function to pass a valid pointer, that has /// the same size as [`PL011State`]. We also expect the device is /// readable/writeable from one thread at any time. -pub unsafe extern "C" fn pl011_event(opaque: *mut core::ffi::c_void, event: QEMUChrEvent) { +pub unsafe extern "C" fn pl011_event(opaque: *mut c_void, event: QEMUChrEvent) { unsafe { debug_assert!(!opaque.is_null()); let mut state = NonNull::new_unchecked(opaque.cast::()); diff --git a/rust/hw/char/pl011/src/lib.rs b/rust/hw/char/pl011/src/lib.rs index 2939ee50c99..2b157868b0f 100644 --- a/rust/hw/char/pl011/src/lib.rs +++ b/rust/hw/char/pl011/src/lib.rs @@ -45,7 +45,7 @@ pub mod device_class; pub mod memory_ops; -pub const TYPE_PL011: &::core::ffi::CStr = c"pl011"; +pub const TYPE_PL011: &::std::ffi::CStr = c"pl011"; /// Offset of each register from the base memory address of the device. /// diff --git a/rust/hw/char/pl011/src/memory_ops.rs b/rust/hw/char/pl011/src/memory_ops.rs index 24ac9c870c1..6d822027d51 100644 --- a/rust/hw/char/pl011/src/memory_ops.rs +++ b/rust/hw/char/pl011/src/memory_ops.rs @@ -4,6 +4,8 @@ use core::ptr::NonNull; +use std::os::raw::{c_uint, c_void}; + use qemu_api::{ bindings::*, zeroable::Zeroable @@ -26,9 +28,9 @@ }; unsafe extern "C" fn pl011_read( - opaque: *mut core::ffi::c_void, + opaque: *mut c_void, addr: hwaddr, - size: core::ffi::c_uint, + size: c_uint, ) -> u64 { assert!(!opaque.is_null()); let mut state = unsafe { NonNull::new_unchecked(opaque.cast::()) }; @@ -47,10 +49,10 @@ } unsafe extern "C" fn pl011_write( - opaque: *mut core::ffi::c_void, + opaque: *mut c_void, addr: hwaddr, data: u64, - _size: core::ffi::c_uint, + _size: c_uint, ) { unsafe { assert!(!opaque.is_null()); diff --git a/rust/qemu-api/src/definitions.rs b/rust/qemu-api/src/definitions.rs index 064afe60549..26597934bbd 100644 --- a/rust/qemu-api/src/definitions.rs +++ b/rust/qemu-api/src/definitions.rs @@ -4,7 +4,7 @@ //! Definitions required by QEMU when registering a device. -use ::core::ffi::{c_void, CStr}; +use std::{ffi::CStr, os::raw::c_void}; use crate::bindings::{Object, ObjectClass, TypeInfo}; diff --git a/rust/qemu-api/src/device_class.rs b/rust/qemu-api/src/device_class.rs index ed2d7ce1a54..5c305d945d3 100644 --- a/rust/qemu-api/src/device_class.rs +++ b/rust/qemu-api/src/device_class.rs @@ -7,7 +7,7 @@ macro_rules! device_class_init { ($func:ident, props => $props:ident, realize_fn => $realize_fn:expr, legacy_reset_fn => $legacy_reset_fn:expr, vmsd => $vmsd:ident$(,)*) => { pub unsafe extern "C" fn $func( klass: *mut $crate::bindings::ObjectClass, - _: *mut ::core::ffi::c_void, + _: *mut ::std::os::raw::c_void, ) { let mut dc = ::core::ptr::NonNull::new(klass.cast::<$crate::bindings::DeviceClass>()).unwrap(); @@ -26,7 +26,7 @@ macro_rules! define_property { ($name:expr, $state:ty, $field:expr, $prop:expr, $type:expr, default = $defval:expr$(,)*) => { $crate::bindings::Property { // use associated function syntax for type checking - name: ::core::ffi::CStr::as_ptr($name), + name: ::std::ffi::CStr::as_ptr($name), info: $prop, offset: ::core::mem::offset_of!($state, $field) as isize, set_default: true, @@ -37,7 +37,7 @@ macro_rules! define_property { ($name:expr, $state:ty, $field:expr, $prop:expr, $type:expr$(,)*) => { $crate::bindings::Property { // use associated function syntax for type checking - name: ::core::ffi::CStr::as_ptr($name), + name: ::std::ffi::CStr::as_ptr($name), info: $prop, offset: ::core::mem::offset_of!($state, $field) as isize, set_default: false, @@ -75,7 +75,7 @@ macro_rules! vm_state_description { pub static $name: $crate::bindings::VMStateDescription = $crate::bindings::VMStateDescription { $(name: { #[used] - static VMSTATE_NAME: &::core::ffi::CStr = $vname; + static VMSTATE_NAME: &::std::ffi::CStr = $vname; $vname.as_ptr() },)* unmigratable: true, diff --git a/rust/qemu-api/src/lib.rs b/rust/qemu-api/src/lib.rs index e94a15bb823..321c33d2c7b 100644 --- a/rust/qemu-api/src/lib.rs +++ b/rust/qemu-api/src/lib.rs @@ -31,7 +31,10 @@ unsafe impl Sync for bindings::VMStateDescription {} pub mod device_class; pub mod zeroable; -use std::alloc::{GlobalAlloc, Layout}; +use std::{ + alloc::{GlobalAlloc, Layout}, + os::raw::c_void, +}; #[cfg(HAVE_GLIB_WITH_ALIGNED_ALLOC)] extern "C" { @@ -45,8 +48,8 @@ fn g_aligned_alloc0( #[cfg(not(HAVE_GLIB_WITH_ALIGNED_ALLOC))] extern "C" { - fn qemu_memalign(alignment: usize, size: usize) -> *mut ::core::ffi::c_void; - fn qemu_vfree(ptr: *mut ::core::ffi::c_void); + fn qemu_memalign(alignment: usize, size: usize) -> *mut c_void; + fn qemu_vfree(ptr: *mut c_void); } extern "C" { @@ -111,7 +114,7 @@ fn default() -> Self { } // Sanity check. -const _: [(); 8] = [(); ::core::mem::size_of::<*mut ::core::ffi::c_void>()]; +const _: [(); 8] = [(); ::core::mem::size_of::<*mut c_void>()]; unsafe impl GlobalAlloc for QemuAllocator { unsafe fn alloc(&self, layout: Layout) -> *mut u8 { diff --git a/rust/qemu-api/tests/tests.rs b/rust/qemu-api/tests/tests.rs index aa1e0568c69..3396c33fe1e 100644 --- a/rust/qemu-api/tests/tests.rs +++ b/rust/qemu-api/tests/tests.rs @@ -2,7 +2,7 @@ // Author(s): Manos Pitsidianakis // SPDX-License-Identifier: GPL-2.0-or-later -use core::ffi::CStr; +use std::{ffi::CStr, os::raw::c_void}; use qemu_api::{ bindings::*, @@ -63,11 +63,10 @@ impl ObjectImpl for DummyState { } impl Class for DummyClass { - const CLASS_INIT: Option< - unsafe extern "C" fn(klass: *mut ObjectClass, data: *mut core::ffi::c_void), - > = Some(dummy_class_init); + const CLASS_INIT: Option = + Some(dummy_class_init); const CLASS_BASE_INIT: Option< - unsafe extern "C" fn(klass: *mut ObjectClass, data: *mut core::ffi::c_void), + unsafe extern "C" fn(klass: *mut ObjectClass, data: *mut c_void), > = None; } From patchwork Tue Oct 22 10:09:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13845475 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3104BD1CDCB for ; Tue, 22 Oct 2024 10:11:01 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t3BqJ-0004rx-Ma; Tue, 22 Oct 2024 06:10:24 -0400 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 1t3BqH-0004rf-Dp for qemu-devel@nongnu.org; Tue, 22 Oct 2024 06:10:21 -0400 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 1t3BqF-0004NZ-Lq for qemu-devel@nongnu.org; Tue, 22 Oct 2024 06:10:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729591818; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zoIDQehBCXOq+hK5SCx2x9E41Nu5lYrh5jQDtEdUC3E=; b=ZLx3XUaufF5hGfTBT6VX/Ob4ZMiuXLnI8FHhExlkp+NbH6Q/thYlVDo+t7rlYZRztcT4+M V5oOFIj35DStUjdMn10vB9QQfW2TACxRkeIleQHyVx/txqGSJi+wOISLTihJ3K2gmVaX3m Kfzrzb1JBJ4Neu0yGmZmeplAeldReYA= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-180-VdRURoNlNmGiDy8JdBteMw-1; Tue, 22 Oct 2024 06:10:17 -0400 X-MC-Unique: VdRURoNlNmGiDy8JdBteMw-1 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-37d47fdbbd6so3187099f8f.3 for ; Tue, 22 Oct 2024 03:10:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729591816; x=1730196616; 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=zoIDQehBCXOq+hK5SCx2x9E41Nu5lYrh5jQDtEdUC3E=; b=uqYYVe+fkXZRSa5sdNwcTLZErJNEBW9HXgAXFw4CCNr/4fPblBHxmoF7LGanRefQjU y4t6TxN/yii3EPcmfRQ6SFs9DNjFo90l0g8a3tExX8Zba8zHX4uGOF6qPGIuM969wWpv Si14PkQ3v2tltJMPyDeUduWLi6zXx5ynSK2OIjdYuRJw6Jag8y0fOsd9QPUFD0dtoXGS ZLHlnCd7cXte6Kp1NPxbyECUMvFcjF3DwEuAfMg2Y7bIlJcOzbHKSCQnDXj2bMWd/24O /rRKm+d2BNfPlzuobvPfvEdR6efXUIPRvi0i4viS3XcD6rJpLZGdoYeJvCYf/Maetx6B FYbQ== X-Gm-Message-State: AOJu0Yw8JlUfQyggKHPbyPgkYxopGK2yL6g7QeRYkbUr2IKaHuV41iRL qAsuCsGmB43CIesZFPJWOozYpL6QEIlBKitUO2GFOZrvYYNfDbbgLkR3CisRK0wi2Lv9v+ETK91 VEpgFBvXp37i5pvC9Q7LtBJe+0qUip8fIw2EJm5Tbo5wloLxsN5JUI/L41doAdI3qaFdy8uREpm zVs7QTKFQm6Tz7TQcxwU7XjkTXn6bTWOeLQXawTp8= X-Received: by 2002:adf:f491:0:b0:37d:47f9:be8a with SMTP id ffacd0b85a97d-37ef2040d72mr1443619f8f.0.1729591815616; Tue, 22 Oct 2024 03:10:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHV/5Fa5LQjFFaW5cFo+BfLBeWWn3KlkerhQymuadx9IzZ/+riWB9rstO66wqBfjZMuNIiW8A== X-Received: by 2002:adf:f491:0:b0:37d:47f9:be8a with SMTP id ffacd0b85a97d-37ef2040d72mr1443546f8f.0.1729591813778; Tue, 22 Oct 2024 03:10:13 -0700 (PDT) Received: from avogadro.local ([151.95.144.54]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4316f570dd5sm83879455e9.3.2024.10.22.03.10.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Oct 2024 03:10:12 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: berrange@redhat.com, kwolf@redhat.com, junjie.mao@hotmail.com, manos.pitsidianakis@linaro.org Subject: [PATCH v2 04/14] rust: introduce a c_str macro Date: Tue, 22 Oct 2024 12:09:45 +0200 Message-ID: <20241022100956.196657-5-pbonzini@redhat.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241022100956.196657-1-pbonzini@redhat.com> References: <20241022100956.196657-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.421, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org This allows CStr constants to be defined easily on Rust 1.63.0, while checking that there are no embedded NULs. c"" literals were only stabilized in Rust 1.77.0. Signed-off-by: Paolo Bonzini --- rust/hw/char/pl011/src/device.rs | 5 ++- rust/hw/char/pl011/src/device_class.rs | 5 ++- rust/hw/char/pl011/src/lib.rs | 4 +- rust/qemu-api/meson.build | 4 ++ rust/qemu-api/src/c_str.rs | 53 ++++++++++++++++++++++++++ rust/qemu-api/src/lib.rs | 1 + rust/qemu-api/tests/tests.rs | 8 ++-- 7 files changed, 71 insertions(+), 9 deletions(-) create mode 100644 rust/qemu-api/src/c_str.rs diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs index 7be21769ae4..5ffe1911376 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -11,6 +11,7 @@ use qemu_api::{ bindings::{self, *}, + c_str, definitions::ObjectImpl, }; @@ -99,7 +100,7 @@ impl qemu_api::definitions::Class for PL011Class { } #[used] -pub static CLK_NAME: &CStr = c"clk"; +pub static CLK_NAME: &CStr = c_str!("clk"); impl PL011State { /// Initializes a pre-allocated, unitialized instance of `PL011State`. @@ -575,7 +576,7 @@ pub fn update(&self) { let dev: *mut DeviceState = qdev_new(PL011State::TYPE_INFO.name); let sysbus: *mut SysBusDevice = dev.cast::(); - qdev_prop_set_chr(dev, c"chardev".as_ptr(), chr); + qdev_prop_set_chr(dev, c_str!("chardev").as_ptr(), chr); sysbus_realize_and_unref(sysbus, addr_of!(error_fatal) as *mut *mut Error); sysbus_mmio_map(sysbus, 0, addr); sysbus_connect_irq(sysbus, 0, irq); diff --git a/rust/hw/char/pl011/src/device_class.rs b/rust/hw/char/pl011/src/device_class.rs index 78fa1cdd5b6..3b9b0267b4c 100644 --- a/rust/hw/char/pl011/src/device_class.rs +++ b/rust/hw/char/pl011/src/device_class.rs @@ -6,6 +6,7 @@ use qemu_api::{ bindings::*, + c_str, definitions::ObjectImpl, zeroable::Zeroable, }; @@ -22,14 +23,14 @@ qemu_api::declare_properties! { PL011_PROPERTIES, qemu_api::define_property!( - c"chardev", + c_str!("chardev"), PL011State, char_backend, unsafe { &qdev_prop_chr }, CharBackend ), qemu_api::define_property!( - c"migrate-clk", + c_str!("migrate-clk"), PL011State, migrate_clock, unsafe { &qdev_prop_bool }, diff --git a/rust/hw/char/pl011/src/lib.rs b/rust/hw/char/pl011/src/lib.rs index 2b157868b0f..0a598e5629d 100644 --- a/rust/hw/char/pl011/src/lib.rs +++ b/rust/hw/char/pl011/src/lib.rs @@ -41,11 +41,13 @@ extern crate bilge_impl; extern crate qemu_api; +use qemu_api::c_str; + pub mod device; pub mod device_class; pub mod memory_ops; -pub const TYPE_PL011: &::std::ffi::CStr = c"pl011"; +pub const TYPE_PL011: &::std::ffi::CStr = c_str!("pl011"); /// Offset of each register from the base memory address of the device. /// diff --git a/rust/qemu-api/meson.build b/rust/qemu-api/meson.build index 1b0fd406378..2b3dea59fb6 100644 --- a/rust/qemu-api/meson.build +++ b/rust/qemu-api/meson.build @@ -3,6 +3,7 @@ _qemu_api_rs = static_library( structured_sources( [ 'src/lib.rs', + 'src/c_str.rs', 'src/definitions.rs', 'src/device_class.rs', 'src/zeroable.rs', @@ -17,6 +18,9 @@ _qemu_api_rs = static_library( ], ) +rust.test('rust-qemu-api-tests', _qemu_api_rs, + suite: ['unit', 'rust']) + qemu_api = declare_dependency( link_with: _qemu_api_rs, dependencies: qemu_api_macros, diff --git a/rust/qemu-api/src/c_str.rs b/rust/qemu-api/src/c_str.rs new file mode 100644 index 00000000000..5ef46d12bef --- /dev/null +++ b/rust/qemu-api/src/c_str.rs @@ -0,0 +1,53 @@ +// Copyright 2024 Red Hat, Inc. +// Author(s): Paolo Bonzini +// SPDX-License-Identifier: GPL-2.0-or-later + +#[macro_export] +/// Given a string constant _without_ embedded or trailing NULs, return +/// a CStr. +/// +/// Needed for compatibility with Rust <1.77. +macro_rules! c_str { + ($str:expr) => {{ + const STRING: &str = concat!($str, "\0"); + const BYTES: &[u8] = STRING.as_bytes(); + + // "for" is not allowed in const context... oh well, + // everybody loves some lisp. This could be turned into + // a procedural macro if this is a problem; alternatively + // Rust 1.72 makes CStr::from_bytes_with_nul a const function. + const fn f(b: &[u8], i: usize) { + if i == BYTES.len() - 1 { + } else if BYTES[i] == 0 { + panic!("c_str argument contains NUL") + } else { + f(b, i + 1) + } + } + f(BYTES, 0); + + // SAFETY: absence of NULs apart from the final byte was checked above + unsafe { std::ffi::CStr::from_bytes_with_nul_unchecked(BYTES) } + }}; +} + +#[cfg(test)] +mod tests { + use std::ffi::CStr; + + use crate::c_str; + + #[test] + fn test_cstr_macro() { + let good = c_str!(" From patchwork Tue Oct 22 10:09:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13845481 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A0562D1CDCB for ; Tue, 22 Oct 2024 10:11:43 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t3BqU-0004sX-2N; Tue, 22 Oct 2024 06:10:34 -0400 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 1t3BqM-0004sD-F4 for qemu-devel@nongnu.org; Tue, 22 Oct 2024 06:10:27 -0400 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 1t3BqJ-0004O1-GK for qemu-devel@nongnu.org; Tue, 22 Oct 2024 06:10:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729591822; 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=FhAct4q18ImXFIsWNk2smwgX1VzeDjNJvhYscWcGBhY=; b=ehLKCrcbpel7YcafEFxnSPUOA+mezi2WVvU2zO3YTGbdQSEGbe+2VxZ3Ryw8aFo+9lmgyE Ae/NlA2Nl6fBS1JIwQqriYdmYDkIQNismsBEUv9mrMlvzi7M3KjwQslVlYncvhFJnhFt9f qQ8HR010vDP/KkJNRKAsbFqQ/GBZRPE= 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-209-HSM7FzGbMFWdl4WtJo0cuw-1; Tue, 22 Oct 2024 06:10:21 -0400 X-MC-Unique: HSM7FzGbMFWdl4WtJo0cuw-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4315d98a873so36909055e9.1 for ; Tue, 22 Oct 2024 03:10:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729591819; x=1730196619; 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=FhAct4q18ImXFIsWNk2smwgX1VzeDjNJvhYscWcGBhY=; b=geNrDPU8nL25EgmZM/nS4JdfBg7Ea5Qho9oHU3n4Ld7h7TBLR8ouoE0HJ0zQqk8gO2 /XxBq1jrxNGaB/pACLyqKs8SW35+1HyzW26jrl/cjPpK169EnJ4MKs5QcfV+moP61DcE 00zGaKGGlrjZMnIy8m0TWqNhYJGXYTm0/QD1ypttuOPc7PknDeD9Xb7aDz8t/+vst/zM 2gYhGA1trDbGqbi1O2vs8JfuFhL5lRc+NwGFWJVgCj0pjX9hM5s0cEjgi4fgSTuqPNBp o3wCTe8Ri6x1OvSmsVAz11rxf2lKIrV5Sv5br8GwZLH7AjDljb75eijrENh8BsArBYSD lhNQ== X-Gm-Message-State: AOJu0Yyf3/unVNI/uH80Zi724cT9kVDJ2usBSVuPJx0frXOVChOzpch8 u4oENVxeMHVwJWJvBbp+dwCSQDOfGw1ndJllMcWcuo2INwsfP+sPGzn1+x7K+/y+OeppFE9V716 OWKPK1hfyh/AXVgvyRz0H/ofsbJxn9zFlUgU+HgQD/i5+lbez+i76N/01iE9Ns8obFShICMLwUY yfuBvYnu6mq+CHqXh28zIMpKBLGdnIy6GvbL5KSUE= X-Received: by 2002:adf:cb09:0:b0:37c:d179:2f73 with SMTP id ffacd0b85a97d-37ef0b7c8a5mr1907599f8f.13.1729591819405; Tue, 22 Oct 2024 03:10:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHQHeGfJVT36YqLn+DMDNjjXcUGuP1hlqTqi7nBib4PHBCTALP7lJMDW5934aNhKUagchCtcg== X-Received: by 2002:adf:cb09:0:b0:37c:d179:2f73 with SMTP id ffacd0b85a97d-37ef0b7c8a5mr1907579f8f.13.1729591818925; Tue, 22 Oct 2024 03:10:18 -0700 (PDT) Received: from avogadro.local ([151.95.144.54]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37ee0a48882sm6257283f8f.30.2024.10.22.03.10.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Oct 2024 03:10:17 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: berrange@redhat.com, kwolf@redhat.com, junjie.mao@hotmail.com, manos.pitsidianakis@linaro.org Subject: [PATCH v2 05/14] rust: silence unknown warnings for the sake of old compilers Date: Tue, 22 Oct 2024 12:09:46 +0200 Message-ID: <20241022100956.196657-6-pbonzini@redhat.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241022100956.196657-1-pbonzini@redhat.com> References: <20241022100956.196657-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.421, 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=-1.699, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Occasionally, we may need to silence warnings and clippy lints that were only introduced in newer Rust compiler versions. However, this would fail when compiling with an older rustc: error: unknown lint: `non_local_definitions` --> rust/qemu-api/rust-qemu-api-tests.p/structured/offset_of.rs:79:17 So by default we need to block the unknown_lints warning. To avoid misspelled lints or other similar issues, re-enable it in the CI job that uses nightly rust. Signed-off-by: Paolo Bonzini --- meson.build | 8 ++++++++ .gitlab-ci.d/buildtest.yml | 2 +- meson_options.txt | 2 ++ scripts/meson-buildoptions.sh | 4 ++++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 94f30033f68..fe72f9951ca 100644 --- a/meson.build +++ b/meson.build @@ -3327,6 +3327,14 @@ if have_rust and have_system # Prohibit code that is forbidden in Rust 2024 rustc_args += ['-D', 'unsafe_op_in_unsafe_fn'] + # Occasionally, we may need to silence warnings and clippy lints that + # were only introduced in newer Rust compiler versions. Do not croak + # in that case; a CI job with rust_strict_lints == true ensures that + # we do not have misspelled allow() attributes. + if not get_option('strict_rust_lints') + rustc_args += ['-A', 'unknown_lints'] + endif + # Apart from procedural macros, our Rust executables will often link # with C code, so include all the libraries that C code needs. This # is safe; https://github.com/rust-lang/rust/pull/54675 says that diff --git a/.gitlab-ci.d/buildtest.yml b/.gitlab-ci.d/buildtest.yml index 7705000e3cc..4c87f8788d5 100644 --- a/.gitlab-ci.d/buildtest.yml +++ b/.gitlab-ci.d/buildtest.yml @@ -128,7 +128,7 @@ build-system-fedora-rust-nightly: job: amd64-fedora-rust-nightly-container variables: IMAGE: fedora-rust-nightly - CONFIGURE_ARGS: --disable-docs --enable-rust + CONFIGURE_ARGS: --disable-docs --enable-rust --enable-strict-rust-lints TARGETS: aarch64-softmmu MAKE_CHECK_ARGS: check-build allow_failure: true diff --git a/meson_options.txt b/meson_options.txt index 0ee4d7bb86b..e46199a3232 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -376,3 +376,5 @@ option('x86_version', type : 'combo', choices : ['0', '1', '2', '3', '4'], value option('rust', type: 'feature', value: 'disabled', description: 'Rust support') +option('strict_rust_lints', type: 'boolean', value: false, + description: 'Enable stricter set of Rust warnings') diff --git a/scripts/meson-buildoptions.sh b/scripts/meson-buildoptions.sh index 6d08605b771..e898b20307d 100644 --- a/scripts/meson-buildoptions.sh +++ b/scripts/meson-buildoptions.sh @@ -47,6 +47,8 @@ meson_options_help() { printf "%s\n" ' getrandom()' printf "%s\n" ' --enable-safe-stack SafeStack Stack Smash Protection (requires' printf "%s\n" ' clang/llvm and coroutine backend ucontext)' + printf "%s\n" ' --enable-strict-rust-lints' + printf "%s\n" ' Enable stricter set of Rust warnings' printf "%s\n" ' --enable-strip Strip targets on install' printf "%s\n" ' --enable-tcg-interpreter TCG with bytecode interpreter (slow)' printf "%s\n" ' --enable-trace-backends=CHOICES' @@ -490,6 +492,8 @@ _meson_option_parse() { --disable-spice-protocol) printf "%s" -Dspice_protocol=disabled ;; --enable-stack-protector) printf "%s" -Dstack_protector=enabled ;; --disable-stack-protector) printf "%s" -Dstack_protector=disabled ;; + --enable-strict-rust-lints) printf "%s" -Dstrict_rust_lints=true ;; + --disable-strict-rust-lints) printf "%s" -Dstrict_rust_lints=false ;; --enable-strip) printf "%s" -Dstrip=true ;; --disable-strip) printf "%s" -Dstrip=false ;; --sysconfdir=*) quote_sh "-Dsysconfdir=$2" ;; From patchwork Tue Oct 22 10:09:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13845476 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DC931D1CDCB for ; Tue, 22 Oct 2024 10:11:16 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t3Bqb-0004vA-Cl; Tue, 22 Oct 2024 06:10:41 -0400 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 1t3BqZ-0004uS-0T for qemu-devel@nongnu.org; Tue, 22 Oct 2024 06:10:39 -0400 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 1t3BqT-0004Oj-Ti for qemu-devel@nongnu.org; Tue, 22 Oct 2024 06:10:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729591832; 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=p2uLljYjUly9gfbALpWloSBtc6UsfQdEzE6UaHjO4cY=; b=PuMblHEsDrB9zrnXHutJYtRygWmrjGMh9hgVyIpsjT5U/9CSThapiQOplaSjB9bLEFI/Sg DntNyHtpUdFvRgMzCnxlOOs1B8lvNm0I4zbRnuyjy9PGF8bJNkHMvbWF9yi2Ym66wpDJey eGAI+9Rf7WQ+ZaUEwyxLLmWrJxYKPpY= 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-256-g0cZToZgMdytz_4yEQpcYw-1; Tue, 22 Oct 2024 06:10:25 -0400 X-MC-Unique: g0cZToZgMdytz_4yEQpcYw-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4315eaa3189so43705075e9.1 for ; Tue, 22 Oct 2024 03:10:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729591822; x=1730196622; 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=p2uLljYjUly9gfbALpWloSBtc6UsfQdEzE6UaHjO4cY=; b=aSHHihYZfYjAxeA8Af46SeCzB99phFxoVnaJVNyjQPnjYiQxqLXm5QuKkpFYf3JFYc 1f7K6dEoGMLSdINPJkvvgCC7DSWz+rok9KofHabt/k7a1TFAUjfTss03woy4oUAX9usO C+tAfUqfoRYQhXHP1EhN1lq2owgADcXAuRrdia3/UA3Lv+0FhGo0S64Q+MntUga/QLR5 Tk7PSsBjlc7cMOoQz4eIL72b0a1frhWg+6RWavsvN1sIPTjnyeSZZmDR2NpMbcC29c2c mlZzbgStSraeMn6XqH1snX1oCjmIBgoK/R/QJhWYFMdzjE7L2+TgyYG1tz2EdF9Wd1lc x8CA== X-Gm-Message-State: AOJu0YxTd56YCaU1yzxURFsMeRgFD3hgij/08hxRUBL0qkw9XBfbtaWW BfKHWxHKLq4bkt8U1gQUJuyCaB2dlbAckv6gQ8GCxS6F/kFAbrXbL999O2049DvMNwnlUfRyQgh qhAyKcmYLgaFRCSsb8eilB4HbufRT3KvtfKgHpnuf3LmuE0tnP+eCbEHEiKKN+LtNYM0elgpC49 pK1q5dsxyOFdtbcdmAtSseN94SfsYU/0qIiKFG2fE= X-Received: by 2002:a05:600c:5118:b0:431:604d:b22 with SMTP id 5b1f17b1804b1-4316163bcbdmr176850915e9.16.1729591822178; Tue, 22 Oct 2024 03:10:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHHoS9DC1RJMddRt0hU6ZtpdoDQDkvBCdOP19Ectrf7z2F8rSu2CbtI7oaked69XcOYrgiygw== X-Received: by 2002:a05:600c:5118:b0:431:604d:b22 with SMTP id 5b1f17b1804b1-4316163bcbdmr176850465e9.16.1729591821609; Tue, 22 Oct 2024 03:10:21 -0700 (PDT) Received: from avogadro.local ([151.95.144.54]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4316f5711b3sm83295015e9.9.2024.10.22.03.10.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Oct 2024 03:10:21 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: berrange@redhat.com, kwolf@redhat.com, junjie.mao@hotmail.com, manos.pitsidianakis@linaro.org Subject: [PATCH v2 06/14] rust: synchronize dependencies between subprojects and Cargo.lock Date: Tue, 22 Oct 2024 12:09:47 +0200 Message-ID: <20241022100956.196657-7-pbonzini@redhat.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241022100956.196657-1-pbonzini@redhat.com> References: <20241022100956.196657-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=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=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org The next commit will introduce a new build dependency for rust/qemu-api, version_check. Before adding it, ensure that all dependencies are synchronized between the Meson- and cargo-based build systems. Note that it's not clear whether in the long term we'll use Cargo for anything; it seems that the three main uses (clippy, rustfmt, rustdoc) can all be invoked manually---either via glue code in QEMU, or by extending Meson to gain the relevant functionality. However, for the time being we're stuck with Cargo so it should at least look at the same code as the rest of the build system. Signed-off-by: Paolo Bonzini --- rust/hw/char/pl011/Cargo.lock | 5 +++- rust/qemu-api-macros/Cargo.lock | 11 ++++---- rust/qemu-api/Cargo.lock | 49 ++++++++++++++++++++++++++++++++- rust/qemu-api/Cargo.toml | 1 + 4 files changed, 59 insertions(+), 7 deletions(-) diff --git a/rust/hw/char/pl011/Cargo.lock b/rust/hw/char/pl011/Cargo.lock index b58cebb186e..82028ddf793 100644 --- a/rust/hw/char/pl011/Cargo.lock +++ b/rust/hw/char/pl011/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "arbitrary-int" @@ -91,6 +91,9 @@ dependencies = [ [[package]] name = "qemu_api" version = "0.1.0" +dependencies = [ + "qemu_api_macros", +] [[package]] name = "qemu_api_macros" diff --git a/rust/qemu-api-macros/Cargo.lock b/rust/qemu-api-macros/Cargo.lock index fdc0fce116c..779b0ac6a25 100644 --- a/rust/qemu-api-macros/Cargo.lock +++ b/rust/qemu-api-macros/Cargo.lock @@ -1,12 +1,12 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "proc-macro2" -version = "1.0.86" +version = "1.0.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +checksum = "ec96c6a92621310b51366f1e28d05ef11489516e93be030060e5fc12024a49d6" dependencies = [ "unicode-ident", ] @@ -18,6 +18,7 @@ dependencies = [ "proc-macro2", "quote", "syn", + "unicode-ident", ] [[package]] @@ -31,9 +32,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.72" +version = "2.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" dependencies = [ "proc-macro2", "quote", diff --git a/rust/qemu-api/Cargo.lock b/rust/qemu-api/Cargo.lock index e9c51a243a8..468293feedd 100644 --- a/rust/qemu-api/Cargo.lock +++ b/rust/qemu-api/Cargo.lock @@ -1,7 +1,54 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 + +[[package]] +name = "proc-macro2" +version = "1.0.84" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec96c6a92621310b51366f1e28d05ef11489516e93be030060e5fc12024a49d6" +dependencies = [ + "unicode-ident", +] [[package]] name = "qemu_api" version = "0.1.0" +dependencies = [ + "qemu_api_macros", +] + +[[package]] +name = "qemu_api_macros" +version = "0.1.0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "syn" +version = "2.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/rust/qemu-api/Cargo.toml b/rust/qemu-api/Cargo.toml index 3677def3fe2..db594c64083 100644 --- a/rust/qemu-api/Cargo.toml +++ b/rust/qemu-api/Cargo.toml @@ -14,6 +14,7 @@ keywords = [] categories = [] [dependencies] +qemu_api_macros = { path = "../qemu-api-macros" } [features] default = [] From patchwork Tue Oct 22 10:09:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13845484 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8568BD1CDCB for ; Tue, 22 Oct 2024 10:12:13 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t3BqY-0004u6-As; Tue, 22 Oct 2024 06:10:38 -0400 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 1t3BqV-0004tQ-ES for qemu-devel@nongnu.org; Tue, 22 Oct 2024 06:10:35 -0400 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 1t3BqR-0004Od-D9 for qemu-devel@nongnu.org; Tue, 22 Oct 2024 06:10:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729591830; 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=yBchrBlim6aYT5+mpyUWgR4s/JYFs7BD36LJ5gWznMw=; b=dSCVQvNlrzupPWK5p16QOpQhgSo3200hs90D/TbHmY8fd5n/iX2Pigkn1+thNFP3rU+vEn jBUF0bYFkPEr14diQhZxd0shU66StwGq0gq8vPQebiYvf0iGu7vhuaujbj1zvSCZCtYDb7 4HsK5nDpbXuuXs4FBAwlZnwcYfe3x0s= 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-658-g-A0iFiVMOue-11gTz6pIA-1; Tue, 22 Oct 2024 06:10:29 -0400 X-MC-Unique: g-A0iFiVMOue-11gTz6pIA-1 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4315eaa3189so43705645e9.1 for ; Tue, 22 Oct 2024 03:10:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729591827; x=1730196627; 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=yBchrBlim6aYT5+mpyUWgR4s/JYFs7BD36LJ5gWznMw=; b=xAKf4TO8C2tZAkq8NTvS1HOqaFGXsOMiHX9ifv2lxtJGpAT9WhMwyot00sGRcea/xc /UwHuMUm+Z0DwMrIbOsrMHpXOZt5Kv4fsQyZCB4/i6mlnVUg+kpvL/OQW5HoCtcpTIFo ZTv1o83DZ/p6ekrW4zAZDz4VYSQ5aDuxjtW+HSZgCgfLdvuSmkzJY2zNvdPdxxMlalrs /iDiRSO6YZlL3ITt/O5QQxfLJdajYDGDJHuUK0lvaFw6VzK9wtcu8uc3xKo4Mr6U9/6H 7deVGrbjg2ipJ2qulIXvOrw8pZPgbR+fbl/g4hhCv+jLhpNavcF0rnufa/vxeaV5GyPe Z1Pg== X-Gm-Message-State: AOJu0YxvULBZuSHgPb1RAzlAGxlc86RTAXaV6l/aS/sg6W7ORV/m6Toy M45BTGSg+Sl0K8gQZj2Ia2Um2VADrqGJ31KsK7NHKaL5eXVM8MbcYdyJ9nHO+A1w+ir5FdVzEwT 3T1X0YZQFxfaRqbvVgPjR8zlPSY7BqFMAL1jYQRpH+nTRy3M3xhnVN8qOPoBdu+kh20YBl9ENp2 nKcLQ/e52xBM5LyS68C+SytutFYabXfHRkNZgJegQ= X-Received: by 2002:a05:600c:5489:b0:431:24c3:dbaa with SMTP id 5b1f17b1804b1-4316161eeaamr144556885e9.2.1729591827193; Tue, 22 Oct 2024 03:10:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH1SfvfTluFev9BgEl9+dkTmUGHtWKuxlCnQ21W7oWMzQzPNPw8Gl95aBTc/lNhhoSNQAoAOw== X-Received: by 2002:a05:600c:5489:b0:431:24c3:dbaa with SMTP id 5b1f17b1804b1-4316161eeaamr144556545e9.2.1729591826527; Tue, 22 Oct 2024 03:10:26 -0700 (PDT) Received: from avogadro.local ([151.95.144.54]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-431805a8583sm6287055e9.48.2024.10.22.03.10.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Oct 2024 03:10:24 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: berrange@redhat.com, kwolf@redhat.com, junjie.mao@hotmail.com, manos.pitsidianakis@linaro.org Subject: [PATCH v2 07/14] rust: introduce alternative implementation of offset_of! Date: Tue, 22 Oct 2024 12:09:48 +0200 Message-ID: <20241022100956.196657-8-pbonzini@redhat.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241022100956.196657-1-pbonzini@redhat.com> References: <20241022100956.196657-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.421, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Junjie Mao offset_of! was stabilized in Rust 1.77.0. Use an alternative implemenation that was found on the Rust forums, and whose author agreed to license as MIT for use in QEMU. The alternative allows only one level of field access, but apart from this can be used just by replacing core::mem::offset_of! with qemu_api::offset_of!. The actual implementation of offset_of! is done in a declarative macro, but for simplicity and to avoid introducing an extra level of indentation, the trigger is a procedural macro #[derive(offsets)]. Signed-off-by: Junjie Mao Co-developed-by: Paolo Bonzini Signed-off-by: Paolo Bonzini --- rust/hw/char/pl011/Cargo.lock | 1 + rust/hw/char/pl011/src/device.rs | 2 +- rust/qemu-api-macros/Cargo.toml | 5 +- rust/qemu-api-macros/src/lib.rs | 29 +++- rust/qemu-api/Cargo.lock | 7 + rust/qemu-api/Cargo.toml | 6 +- rust/qemu-api/build.rs | 8 + rust/qemu-api/meson.build | 12 +- rust/qemu-api/src/device_class.rs | 8 +- rust/qemu-api/src/lib.rs | 4 + rust/qemu-api/src/offset_of.rs | 161 ++++++++++++++++++ rust/qemu-api/tests/tests.rs | 1 + subprojects/packagefiles/syn-2-rs/meson.build | 1 + 13 files changed, 232 insertions(+), 13 deletions(-) create mode 100644 rust/qemu-api/src/offset_of.rs diff --git a/rust/hw/char/pl011/Cargo.lock b/rust/hw/char/pl011/Cargo.lock index 82028ddf793..087658ca72b 100644 --- a/rust/hw/char/pl011/Cargo.lock +++ b/rust/hw/char/pl011/Cargo.lock @@ -93,6 +93,7 @@ name = "qemu_api" version = "0.1.0" dependencies = [ "qemu_api_macros", + "version_check", ] [[package]] diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs index 5ffe1911376..c26d21e079d 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -29,7 +29,7 @@ pub const PL011_FIFO_DEPTH: usize = 16_usize; #[repr(C)] -#[derive(Debug, qemu_api_macros::Object)] +#[derive(Debug, qemu_api_macros::Object, qemu_api_macros::offsets)] /// PL011 Device Model in QEMU pub struct PL011State { pub parent_obj: SysBusDevice, diff --git a/rust/qemu-api-macros/Cargo.toml b/rust/qemu-api-macros/Cargo.toml index 144cc3650fa..47fec2e4637 100644 --- a/rust/qemu-api-macros/Cargo.toml +++ b/rust/qemu-api-macros/Cargo.toml @@ -19,7 +19,10 @@ proc-macro = true [dependencies] proc-macro2 = "1" quote = "1" -syn = "2" + +[dependencies.syn] +version = "2" +features= ["extra-traits"] # Do not include in any global workspace [workspace] diff --git a/rust/qemu-api-macros/src/lib.rs b/rust/qemu-api-macros/src/lib.rs index a4bc5d01ee8..472264159d6 100644 --- a/rust/qemu-api-macros/src/lib.rs +++ b/rust/qemu-api-macros/src/lib.rs @@ -3,8 +3,8 @@ // SPDX-License-Identifier: GPL-2.0-or-later use proc_macro::TokenStream; -use quote::quote; -use syn::{parse_macro_input, DeriveInput}; +use quote::{quote, quote_spanned}; +use syn::{parse_macro_input, parse_quote, spanned::Spanned, Attribute, DeriveInput}; #[proc_macro_derive(Object)] pub fn derive_object(input: TokenStream) -> TokenStream { @@ -21,3 +21,28 @@ pub fn derive_object(input: TokenStream) -> TokenStream { TokenStream::from(expanded) } + +#[proc_macro_derive(offsets)] +pub fn derive_offsets(input: TokenStream) -> TokenStream { + let input = parse_macro_input!(input as DeriveInput); + let repr_c: Attribute = parse_quote! { #[repr(C)] }; + + // All the work for expanding this macro is done in "with_offsets!", + // a macro in the qemu_api crate which re-parses the struct declaration; + // this derive macro is just a convenience. + // + // The with_offsets! macro expands to nothing if the compiler is new enough + // to have a stable offset_of. + let expanded = if !input.attrs.iter().any(|x| *x == repr_c) { + quote_spanned! { + input.span() => + compile_error!("expected #[repr(C)] together with #[derive(offsets)]"); + } + } else { + quote! { + ::qemu_api::with_offsets! { #input } + } + }; + + TokenStream::from(expanded) +} diff --git a/rust/qemu-api/Cargo.lock b/rust/qemu-api/Cargo.lock index 468293feedd..371c6167918 100644 --- a/rust/qemu-api/Cargo.lock +++ b/rust/qemu-api/Cargo.lock @@ -16,6 +16,7 @@ name = "qemu_api" version = "0.1.0" dependencies = [ "qemu_api_macros", + "version_check", ] [[package]] @@ -52,3 +53,9 @@ name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" diff --git a/rust/qemu-api/Cargo.toml b/rust/qemu-api/Cargo.toml index db594c64083..9c3a99522a9 100644 --- a/rust/qemu-api/Cargo.toml +++ b/rust/qemu-api/Cargo.toml @@ -16,6 +16,9 @@ categories = [] [dependencies] qemu_api_macros = { path = "../qemu-api-macros" } +[build-dependencies] +version_check = "~0.9" + [features] default = [] allocator = [] @@ -24,4 +27,5 @@ allocator = [] [workspace] [lints.rust] -unexpected_cfgs = { level = "warn", check-cfg = ['cfg(MESON)', 'cfg(HAVE_GLIB_WITH_ALIGNED_ALLOC)'] } +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(MESON)', 'cfg(HAVE_GLIB_WITH_ALIGNED_ALLOC)', + 'cfg(has_offset_of)'] } diff --git a/rust/qemu-api/build.rs b/rust/qemu-api/build.rs index 419b154c2d2..0a68c3712f1 100644 --- a/rust/qemu-api/build.rs +++ b/rust/qemu-api/build.rs @@ -3,6 +3,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later use std::path::Path; +use version_check as rustc; fn main() { if !Path::new("src/bindings.rs").exists() { @@ -11,4 +12,11 @@ fn main() { (`ninja bindings.rs`) and copy them to src/bindings.rs, or build through meson." ); } + + // Check for available rustc features + if rustc::is_min_version("1.77.0").unwrap_or(false) { + println!("cargo:rustc-cfg=has_offset_of"); + } + + println!("cargo:rerun-if-changed=build.rs"); } diff --git a/rust/qemu-api/meson.build b/rust/qemu-api/meson.build index 2b3dea59fb6..4ac33acced3 100644 --- a/rust/qemu-api/meson.build +++ b/rust/qemu-api/meson.build @@ -1,3 +1,9 @@ +_qemu_api_cfg = ['--cfg', 'MESON'] +# _qemu_api_cfg += ['--cfg', 'feature="allocator"'] +if rustc.version().version_compare('>=1.77.0') + _qemu_api_cfg += ['--cfg', 'has_offset_of'] +endif + _qemu_api_rs = static_library( 'qemu_api', structured_sources( @@ -6,16 +12,14 @@ _qemu_api_rs = static_library( 'src/c_str.rs', 'src/definitions.rs', 'src/device_class.rs', + 'src/offset_of.rs', 'src/zeroable.rs', ], {'.' : bindings_rs}, ), override_options: ['rust_std=2021', 'build.rust_std=2021'], rust_abi: 'rust', - rust_args: [ - '--cfg', 'MESON', - # '--cfg', 'feature="allocator"', - ], + rust_args: _qemu_api_cfg, ) rust.test('rust-qemu-api-tests', _qemu_api_rs, diff --git a/rust/qemu-api/src/device_class.rs b/rust/qemu-api/src/device_class.rs index 5c305d945d3..ce3d5f50507 100644 --- a/rust/qemu-api/src/device_class.rs +++ b/rust/qemu-api/src/device_class.rs @@ -23,23 +23,23 @@ macro_rules! device_class_init { #[macro_export] macro_rules! define_property { - ($name:expr, $state:ty, $field:expr, $prop:expr, $type:expr, default = $defval:expr$(,)*) => { + ($name:expr, $state:ty, $field:ident, $prop:expr, $type:expr, default = $defval:expr$(,)*) => { $crate::bindings::Property { // use associated function syntax for type checking name: ::std::ffi::CStr::as_ptr($name), info: $prop, - offset: ::core::mem::offset_of!($state, $field) as isize, + offset: $crate::offset_of!($state, $field) as isize, set_default: true, defval: $crate::bindings::Property__bindgen_ty_1 { u: $defval.into() }, ..$crate::zeroable::Zeroable::ZERO } }; - ($name:expr, $state:ty, $field:expr, $prop:expr, $type:expr$(,)*) => { + ($name:expr, $state:ty, $field:ident, $prop:expr, $type:expr$(,)*) => { $crate::bindings::Property { // use associated function syntax for type checking name: ::std::ffi::CStr::as_ptr($name), info: $prop, - offset: ::core::mem::offset_of!($state, $field) as isize, + offset: $crate::offset_of!($state, $field) as isize, set_default: false, ..$crate::zeroable::Zeroable::ZERO } diff --git a/rust/qemu-api/src/lib.rs b/rust/qemu-api/src/lib.rs index 9c3be4f6489..92f1785d891 100644 --- a/rust/qemu-api/src/lib.rs +++ b/rust/qemu-api/src/lib.rs @@ -30,6 +30,7 @@ unsafe impl Sync for bindings::VMStateDescription {} pub mod c_str; pub mod definitions; pub mod device_class; +pub mod offset_of; pub mod zeroable; use std::{ @@ -166,3 +167,6 @@ unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) { } } } + +#[cfg(has_offset_of)] +pub use std::mem::offset_of; diff --git a/rust/qemu-api/src/offset_of.rs b/rust/qemu-api/src/offset_of.rs new file mode 100644 index 00000000000..87db8607592 --- /dev/null +++ b/rust/qemu-api/src/offset_of.rs @@ -0,0 +1,161 @@ +// SPDX-License-Identifier: MIT + +/// This macro provides the same functionality as `core::mem::offset_of`, +/// except that only one level of field access is supported. The declaration +/// of the struct must be wrapped with `with_offsets! { }`. +/// +/// It is needed because `offset_of!` was only stabilized in Rust 1.77. +#[cfg(not(has_offset_of))] +#[macro_export] +macro_rules! offset_of { + ($Container:ty, $field:ident) => { + <$Container>::OFFSET_TO__.$field + }; +} + +/// A wrapper for struct declarations, that allows using `offset_of!` in +/// versions of Rust prior to 1.77 +#[macro_export] +macro_rules! with_offsets { + // This method to generate field offset constants comes from: + // + // https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=10a22a9b8393abd7b541d8fc844bc0df + // + // used under MIT license with permission of Yandros aka Daniel Henry-Mantilla + ( + $(#[$struct_meta:meta])* + $struct_vis:vis + struct $StructName:ident { + $( + $(#[$field_meta:meta])* + $field_vis:vis + $field_name:ident : $field_ty:ty + ),* + $(,)? + } + ) => ( + #[cfg(not(has_offset_of))] + const _: () = { + struct StructOffsetsHelper(std::marker::PhantomData); + const END_OF_PREV_FIELD: usize = 0; + + // populate StructOffsetsHelper with associated consts, + // one for each field + $crate::with_offsets! { + @struct $StructName + @names [ $($field_name)* ] + @tys [ $($field_ty ,)*] + } + + // now turn StructOffsetsHelper's consts into a single struct, + // applying field visibility. This provides better error messages + // than if offset_of! used StructOffsetsHelper:: directly. + pub + struct StructOffsets { + $( + $field_vis + $field_name: usize, + )* + } + impl $StructName { + pub + const OFFSET_TO__: StructOffsets = StructOffsets { + $( + $field_name: StructOffsetsHelper::<$StructName>::$field_name, + )* + }; + } + }; + ); + + ( + @struct $StructName:ident + @names [] + @tys [] + ) => (); + + ( + @struct $StructName:ident + @names [$field_name:ident $($other_names:tt)*] + @tys [$field_ty:ty , $($other_tys:tt)*] + ) => ( + #[allow(non_local_definitions)] + #[allow(clippy::modulo_one)] + impl StructOffsetsHelper<$StructName> { + #[allow(nonstandard_style)] + const $field_name: usize = { + const ALIGN: usize = std::mem::align_of::<$field_ty>(); + const TRAIL: usize = END_OF_PREV_FIELD % ALIGN; + END_OF_PREV_FIELD + (if TRAIL == 0 { 0usize } else { ALIGN - TRAIL }) + }; + } + const _: () = { + const END_OF_PREV_FIELD: usize = + StructOffsetsHelper::<$StructName>::$field_name + + std::mem::size_of::<$field_ty>() + ; + $crate::with_offsets! { + @struct $StructName + @names [$($other_names)*] + @tys [$($other_tys)*] + } + }; + ); +} + +#[cfg(test)] +mod tests { + use crate::offset_of; + + #[repr(C)] + struct Foo { + a: u16, + b: u32, + c: u64, + d: u16, + } + + #[repr(C)] + struct Bar { + pub a: u16, + pub b: u64, + c: Foo, + d: u64, + } + + crate::with_offsets! { + #[repr(C)] + struct Bar { + pub a: u16, + pub b: u64, + c: Foo, + d: u64, + } + } + + #[repr(C)] + pub struct Baz { + b: u32, + a: u8, + } + crate::with_offsets! { + #[repr(C)] + pub struct Baz { + b: u32, + a: u8, + } + } + + #[test] + fn test_offset_of() { + const OFFSET_TO_C: usize = offset_of!(Bar, c); + + assert_eq!(offset_of!(Bar, a), 0); + assert_eq!(offset_of!(Bar, b), 8); + assert_eq!(OFFSET_TO_C, 16); + assert_eq!(offset_of!(Bar, d), 40); + + assert_eq!(offset_of!(Baz, b), 0); + assert_eq!(offset_of!(Baz, a), 4); + } +} diff --git a/rust/qemu-api/tests/tests.rs b/rust/qemu-api/tests/tests.rs index 605bc99ed4c..96e413b75ee 100644 --- a/rust/qemu-api/tests/tests.rs +++ b/rust/qemu-api/tests/tests.rs @@ -20,6 +20,7 @@ fn test_device_decl_macros() { unmigratable: true, } + #[derive(qemu_api_macros::offsets)] #[repr(C)] #[derive(qemu_api_macros::Object)] pub struct DummyState { diff --git a/subprojects/packagefiles/syn-2-rs/meson.build b/subprojects/packagefiles/syn-2-rs/meson.build index a53335f3092..9f56ce1c24d 100644 --- a/subprojects/packagefiles/syn-2-rs/meson.build +++ b/subprojects/packagefiles/syn-2-rs/meson.build @@ -24,6 +24,7 @@ _syn_rs = static_library( '--cfg', 'feature="printing"', '--cfg', 'feature="clone-impls"', '--cfg', 'feature="proc-macro"', + '--cfg', 'feature="extra-traits"', ], dependencies: [ quote_dep, From patchwork Tue Oct 22 10:09:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13845485 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 93FCCD1CDD0 for ; Tue, 22 Oct 2024 10:12:15 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t3Bqa-0004uo-8d; Tue, 22 Oct 2024 06:10:40 -0400 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 1t3BqW-0004tX-II for qemu-devel@nongnu.org; Tue, 22 Oct 2024 06:10:36 -0400 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 1t3BqU-0004Oo-1t for qemu-devel@nongnu.org; Tue, 22 Oct 2024 06:10:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729591833; 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=03JiRCmWWZh2jJskiShZoJxz/aHC3ZzZOgP/wBs0hjc=; b=Nlrbu5pC3o1CQQDM1AxBB3wvtQq+3+z2DHy79F95PusgjSb0v1oVIm4toEp+eVile8yNGh REEBjwnLk4JMucsBt9NwSaYIoYlX3+B+EXaN/9RHKPsjYSTPNACljnB9a4LE/n5W8Ap26W IdAhpkUF5tpuuim3OUNqhND/3Bi+/oM= 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-375-7AElOKDfPgqeNM6EwSfBVg-1; Tue, 22 Oct 2024 06:10:32 -0400 X-MC-Unique: 7AElOKDfPgqeNM6EwSfBVg-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4315dd8fe7fso45269605e9.3 for ; Tue, 22 Oct 2024 03:10:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729591830; x=1730196630; 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=03JiRCmWWZh2jJskiShZoJxz/aHC3ZzZOgP/wBs0hjc=; b=OMq8sbhg8tIYclb4jYBZqdTJq0wBxPnRFq4e5JY8eIzO/tQeP3EQ7Wi4SC2otjiufx pmjwxcLRvstPRqdZY7OwSc8dijolNp/FzTfEoDYyVEnX1i9Niz40VkUC9H9K/CwXmAA3 Al26X6fVe3ozdooF+CgzsvT1CqT+3qvVEpz2jGrdtJY6u+vnCHrdtqLwt2RnA7RStjux HrVRg2zmuHkHvtco2qflsdZMisZVtdVAWHrs7DLE/5ZBmxShteMrW2sYCHfPgoWihpUf ZGekIgxHZEnzAbteQhFHeXlp6KFIIgabdevXINqG4dgyItZIhOVFBupiKJDZK1Spna/R MuoQ== X-Gm-Message-State: AOJu0Yydu1E2ZUD749mqxd/NdLHiF8Z2y8ZST+nZk7kNAakRtYkXjH6z hpC0R/L2V2sPMQXpsVJ89zCrQjnpdkrYwRHK6KwVKld66e2m27EIdigPXC9LlQcBPJC/pPyB5Y9 ou/J3D40sjUaD2FfM1AwDJrg7sHG/jWYomAzmCCodseSkergPxa8TDM4dc8SZMBQXmZWyFGP0Rx z12Veg8D0xy2yCJlejeHNtnXsx85X2U8eIc3kU2hM= X-Received: by 2002:a05:600c:6747:b0:431:5ba1:a520 with SMTP id 5b1f17b1804b1-4316161ef0bmr156590505e9.3.1729591830088; Tue, 22 Oct 2024 03:10:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHeXIzdAkgD/irfpaEYUIV1U1m1yqe+mtDkoib8cYmNAUb4ZS087N2QLxFwDJ4XbqUxXSPPVg== X-Received: by 2002:a05:600c:6747:b0:431:5ba1:a520 with SMTP id 5b1f17b1804b1-4316161ef0bmr156590225e9.3.1729591829637; Tue, 22 Oct 2024 03:10:29 -0700 (PDT) Received: from avogadro.local ([151.95.144.54]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4316f5cc183sm83173315e9.40.2024.10.22.03.10.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Oct 2024 03:10:28 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: berrange@redhat.com, kwolf@redhat.com, junjie.mao@hotmail.com, manos.pitsidianakis@linaro.org Subject: [PATCH v2 08/14] rust: do not use MaybeUninit::zeroed() Date: Tue, 22 Oct 2024 12:09:49 +0200 Message-ID: <20241022100956.196657-9-pbonzini@redhat.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241022100956.196657-1-pbonzini@redhat.com> References: <20241022100956.196657-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.421, 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=-1.699, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org MaybeUninit::zeroed() is handy is not available as a "const" function until Rust 1.75.0. Remove the default implemntation of Zeroable::ZERO, and write by hand the definitions for those types that need it. It may be possible to add automatic implementation of the trait, via a procedural macro and/or a trick similar to offset_of!, but do it the easy way for now. Signed-off-by: Paolo Bonzini --- rust/qemu-api/src/zeroable.rs | 91 +++++++++++++++++++++++++++++------ 1 file changed, 77 insertions(+), 14 deletions(-) diff --git a/rust/qemu-api/src/zeroable.rs b/rust/qemu-api/src/zeroable.rs index 45ec95c9f70..13cdb2ccba5 100644 --- a/rust/qemu-api/src/zeroable.rs +++ b/rust/qemu-api/src/zeroable.rs @@ -1,23 +1,86 @@ // SPDX-License-Identifier: GPL-2.0-or-later +use std::ptr; + /// Encapsulates the requirement that -/// `MaybeUninit::::zeroed().assume_init()` does not cause -/// undefined behavior. +/// `MaybeUninit::::zeroed().assume_init()` does not cause undefined +/// behavior. This trait in principle could be implemented as just: +/// +/// ``` +/// const ZERO: Self = unsafe { +/// ::core::mem::MaybeUninit::<$crate::bindings::Property>::zeroed().assume_init() +/// }, +/// ``` +/// +/// The need for a manual implementation is only because `zeroed()` cannot +/// be used as a `const fn` prior to Rust 1.75.0. Once we can assume a new +/// enough version of the compiler, we could provide a `#[derive(Zeroable)]` +/// macro to check at compile-time that all struct fields are Zeroable, and +/// use the above blanket implementation of the `ZERO` constant. /// /// # Safety /// -/// Do not add this trait to a type unless all-zeroes is -/// a valid value for the type. In particular, remember that raw -/// pointers can be zero, but references and `NonNull` cannot -/// unless wrapped with `Option<>`. +/// Because the implementation of `ZERO` is manual, it does not make +/// any assumption on the safety of `zeroed()`. However, other users of the +/// trait could use it that way. Do not add this trait to a type unless +/// all-zeroes is a valid value for the type. In particular, remember that +/// raw pointers can be zero, but references and `NonNull` cannot pub unsafe trait Zeroable: Default { - /// SAFETY: If the trait was added to a type, then by definition - /// this is safe. - const ZERO: Self = unsafe { ::core::mem::MaybeUninit::::zeroed().assume_init() }; + const ZERO: Self; } -unsafe impl Zeroable for crate::bindings::Property__bindgen_ty_1 {} -unsafe impl Zeroable for crate::bindings::Property {} -unsafe impl Zeroable for crate::bindings::VMStateDescription {} -unsafe impl Zeroable for crate::bindings::MemoryRegionOps__bindgen_ty_1 {} -unsafe impl Zeroable for crate::bindings::MemoryRegionOps__bindgen_ty_2 {} +unsafe impl Zeroable for crate::bindings::Property__bindgen_ty_1 { + const ZERO: Self = Self { i: 0 }; +} + +unsafe impl Zeroable for crate::bindings::Property { + const ZERO: Self = Self { + name: ptr::null(), + info: ptr::null(), + offset: 0, + bitnr: 0, + bitmask: 0, + set_default: false, + defval: Zeroable::ZERO, + arrayoffset: 0, + arrayinfo: ptr::null(), + arrayfieldsize: 0, + link_type: ptr::null(), + }; +} + +unsafe impl Zeroable for crate::bindings::VMStateDescription { + const ZERO: Self = Self { + name: ptr::null(), + unmigratable: false, + early_setup: false, + version_id: 0, + minimum_version_id: 0, + priority: crate::bindings::MigrationPriority::MIG_PRI_DEFAULT, + pre_load: None, + post_load: None, + pre_save: None, + post_save: None, + needed: None, + dev_unplug_pending: None, + fields: ptr::null(), + subsections: ptr::null(), + }; +} + +unsafe impl Zeroable for crate::bindings::MemoryRegionOps__bindgen_ty_1 { + const ZERO: Self = Self { + min_access_size: 0, + max_access_size: 0, + unaligned: false, + accepts: None, + }; +} + +unsafe impl Zeroable for crate::bindings::MemoryRegionOps__bindgen_ty_2 { + const ZERO: Self = Self { + min_access_size: 0, + max_access_size: 0, + unaligned: false, + }; +} From patchwork Tue Oct 22 10:09:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13845480 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5737DD1CDD0 for ; Tue, 22 Oct 2024 10:11:40 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t3Bqb-0004uv-3h; Tue, 22 Oct 2024 06:10:41 -0400 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 1t3BqZ-0004uT-0W for qemu-devel@nongnu.org; Tue, 22 Oct 2024 06:10:39 -0400 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 1t3BqX-0004P4-8p for qemu-devel@nongnu.org; Tue, 22 Oct 2024 06:10:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729591836; 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=8J+8xZYPHbr72c/IJr5xzYf68Dz55JZJUDo+rchRnfs=; b=BWafTN9ooCu3Q8HwEY3llSWVzmktRORBy9JuRoQG5KsX6vNVasabn+GSplXi4nazB/vOWz Ryp1KgecSWRdF2IX1CeWu268eFmyJ7DQNapqD+hbeF/lqdMZfdSgyLAVYeQTCgUkdQ+tUZ RzNXNc4I2QMmPHNL08d8Rc7/WKY3IVo= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-575-fSTsnomuNvqtEb2DW1GSZA-1; Tue, 22 Oct 2024 06:10:35 -0400 X-MC-Unique: fSTsnomuNvqtEb2DW1GSZA-1 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-37d49887a2cso3024973f8f.0 for ; Tue, 22 Oct 2024 03:10:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729591833; x=1730196633; 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=8J+8xZYPHbr72c/IJr5xzYf68Dz55JZJUDo+rchRnfs=; b=Xqo7lzCHwB8R8I4Qwnp60oeIaUbOfaWjTv9iJOXNyywushUHvKpZBMrNLi3V0X5ne/ 6eqctI+qYOWQzCqv7sTTWOAC6hTd/rqOIKP+6m5q/GW6b58tWaOk7g9rGmq783PDfCRA uYwRhoD0p+VpXHGMVHkwTBNnpVudfS14EWzf4vguZwm7A/TfMxBe3Lkr9ianbTLAKB0D 9aEooh8YcAg/Xz8vjf4LZL/+1FoGPAx/QiWaQWQBiihzbJ8zT2V+jFMyH4q8F9JcMGMD DKjgA6z/NEKNLzYN+nj1Ta6c9blzuEXK5Nek5PpQ/tUP1i7e8Vxa+wvvi7XUG9c4kx1v mrcw== X-Gm-Message-State: AOJu0YzYpFEugLIFLLz73OQCoHyxSHa+YhYVUQCYyC/KDlrd9EQz7mka AzRhxCraQqLlkOW9ss5AZjsACJKoDAjnvKOM42IZXluTsPK8W9bh34JJXNKF3+KCm5PkblsQhgA e2IPJLsIKi524j+nYrSD9BgStI7AwvW8/yLEkF+M+OZlCxyF6xt/NWA8OjbEJKjceyvlGqmrICs DejmFVV4LyOFSothBYIC4GDt9laD1RkygUqnpyprc= X-Received: by 2002:a05:6000:4388:b0:378:8b56:4665 with SMTP id ffacd0b85a97d-37ef12c8531mr1556434f8f.24.1729591833455; Tue, 22 Oct 2024 03:10:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHCu/q/XeHdz46UNT7zYQqEGMXcEYMCfCQgwfVFqVhd8DBg290J5LEF3gXAVmH5PiePmhyung== X-Received: by 2002:a05:6000:4388:b0:378:8b56:4665 with SMTP id ffacd0b85a97d-37ef12c8531mr1556406f8f.24.1729591832855; Tue, 22 Oct 2024 03:10:32 -0700 (PDT) Received: from avogadro.local ([151.95.144.54]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37ee0a4ac2esm6272449f8f.44.2024.10.22.03.10.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Oct 2024 03:10:31 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: berrange@redhat.com, kwolf@redhat.com, junjie.mao@hotmail.com, manos.pitsidianakis@linaro.org Subject: [PATCH v2 09/14] rust: clean up detection of the language Date: Tue, 22 Oct 2024 12:09:50 +0200 Message-ID: <20241022100956.196657-10-pbonzini@redhat.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241022100956.196657-1-pbonzini@redhat.com> References: <20241022100956.196657-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.421, 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=-1.699, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Disable the detection code altogether if have_system == false. Signed-off-by: Paolo Bonzini --- meson.build | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/meson.build b/meson.build index fe72f9951ca..e411a8ae567 100644 --- a/meson.build +++ b/meson.build @@ -53,6 +53,17 @@ cpu = host_machine.cpu_family() target_dirs = config_host['TARGET_DIRS'].split() +# type of binaries to build +have_linux_user = false +have_bsd_user = false +have_system = false +foreach target : target_dirs + have_linux_user = have_linux_user or target.endswith('linux-user') + have_bsd_user = have_bsd_user or target.endswith('bsd-user') + have_system = have_system or target.endswith('-softmmu') +endforeach +have_user = have_linux_user or have_bsd_user + ############ # Programs # ############ @@ -71,11 +82,13 @@ if host_os == 'darwin' and \ all_languages += ['objc'] objc = meson.get_compiler('objc') endif -have_rust = false -if not get_option('rust').disabled() and add_languages('rust', required: get_option('rust'), native: false) \ - and add_languages('rust', required: get_option('rust'), native: true) + +have_rust = add_languages('rust', native: false, + required: get_option('rust').disable_auto_if(not have_system)) +have_rust = have_rust and add_languages('rust', native: true, + required: get_option('rust').disable_auto_if(not have_system)) +if have_rust rustc = meson.get_compiler('rust') - have_rust = true if rustc.version().version_compare('<1.80.0') if get_option('rust').enabled() error('rustc version ' + rustc.version() + ' is unsupported: Please upgrade to at least 1.80.0') @@ -186,17 +199,6 @@ have_vhost_net_vdpa = have_vhost_vdpa and get_option('vhost_net').allowed() have_vhost_net_kernel = have_vhost_kernel and get_option('vhost_net').allowed() have_vhost_net = have_vhost_net_kernel or have_vhost_net_user or have_vhost_net_vdpa -# type of binaries to build -have_linux_user = false -have_bsd_user = false -have_system = false -foreach target : target_dirs - have_linux_user = have_linux_user or target.endswith('linux-user') - have_bsd_user = have_bsd_user or target.endswith('bsd-user') - have_system = have_system or target.endswith('-softmmu') -endforeach -have_user = have_linux_user or have_bsd_user - have_tools = get_option('tools') \ .disable_auto_if(not have_system) \ .allowed() @@ -3317,7 +3319,7 @@ endif genh += configure_file(output: 'config-host.h', configuration: config_host_data) -if have_rust and have_system +if have_rust rustc_args = run_command( find_program('scripts/rust/rustc_args.py'), '--config-headers', meson.project_build_root() / 'config-host.h', @@ -3937,7 +3939,7 @@ common_all = static_library('common', implicit_include_directories: false, dependencies: common_ss.all_dependencies()) -if have_rust and have_system +if have_rust bindgen_args = [ '--disable-header-comment', '--raw-line', '// @generated', @@ -4091,7 +4093,7 @@ foreach target : target_dirs arch_srcs += target_specific.sources() arch_deps += target_specific.dependencies() - if have_rust and have_system + if have_rust and target_type == 'system' target_rust = rust_devices_ss.apply(config_target, strict: false) crates = [] foreach dep : target_rust.dependencies() @@ -4453,9 +4455,9 @@ else endif summary_info += {'Rust support': have_rust} if have_rust - summary_info += {'rustc version': rustc.version()} - summary_info += {'rustc': ' '.join(rustc.cmd_array())} summary_info += {'Rust target': config_host['RUST_TARGET_TRIPLE']} + summary_info += {'rustc': ' '.join(rustc.cmd_array())} + summary_info += {'rustc version': rustc.version()} endif option_cflags = (get_option('debug') ? ['-g'] : []) if get_option('optimization') != 'plain' From patchwork Tue Oct 22 10:09:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13845477 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E5D6DD1CDCF for ; Tue, 22 Oct 2024 10:11:24 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t3Bqf-000520-Nl; Tue, 22 Oct 2024 06:10:45 -0400 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 1t3Bqc-0004vG-K2 for qemu-devel@nongnu.org; Tue, 22 Oct 2024 06:10:43 -0400 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 1t3Bqa-0004PU-SM for qemu-devel@nongnu.org; Tue, 22 Oct 2024 06:10:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729591840; 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=PBRhOELsRn9xQQiWxQ4MS4Iao+woVuEtGdzYywQ/DGE=; b=dx3RbDRXRWrW6XfS7FdVBurOht5OK9uDrLYVcuJe83ZQEcmDl6rS0O/l7ScYvYuRopx1/l DJGvKALZrEwDMvNF8vkPfslKvX1VlbnrBwsRjYAeHlvA2/WKMOewpDEBx8zlkAzkzlLZbp lQsQ+iJC2tMqgTR9xjZ1KBXalgiXPf8= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-651-oYG8AMCJMEi8EQj7rbhQ_Q-1; Tue, 22 Oct 2024 06:10:38 -0400 X-MC-Unique: oYG8AMCJMEi8EQj7rbhQ_Q-1 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-37d49887a2cso3024991f8f.0 for ; Tue, 22 Oct 2024 03:10:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729591837; x=1730196637; 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=PBRhOELsRn9xQQiWxQ4MS4Iao+woVuEtGdzYywQ/DGE=; b=mTGBcSk6/qNaFqVWLG7YF+Wzro343smYVnKErSi8B5Zo5VKN2qjcQDadcRKjvnIzOp m0bIdvQs5wylvyftA5ES4OGeb84Igqv+sz4me0G3Xpel7tV/5oF2QlfPFLwCU4mtCEug snTSoc/pnoanBqOMztU0+tI1gMKOCopyQGXqXZyCNZlCBjcuO/1C3P6BW8kasWhzdqjq FuwGQFQSIIGtyAuszWN5dokM8w12/1qzdiM2LtN4onkF7ZQCvP9FmlCVazDXbNyh8Hgx DuE1zZ8zP+crmHt5omitaPOy2PzqBTTjFGOVk0zt/tsE7jIR1xq+RF5p97TLZsc/1ev7 R+0g== X-Gm-Message-State: AOJu0YyrdrUmmzhKuco3MsrMbn6xDLyBDvkEnX/rLckWZyQcLyEUf/+6 gp0l6V+LFEmCu/dY/5eJ5Lo31NAS2frFlxM5qRVp5McGZohXaRvZqO6UkHUNxh7xyf/jHnjr8QQ z3BHQlg1tUV3shcOlKQuBPv/hv6d9H/UYcLzQY/+ZHTLU7w24y05lhMmc7Gn8AmiskexMNO1QfG xJhyDWhhNNLzbT1M+FD47g+/PQTnOlCjtXwgx/L/g= X-Received: by 2002:adf:e54c:0:b0:371:6fc7:d45d with SMTP id ffacd0b85a97d-37ef1263b35mr1699932f8f.2.1729591837111; Tue, 22 Oct 2024 03:10:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGMglMYBxnOmMQKOThNtR81vbuaOXQHUSglgnAY0h0XMLxiJLA1jMKp4WiYGoFYzWmn9H79nw== X-Received: by 2002:adf:e54c:0:b0:371:6fc7:d45d with SMTP id ffacd0b85a97d-37ef1263b35mr1699916f8f.2.1729591836675; Tue, 22 Oct 2024 03:10:36 -0700 (PDT) Received: from avogadro.local ([151.95.144.54]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37ee0a487bdsm6312221f8f.32.2024.10.22.03.10.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Oct 2024 03:10:35 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: berrange@redhat.com, kwolf@redhat.com, junjie.mao@hotmail.com, manos.pitsidianakis@linaro.org Subject: [PATCH v2 10/14] rust: allow version 1.63.0 of rustc Date: Tue, 22 Oct 2024 12:09:51 +0200 Message-ID: <20241022100956.196657-11-pbonzini@redhat.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241022100956.196657-1-pbonzini@redhat.com> References: <20241022100956.196657-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.421, 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=-1.699, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org All constructs introduced by newer versions of Rust have been removed. Apart from Debian 12, all other supported Linux distributions have rustc 1.75.0 or newer. This means that they only lack c"" literals and stable offset_of!. Signed-off-by: Paolo Bonzini --- meson.build | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/meson.build b/meson.build index e411a8ae567..9c57d7e5c6d 100644 --- a/meson.build +++ b/meson.build @@ -89,11 +89,12 @@ have_rust = have_rust and add_languages('rust', native: true, required: get_option('rust').disable_auto_if(not have_system)) if have_rust rustc = meson.get_compiler('rust') - if rustc.version().version_compare('<1.80.0') + if rustc.version().version_compare('<1.63.0') if get_option('rust').enabled() - error('rustc version ' + rustc.version() + ' is unsupported: Please upgrade to at least 1.80.0') + error('rustc version ' + rustc.version() + ' is unsupported. Please upgrade to at least 1.63.0') else - warning('rustc version ' + rustc.version() + ' is unsupported: Disabling Rust compilation. Please upgrade to at least 1.80.0 to use Rust.') + warning('rustc version ' + rustc.version() + ' is unsupported, disabling Rust compilation.') + message('Please upgrade to at least 1.63.0 to use Rust.') have_rust = false endif endif From patchwork Tue Oct 22 10:09:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13845479 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A2826D1CDCB for ; Tue, 22 Oct 2024 10:11:39 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t3Bqk-00055e-8H; Tue, 22 Oct 2024 06:10:50 -0400 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 1t3Bqh-00053E-28 for qemu-devel@nongnu.org; Tue, 22 Oct 2024 06:10:47 -0400 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 1t3Bqf-0004Pl-0Y for qemu-devel@nongnu.org; Tue, 22 Oct 2024 06:10:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729591844; 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=biLPxyuTmYjTQwz6O/sjJWtUJX+CBzOfsRAa2TZ+E2U=; b=Rbk4qHFsRDolWbEeF5kirzGT5VZIe484WSWZYTO/9stZbF8B0taCGT+syesrWrdVT5I0k9 9a1VwC1CF19L9GB9MuPa8Di0bRbnchpJi7L+hixXIMHnqm35eAT/Lui4jvOfXr1LW4Q/jW lKgp9qlqmMJnGC7rlhHCHEgpf8cexzU= Received: from mail-lf1-f70.google.com (mail-lf1-f70.google.com [209.85.167.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-356-zgRU7B9SNaC5VoTaDkKawA-1; Tue, 22 Oct 2024 06:10:42 -0400 X-MC-Unique: zgRU7B9SNaC5VoTaDkKawA-1 Received: by mail-lf1-f70.google.com with SMTP id 2adb3069b0e04-539ed93e08aso4018331e87.3 for ; Tue, 22 Oct 2024 03:10:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729591840; x=1730196640; 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=biLPxyuTmYjTQwz6O/sjJWtUJX+CBzOfsRAa2TZ+E2U=; b=ke5+UTcSW3H66cfdLX7H3ja1yW3HCBbtoF6RfoHVw9MJYM1DAGkqhEUgtea2h6ZGWX tcT4xIO3WEuPElMDaE3j0LYGryu/sVWZcpK7Ol8KTuYryCDwK0La0bXDFMD4mM4P0Tjn ifYDICXesbJ3O6DpSqjUvQKvhmSITEPqnoJSWSIpRyCOybucGiXjBb1NCaFiOQsuq9TU kT0Al5NFM0q8AN0c3W+d9lfmjwTKncNzdFUmsqEgklJvtL0/UVQOOL+Kclw0UGyvmolS gsbxxTWsFzwyIXv87G1BZzkQWEo7ITNYMo4OCIKlO03eJfHLmGV+Oz3+T28hw1fktRas uROg== X-Gm-Message-State: AOJu0YxKdAPtz7Xj6o0dDfandLTl5U4pzkwY0m/e63HVKoCjFspmZ4xY Y8ZfPIvIu9u8NiZEMdNsCACDUUlDfJvigZIzZnfS5T2LAcvsPSRmkQwb1THgmRpqnXux88Tt/BW EijOhDDMT5HRWUO/Zsz+rZG9+j3sYckdlycLdRo9d04Ob04CbggwQ1IZee0TZZWcAvig3MMUhXy AWyt4end9EyJX/NuBcTfQD08W75/77tWh8PDL11jg= X-Received: by 2002:a05:6512:2207:b0:539:f699:4954 with SMTP id 2adb3069b0e04-53b12c42f7emr1743110e87.58.1729591840250; Tue, 22 Oct 2024 03:10:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFrpdzMEtP8GCRmiUdFQ5jGMhUMEzMd9aQF/jUXNzE+TGciLXFKA5p3pvKX+bCR0aSoJfrHPQ== X-Received: by 2002:a05:6512:2207:b0:539:f699:4954 with SMTP id 2adb3069b0e04-53b12c42f7emr1743077e87.58.1729591839635; Tue, 22 Oct 2024 03:10:39 -0700 (PDT) Received: from avogadro.local ([151.95.144.54]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4316f5cc563sm83567805e9.44.2024.10.22.03.10.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Oct 2024 03:10:38 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: berrange@redhat.com, kwolf@redhat.com, junjie.mao@hotmail.com, manos.pitsidianakis@linaro.org Subject: [PATCH v2 11/14] rust: do not use --generate-cstr Date: Tue, 22 Oct 2024 12:09:52 +0200 Message-ID: <20241022100956.196657-12-pbonzini@redhat.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241022100956.196657-1-pbonzini@redhat.com> References: <20241022100956.196657-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.421, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org --generate-cstr is a good idea and generally the right thing to do, but it is not available in Debian 12 and Ubuntu 22.04. Work around the absence. Signed-off-by: Paolo Bonzini --- meson.build | 4 +++- rust/hw/char/pl011/src/device.rs | 1 + rust/qemu-api/src/device_class.rs | 10 ++++++++++ rust/qemu-api/tests/tests.rs | 4 ++-- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/meson.build b/meson.build index 9c57d7e5c6d..a083e3434b3 100644 --- a/meson.build +++ b/meson.build @@ -3941,13 +3941,15 @@ common_all = static_library('common', dependencies: common_ss.all_dependencies()) if have_rust + # We would like to use --generate-cstr, but it is only available + # starting with bindgen 0.66.0. The oldest supported versions + # are in Ubuntu 22.04 (0.59.1) and Debian 12 (0.60.1). bindgen_args = [ '--disable-header-comment', '--raw-line', '// @generated', '--ctypes-prefix', 'std::os::raw', '--formatter', 'rustfmt', '--generate-block', - '--generate-cstr', '--impl-debug', '--merge-extern-blocks', '--no-doc-comments', diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs index c26d21e079d..1bcb6a0fba8 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -13,6 +13,7 @@ bindings::{self, *}, c_str, definitions::ObjectImpl, + device_class::TYPE_SYS_BUS_DEVICE, }; use crate::{ diff --git a/rust/qemu-api/src/device_class.rs b/rust/qemu-api/src/device_class.rs index ce3d5f50507..995267dd715 100644 --- a/rust/qemu-api/src/device_class.rs +++ b/rust/qemu-api/src/device_class.rs @@ -2,6 +2,10 @@ // Author(s): Manos Pitsidianakis // SPDX-License-Identifier: GPL-2.0-or-later +use std::ffi::CStr; + +use crate::bindings; + #[macro_export] macro_rules! device_class_init { ($func:ident, props => $props:ident, realize_fn => $realize_fn:expr, legacy_reset_fn => $legacy_reset_fn:expr, vmsd => $vmsd:ident$(,)*) => { @@ -83,3 +87,9 @@ macro_rules! vm_state_description { }; } } + +// workaround until we can use --generate-cstr in bindgen. +pub const TYPE_DEVICE: &CStr = + unsafe { CStr::from_bytes_with_nul_unchecked(bindings::TYPE_DEVICE) }; +pub const TYPE_SYS_BUS_DEVICE: &CStr = + unsafe { CStr::from_bytes_with_nul_unchecked(bindings::TYPE_SYS_BUS_DEVICE) }; diff --git a/rust/qemu-api/tests/tests.rs b/rust/qemu-api/tests/tests.rs index 96e413b75ee..f932acd5c10 100644 --- a/rust/qemu-api/tests/tests.rs +++ b/rust/qemu-api/tests/tests.rs @@ -8,7 +8,7 @@ bindings::*, c_str, declare_properties, define_property, definitions::{Class, ObjectImpl}, - device_class_init, vm_state_description, + device_class, device_class_init, vm_state_description, }; #[test] @@ -56,7 +56,7 @@ impl ObjectImpl for DummyState { type Class = DummyClass; const TYPE_INFO: qemu_api::bindings::TypeInfo = qemu_api::type_info! { Self }; const TYPE_NAME: &'static CStr = c_str!("dummy"); - const PARENT_TYPE_NAME: Option<&'static CStr> = Some(TYPE_DEVICE); + const PARENT_TYPE_NAME: Option<&'static CStr> = Some(device_class::TYPE_DEVICE); const ABSTRACT: bool = false; const INSTANCE_INIT: Option = None; const INSTANCE_POST_INIT: Option = None; From patchwork Tue Oct 22 10:09:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13845482 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 234D9D1CDCF for ; Tue, 22 Oct 2024 10:11:51 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t3Bqn-00056h-7O; Tue, 22 Oct 2024 06:10:53 -0400 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 1t3Bql-00056J-5I for qemu-devel@nongnu.org; Tue, 22 Oct 2024 06:10:51 -0400 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 1t3Bqj-0004Q1-3B for qemu-devel@nongnu.org; Tue, 22 Oct 2024 06:10:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729591848; 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=sqZKZs4ctIO+XwCEz08VcQx7mTvLUzVoJpL0KkC+cT8=; b=DnATGNaNzIHWQoPmOJDYoxzCj3ryKKaY1e5rwywUaDhkfpJ9Tf/StwGBpdnrCLFf51Orf8 oiyYEj0TR+KNX+Nrz2e8FK7XghfsS6CiT2MG9PrOGBp8OiuNcwUxAiseB1Ta6RLIBZwYDi +Xgsh5FubltZjjP/SNn2gY18ZHWAw1o= 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-504-sZ24dXJhPJqJpGn-HtrDRQ-1; Tue, 22 Oct 2024 06:10:46 -0400 X-MC-Unique: sZ24dXJhPJqJpGn-HtrDRQ-1 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4314c6ca114so43647315e9.1 for ; Tue, 22 Oct 2024 03:10:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729591844; x=1730196644; 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=sqZKZs4ctIO+XwCEz08VcQx7mTvLUzVoJpL0KkC+cT8=; b=Qwvb+Qay0Z2neZtEYrsF3U6PLQP2L/TSBFWMKGLXDZX9smYCrHXEwCi6SjX/ChQ+4o POFYHO+jfbwgsxhGybsPNxgYTNKLIyYsD4QS2gNSl/mrGrfbxaVbdsLpfHp1Ivc9v/J1 wPezmd91OK/SClqoxcw4HLpNRViU3KTM9ZgO4r36bsxBRgLHPRzGKdFRPLJ13/Mp0fji 0QOfHHZtimfE+cjTPlZHYxzxVMvjhnqVg5rEFPMmKAFvqfWbUEy6nOfMXRa2gPrcbbVp BY4mPwM7cGdUcdBGCEDtTXj1f1CRi9DYBr9vWrtUh2CcRkl2qDxAd/SQxtlvDCZ5SB5p l5Pg== X-Gm-Message-State: AOJu0YyqoF6BFydnOM7pgmI1XdcLGfB81j02Haz+txcz8S7Ak3VUeQHy MSXyEgNlWL/Re1fuceP3KVY4kdd0B5+r6N5QwRwb7oVK7mcqEJl61KXwpnMLiWJn/P3UZaZQN+E HBU4I9idvy1IiAc3e9l5YPHfMfcl6IfcsBZ8fQjYVthaT+8IFxdwQmzKl7pfWn0UqsZrLgEqJJK kS1whgfdLisz+QC0NZWrc5NgIM1Lk7aG4N/IhCoOs= X-Received: by 2002:a05:600c:4687:b0:42c:b220:4778 with SMTP id 5b1f17b1804b1-4317cb0acd5mr15758815e9.33.1729591843911; Tue, 22 Oct 2024 03:10:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFHQXFBOMtcFlMJKbKgMFyEMN/5s07ayLP0urv3U5os3KfbvukbP9P0rEK2yQX+0m9oNq4BEg== X-Received: by 2002:a05:600c:4687:b0:42c:b220:4778 with SMTP id 5b1f17b1804b1-4317cb0acd5mr15758585e9.33.1729591843395; Tue, 22 Oct 2024 03:10:43 -0700 (PDT) Received: from avogadro.local ([151.95.144.54]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4316f5c314bsm83516045e9.32.2024.10.22.03.10.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Oct 2024 03:10:41 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: berrange@redhat.com, kwolf@redhat.com, junjie.mao@hotmail.com, manos.pitsidianakis@linaro.org Subject: [PATCH v2 12/14] rust: allow older version of bindgen Date: Tue, 22 Oct 2024 12:09:53 +0200 Message-ID: <20241022100956.196657-13-pbonzini@redhat.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241022100956.196657-1-pbonzini@redhat.com> References: <20241022100956.196657-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.421, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Cope with the old version that is provided in Debian 12. --size_t-is-usize is needed on bindgen <0.61.0, and it was removed in bindgen 0.65.0, so check for it in meson.build. --merge-extern-blocks was added in 0.61.0. --formatter rustfmt was added in 0.65.0 and is the default, so remove it. Apart from Debian 12 and Ubuntu 22.04, all other supported distros have version 0.66.x of bindgen or newer (or do not have bindgen at all). Signed-off-by: Paolo Bonzini --- docs/about/build-platforms.rst | 8 ++++++++ meson.build | 29 +++++++++++++++++++++++++---- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/docs/about/build-platforms.rst b/docs/about/build-platforms.rst index 8fd7da140a3..8173830c17a 100644 --- a/docs/about/build-platforms.rst +++ b/docs/about/build-platforms.rst @@ -107,6 +107,14 @@ Python build dependencies required, it may be necessary to fetch python modules from the Python Package Index (PyPI) via ``pip``, in order to build QEMU. +Rust build dependencies + QEMU is generally conservative in adding new Rust dependencies, and all + of them are included in the distributed tarballs. One exception is the + bindgen tool, which is too big to package and distribute. The minimum + supported version of bindgen is 0.60.x. For distributions that do not + include bindgen or have an older version, it is recommended to install + a newer version using ``cargo install bindgen-cli``. + Optional build dependencies Build components whose absence does not affect the ability to build QEMU may not be available in distros, or may be too old for QEMU's diff --git a/meson.build b/meson.build index a083e3434b3..d78afb79d67 100644 --- a/meson.build +++ b/meson.build @@ -100,6 +100,21 @@ if have_rust endif endif +bindgen = find_program('bindgen', required: get_option('rust').disable_auto_if(not have_rust)) +if not bindgen.found() or bindgen.version().version_compare('<0.60.0') + if get_option('rust').enabled() + error('bindgen version ' + bindgen.version() + ' is unsupported. You can install a new version with "cargo install bindgen-cli"') + else + if bindgen.found() + warning('bindgen version ' + bindgen.version() + ' is unsupported, disabling Rust compilation.') + else + warning('bindgen not found, disabling Rust compilation.') + endif + message('To use Rust you can install a new version with "cargo install bindgen-cli"') + have_rust = false + endif +endif + dtrace = not_found stap = not_found if 'dtrace' in get_option('trace_backends') @@ -3943,15 +3958,13 @@ common_all = static_library('common', if have_rust # We would like to use --generate-cstr, but it is only available # starting with bindgen 0.66.0. The oldest supported versions - # are in Ubuntu 22.04 (0.59.1) and Debian 12 (0.60.1). + # is 0.60.x (Debian 12 has 0.60.1) which introduces --allowlist-file. bindgen_args = [ '--disable-header-comment', '--raw-line', '// @generated', '--ctypes-prefix', 'std::os::raw', - '--formatter', 'rustfmt', '--generate-block', '--impl-debug', - '--merge-extern-blocks', '--no-doc-comments', '--with-derive-default', '--no-layout-tests', @@ -3960,6 +3973,12 @@ if have_rust '--allowlist-file', meson.project_source_root() + '/.*', '--allowlist-file', meson.project_build_root() + '/.*' ] + if bindgen.version().version_compare('<0.61.0') + # default in 0.61+ + bindgen_args += ['--size_t-is-usize'] + else + bindgen_args += ['--merge-extern-blocks'] + endif c_enums = [ 'DeviceCategory', 'GpioPolarity', @@ -3995,7 +4014,7 @@ if have_rust dependencies: common_ss.all_dependencies(), output: 'bindings.rs', include_directories: include_directories('.', 'include'), - bindgen_version: ['>=0.69.4'], + bindgen_version: ['>=0.60.0'], args: bindgen_args, ) subdir('rust') @@ -4461,6 +4480,8 @@ if have_rust summary_info += {'Rust target': config_host['RUST_TARGET_TRIPLE']} summary_info += {'rustc': ' '.join(rustc.cmd_array())} summary_info += {'rustc version': rustc.version()} + summary_info += {'bindgen': bindgen.full_path()} + summary_info += {'bindgen version': bindgen.version()} endif option_cflags = (get_option('debug') ? ['-g'] : []) if get_option('optimization') != 'plain' From patchwork Tue Oct 22 10:09:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13845483 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C387CD1CDD0 for ; Tue, 22 Oct 2024 10:11:51 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t3Bqo-000572-8L; Tue, 22 Oct 2024 06:10:54 -0400 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 1t3Bqm-00056Z-Ib for qemu-devel@nongnu.org; Tue, 22 Oct 2024 06:10:52 -0400 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 1t3Bql-0004Q7-5z for qemu-devel@nongnu.org; Tue, 22 Oct 2024 06:10:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729591850; 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=K9B3S4pkz/ND8ZX3LymjnObrKUjAIX6qwMdxq9Q+Q3M=; b=SD6ifI+tF2B+wjjveBxHO9LVNqVvoes4bd6026sKkeOW7vMtcggmn1+trHrFDAjvs9jCEp phS+Yjo5RPPrkUxEwvJDIla851LziXyXk3nTuxOBxU50g+ORJddZNxfCsL8JhEN+Zc1InX SG/WAhUlEdo1Sx+oFkS7290Bs3FiEG4= 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-58-LzABJowoNgejoB91X1AFWQ-1; Tue, 22 Oct 2024 06:10:49 -0400 X-MC-Unique: LzABJowoNgejoB91X1AFWQ-1 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4317391101aso14416645e9.2 for ; Tue, 22 Oct 2024 03:10:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729591847; x=1730196647; 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=K9B3S4pkz/ND8ZX3LymjnObrKUjAIX6qwMdxq9Q+Q3M=; b=d3UzbLRbvCPGTxomKFsg48Mh88esiKyvBUgUQzLw6AaZAz4YlCkPAJD4ezFHskhZ6H GnV58MOMvVri9quRUHoA42QPPAcmpMmfYc2zaTwltPCv0VO0ceApBqFaG4XrUR/7C85f RoHgfE8oB2122D7CrjrKF1hwvtJ9RAtAwGEQPl2wq/SjuNSjebdRPqrX8RAqZgP6zFq5 FK77XEQfGNYe3m7EP0kS8OAIRlvRnGKU+drR61LWJ/2EyEW39S5t122ucqDQIiExeXFS 4UyOQRlqCPKcOChMbZulJ/7Bm4hnj+OHOmTDi+yBKvsoqascnHUX2m6mYIjmWT0C/B7q 6QYQ== X-Gm-Message-State: AOJu0YzguYD0QzQgksjQ7VnrAlo1iaqToJJNphMJJN7zAsWUTgkw6n/h 8dE13K9bT/mx7u5AbvzGEsvoTuPlN4UX0KrjItdB/6eOa84C73PFCo0ValPsTG6uc5WNm102Ol2 dtoqu8K7FIHIpv3dYhocghyl+W+I1jTHuT/1m6r+NjB0DF7shpRxJVLF8zB9AVpRrOJKqb3tkam mmsCPkXJc3mZlr7hwev7veB04uvHyPfHH8wq8EWE8= X-Received: by 2002:a05:600c:1c95:b0:431:6083:cd2a with SMTP id 5b1f17b1804b1-43161659c02mr124685855e9.15.1729591847429; Tue, 22 Oct 2024 03:10:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEDQGfliN2mrPSUog1KDj6MU2y/6FNACnBkmObU8eVnHfr3chcQmaoS/LkbMYCw8wpOebwq8A== X-Received: by 2002:a05:600c:1c95:b0:431:6083:cd2a with SMTP id 5b1f17b1804b1-43161659c02mr124685555e9.15.1729591846992; Tue, 22 Oct 2024 03:10:46 -0700 (PDT) Received: from avogadro.local ([151.95.144.54]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4316f5c3194sm84592765e9.31.2024.10.22.03.10.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Oct 2024 03:10:45 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: berrange@redhat.com, kwolf@redhat.com, junjie.mao@hotmail.com, manos.pitsidianakis@linaro.org Subject: [PATCH v2 13/14] rust: make rustfmt optional Date: Tue, 22 Oct 2024 12:09:54 +0200 Message-ID: <20241022100956.196657-14-pbonzini@redhat.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241022100956.196657-1-pbonzini@redhat.com> References: <20241022100956.196657-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.421, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Paolo Bonzini --- meson.build | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/meson.build b/meson.build index d78afb79d67..5e3501750a1 100644 --- a/meson.build +++ b/meson.build @@ -115,6 +115,10 @@ if not bindgen.found() or bindgen.version().version_compare('<0.60.0') endif endif +if have_rust + rustfmt = find_program('rustfmt', required: false) +endif + dtrace = not_found stap = not_found if 'dtrace' in get_option('trace_backends') @@ -3973,6 +3977,13 @@ if have_rust '--allowlist-file', meson.project_source_root() + '/.*', '--allowlist-file', meson.project_build_root() + '/.*' ] + if not rustfmt.found() + if bindgen.version().version_compare('<0.65.0') + bindgen_args += ['--no-rustfmt-bindings'] + else + bindgen_args += ['--formatter', 'none'] + endif + endif if bindgen.version().version_compare('<0.61.0') # default in 0.61+ bindgen_args += ['--size_t-is-usize'] From patchwork Tue Oct 22 10:09:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13845478 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 010CDD1CDCF for ; Tue, 22 Oct 2024 10:11:39 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t3Br1-0005OD-5H; Tue, 22 Oct 2024 06:11:08 -0400 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 1t3Bqs-0005Cs-AB for qemu-devel@nongnu.org; Tue, 22 Oct 2024 06:10:59 -0400 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 1t3Bqp-0004Qm-Cv for qemu-devel@nongnu.org; Tue, 22 Oct 2024 06:10:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729591854; 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=wXYKPERsSFUrXojLdSDlVUPkke/4VTh6P6Z9bxQslRA=; b=elAXQ18ZwuIfvB2TVzP0sig8naWomxGy75rXUnWxzNeuIPZiQP+loeZm2Rdg3s2xoLdrDU PM2v5ymFxhkxbGy668yBElFX2cVho0+4KlhBqAtL2OoClP7eXOEClygqT8XmXEYKKMhAqI +8riB22x/raC7XWtDb1skgsYxguTjQM= 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-612-2A9CNMs7MRCVXTfxV9fs1w-1; Tue, 22 Oct 2024 06:10:53 -0400 X-MC-Unique: 2A9CNMs7MRCVXTfxV9fs1w-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-431518e6d8fso38190125e9.0 for ; Tue, 22 Oct 2024 03:10:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729591851; x=1730196651; 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=wXYKPERsSFUrXojLdSDlVUPkke/4VTh6P6Z9bxQslRA=; b=ISdxMFoP64otk+aSCW0grWyYdISTw57svAHJOR++pWBa1NigT0qnDeVwT2OsMR9J5y tTRw15nJMfquJyw19GB50BJSdniDEaJWEbD8EkhEcXZ/ruq0/8Dj1HZ120mq/SoJRZ3r 3NdxCzf5gUmRWAuNYEj0HO7hKTSWIowvYt/tTAbPzG+zUzo2/bX2hmWK3tIQVKRlniti svpVbrSHnmpd2gvEuLCU/bSxcOcWieZluNQ/pUUQwfnh+5mjQblzrC9CQb4gjYhpiMS+ bX7w/G931V01zlS5ojC2br64KA7/iJhhGKoVck5tul7Pk4ftVBTVXTcNJKX9dhxCY8I6 6fyQ== X-Gm-Message-State: AOJu0YwlmnK+k1q4mvVeOXURjWeqhZIsTJlAwtGXuzkaXIdUJtwxfB2x SwnbmoB2ZRmX9eY2LsBM8fnMKoD7Pca+x6IW2NBBUNwPAixbfMOlYPDQwo46Q5/WX6g9XXJr/2I 1jOR3ap0C5l4o3zAAUWTbcKViDUfQbGN5X43sVIFvWCjDlsi+E0gB5/2oO2KFv4ZqPU9MT+gxRE 4TApTX2XXMoebRhb9sg6z1Uc/jemaIHmW5FsDdk8c= X-Received: by 2002:a05:600c:4ed2:b0:426:64a2:5362 with SMTP id 5b1f17b1804b1-4316163b8bbmr111004625e9.8.1729591851217; Tue, 22 Oct 2024 03:10:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IENasJYl91Hg+yP66jIknw/gTZ0EeU7r9BvhomsSRp60/DrKVFy7AG/42ZwzSIhw7PyIV6ePQ== X-Received: by 2002:a05:600c:4ed2:b0:426:64a2:5362 with SMTP id 5b1f17b1804b1-4316163b8bbmr111004345e9.8.1729591850739; Tue, 22 Oct 2024 03:10:50 -0700 (PDT) Received: from avogadro.local ([151.95.144.54]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4316f57fc36sm83998985e9.18.2024.10.22.03.10.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Oct 2024 03:10:49 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: berrange@redhat.com, kwolf@redhat.com, junjie.mao@hotmail.com, manos.pitsidianakis@linaro.org Subject: [PATCH v2 14/14] dockerfiles: install bindgen from cargo on Ubuntu 22.04 Date: Tue, 22 Oct 2024 12:09:55 +0200 Message-ID: <20241022100956.196657-15-pbonzini@redhat.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241022100956.196657-1-pbonzini@redhat.com> References: <20241022100956.196657-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.421, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Because Ubuntu 22.04 has a very old version of bindgen, that does not have the important option --allowlist-file, it will not be able to use --enable-rust out of the box. Instead, install the latest version of bindgen-cli via "cargo install" in the container, following the documentation. Signed-off-by: Paolo Bonzini --- tests/docker/dockerfiles/ubuntu2204.docker | 5 +++++ tests/lcitool/mappings.yml | 4 ++++ tests/lcitool/refresh | 11 ++++++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/tests/docker/dockerfiles/ubuntu2204.docker b/tests/docker/dockerfiles/ubuntu2204.docker index ce3aa39d4f3..245ac879622 100644 --- a/tests/docker/dockerfiles/ubuntu2204.docker +++ b/tests/docker/dockerfiles/ubuntu2204.docker @@ -149,6 +149,11 @@ ENV LANG "en_US.UTF-8" ENV MAKE "/usr/bin/make" ENV NINJA "/usr/bin/ninja" ENV PYTHON "/usr/bin/python3" +ENV CARGO_HOME=/usr/local/cargo +ENV PATH=$CARGO_HOME/bin:$PATH +RUN DEBIAN_FRONTEND=noninteractive eatmydata \ + apt install -y --no-install-recommends cargo +RUN cargo install bindgen-cli # As a final step configure the user (if env is defined) ARG USER ARG UID diff --git a/tests/lcitool/mappings.yml b/tests/lcitool/mappings.yml index 9c5ac87c1c2..c90b23a00f1 100644 --- a/tests/lcitool/mappings.yml +++ b/tests/lcitool/mappings.yml @@ -1,4 +1,8 @@ mappings: + # Too old on Ubuntu 22.04; we install it from cargo instead + bindgen: + Ubuntu2204: + flake8: OpenSUSELeap15: diff --git a/tests/lcitool/refresh b/tests/lcitool/refresh index 0f16f4d525c..a46cbbdca41 100755 --- a/tests/lcitool/refresh +++ b/tests/lcitool/refresh @@ -137,6 +137,14 @@ fedora_rustup_nightly_extras = [ 'RUN /usr/local/cargo/bin/rustup run nightly cargo install bindgen-cli\n', ] +ubuntu2204_bindgen_extras = [ + "ENV CARGO_HOME=/usr/local/cargo\n", + 'ENV PATH=$CARGO_HOME/bin:$PATH\n', + "RUN DEBIAN_FRONTEND=noninteractive eatmydata \\\n", + " apt install -y --no-install-recommends cargo\n", + 'RUN cargo install bindgen-cli\n', +] + def cross_build(prefix, targets): conf = "ENV QEMU_CONFIGURE_OPTS --cross-prefix=%s\n" % (prefix) targets = "ENV DEF_TARGET_LIST %s\n" % (targets) @@ -157,7 +165,8 @@ try: trailer="".join(debian12_extras)) generate_dockerfile("fedora", "fedora-40") generate_dockerfile("opensuse-leap", "opensuse-leap-15") - generate_dockerfile("ubuntu2204", "ubuntu-2204") + generate_dockerfile("ubuntu2204", "ubuntu-2204", + trailer="".join(ubuntu2204_bindgen_extras)) # # Non-fatal Rust-enabled build