From nobody Tue May 7 11:02:16 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631017343614443.57773349848526; Tue, 7 Sep 2021 05:22:23 -0700 (PDT) Received: from localhost ([::1]:35336 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNa7K-0000R4-HR for importer@patchew.org; Tue, 07 Sep 2021 08:22:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41712) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNa5G-00065K-LX for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:20:14 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:27973) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNa5E-0005uk-0x for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:20:13 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-211-YLGUIhf_O0aZ4sSey56muw-1; Tue, 07 Sep 2021 08:20:10 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1FEE9100E403 for ; Tue, 7 Sep 2021 12:20:09 +0000 (UTC) Received: from localhost (unknown [10.39.208.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id 89F7E1B46B; Tue, 7 Sep 2021 12:20:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631017211; 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=8T4JlY79PWL+djlbbRqYAkR3sG+cVNaNdae+g2BDu60=; b=I8eAq+C2IawMftG6V2hXZAWF/bQOLy9yKffXqB1SiYyhDfM1R+GTJJ2Oh4NgDf4sgpLOHC 1u1HFtxrjMRTiZhTWhN8wXB03woZSdnJZkxw+LSy82ouGUVAPh7Tp/i5GPMtJmqVQtHUhZ 5OA9zqMa7MSRse06eRKpzqAS2cl9MWc= X-MC-Unique: YLGUIhf_O0aZ4sSey56muw-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [RFC v3 01/32] RFC: docs: add supported host CPUs section Date: Tue, 7 Sep 2021 16:19:12 +0400 Message-Id: <20210907121943.3498701-2-marcandre.lureau@redhat.com> In-Reply-To: <20210907121943.3498701-1-marcandre.lureau@redhat.com> References: <20210907121943.3498701-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=marcandre.lureau@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, berrange@redhat.com, armbru@redhat.com, stefanha@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631017344120100001 From: Marc-Andr=C3=A9 Lureau I was looking for such documentation, but couldn't find it. Signed-off-by: Marc-Andr=C3=A9 Lureau --- docs/about/build-platforms.rst | 28 ++++++++++++++++++++++++++++ meson.build | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/docs/about/build-platforms.rst b/docs/about/build-platforms.rst index 692323609e..bfe90e574e 100644 --- a/docs/about/build-platforms.rst +++ b/docs/about/build-platforms.rst @@ -29,6 +29,34 @@ The `Repology`_ site is a useful resource to identify currently shipped versions of software in various operating systems, though it does not cover all distros listed below. =20 +Supported host CPUs +------------------- + +Those host CPUs have a native TCG backend and are regularly tested: + + .. list-table:: + :header-rows: 1 + + * - CPU Family + - Accelerators + * - ARM + - kvm, xen + * - MIPS + - kvm + * - PPC + - kvm + * - RISC-V + - + * - s390x + - kvm + * - SPARC + - + * - x86 + - kvm, xen, hax, hvf (64 bit only), nvmm, whpx (64 bit only) + +Other architectures are not actively maintained. They use the slow and +experimental TCG interpreter. They may be removed in future releases. + Linux OS, macOS, FreeBSD, NetBSD, OpenBSD ----------------------------------------- =20 diff --git a/meson.build b/meson.build index 7e58e6279b..9e43c9b311 100644 --- a/meson.build +++ b/meson.build @@ -78,7 +78,7 @@ endif =20 accelerator_targets =3D { 'CONFIG_KVM': kvm_targets } if cpu in ['x86', 'x86_64', 'arm', 'aarch64'] - # i368 emulator provides xenpv machine type for multiple architectures + # i386 emulator provides xenpv machine type for multiple architectures accelerator_targets +=3D { 'CONFIG_XEN': ['i386-softmmu', 'x86_64-softmmu'], } --=20 2.33.0.113.g6c40894d24 From nobody Tue May 7 11:02:16 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 163101735393950.432734944454864; Tue, 7 Sep 2021 05:22:33 -0700 (PDT) Received: from localhost ([::1]:35738 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNa7U-0000i4-US for importer@patchew.org; Tue, 07 Sep 2021 08:22:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41856) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNa5X-0006Gr-BD for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:20:33 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:60750) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNa5V-00069X-BF for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:20:31 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-507--QtS-5rCOq6yeAwa03nycA-1; Tue, 07 Sep 2021 08:20:23 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AE052102CB7D for ; Tue, 7 Sep 2021 12:20:22 +0000 (UTC) Received: from localhost (unknown [10.39.208.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1536B5D9F0; Tue, 7 Sep 2021 12:20:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631017227; 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=Rj2SE8GC0mje5TItuVOFNMgeakkP23rxuKjkravVaug=; b=DClCnkf9pjG2CO4qbOeFhm9nS8ZK7BR0ZqO0OIcVYBzsLTk3FGftZnW6b1vqCSo1c0BuZ5 p39nZAKA5cj+ovZu5Flp3el1DB3iohWSduD1BMC/DZKpN2jAOd06ig/KPq94Ieg4mGzXI3 YcIdmPqNG856x68YMPAxn1eUz3UFn4I= X-MC-Unique: -QtS-5rCOq6yeAwa03nycA-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [RFC v3 02/32] build-sys: add HAVE_IPPROTO_MPTCP Date: Tue, 7 Sep 2021 16:19:13 +0400 Message-Id: <20210907121943.3498701-3-marcandre.lureau@redhat.com> In-Reply-To: <20210907121943.3498701-1-marcandre.lureau@redhat.com> References: <20210907121943.3498701-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=marcandre.lureau@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, berrange@redhat.com, armbru@redhat.com, stefanha@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631017355588100001 From: Marc-Andr=C3=A9 Lureau The QAPI schema shouldn't rely on C system headers #define, but on configure-time project #define, so we can express the build condition in a C-independent way. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Markus Armbruster --- meson.build | 2 ++ qapi/sockets.json | 2 +- io/dns-resolver.c | 2 +- util/qemu-sockets.c | 6 +++--- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/meson.build b/meson.build index 9e43c9b311..6e871af4d0 100644 --- a/meson.build +++ b/meson.build @@ -1367,6 +1367,8 @@ config_host_data.set('HAVE_OPTRESET', cc.has_header_symbol('getopt.h', 'optreset')) config_host_data.set('HAVE_UTMPX', cc.has_header_symbol('utmpx.h', 'struct utmpx')) +config_host_data.set('HAVE_IPPROTO_MPTCP', + cc.has_header_symbol('netinet/in.h', 'IPPROTO_MPTCP')) =20 # has_member config_host_data.set('HAVE_SIGEV_NOTIFY_THREAD_ID', diff --git a/qapi/sockets.json b/qapi/sockets.json index 7866dc27d6..c9101f937f 100644 --- a/qapi/sockets.json +++ b/qapi/sockets.json @@ -69,7 +69,7 @@ '*ipv4': 'bool', '*ipv6': 'bool', '*keep-alive': 'bool', - '*mptcp': { 'type': 'bool', 'if': 'IPPROTO_MPTCP' } } } + '*mptcp': { 'type': 'bool', 'if': 'HAVE_IPPROTO_MPTCP' } } } =20 ## # @UnixSocketAddress: diff --git a/io/dns-resolver.c b/io/dns-resolver.c index a5946a93bf..53b0e8407a 100644 --- a/io/dns-resolver.c +++ b/io/dns-resolver.c @@ -122,7 +122,7 @@ static int qio_dns_resolver_lookup_sync_inet(QIODNSReso= lver *resolver, .ipv4 =3D iaddr->ipv4, .has_ipv6 =3D iaddr->has_ipv6, .ipv6 =3D iaddr->ipv6, -#ifdef IPPROTO_MPTCP +#ifdef HAVE_IPPROTO_MPTCP .has_mptcp =3D iaddr->has_mptcp, .mptcp =3D iaddr->mptcp, #endif diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c index f2f3676d1f..02eb2f3d34 100644 --- a/util/qemu-sockets.c +++ b/util/qemu-sockets.c @@ -278,7 +278,7 @@ static int inet_listen_saddr(InetSocketAddress *saddr, =20 /* create socket + bind/listen */ for (e =3D res; e !=3D NULL; e =3D e->ai_next) { -#ifdef IPPROTO_MPTCP +#ifdef HAVE_IPPROTO_MPTCP if (saddr->has_mptcp && saddr->mptcp) { e->ai_protocol =3D IPPROTO_MPTCP; } @@ -462,7 +462,7 @@ int inet_connect_saddr(InetSocketAddress *saddr, Error = **errp) error_free(local_err); local_err =3D NULL; =20 -#ifdef IPPROTO_MPTCP +#ifdef HAVE_IPPROTO_MPTCP if (saddr->has_mptcp && saddr->mptcp) { e->ai_protocol =3D IPPROTO_MPTCP; } @@ -699,7 +699,7 @@ int inet_parse(InetSocketAddress *addr, const char *str= , Error **errp) } addr->has_keep_alive =3D true; } -#ifdef IPPROTO_MPTCP +#ifdef HAVE_IPPROTO_MPTCP begin =3D strstr(optstr, ",mptcp"); if (begin) { if (inet_parse_flag("mptcp", begin + strlen(",mptcp"), --=20 2.33.0.113.g6c40894d24 From nobody Tue May 7 11:02:16 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631017521749723.5757750122772; Tue, 7 Sep 2021 05:25:21 -0700 (PDT) Received: from localhost ([::1]:43518 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNaAC-0006HS-Mx for importer@patchew.org; Tue, 07 Sep 2021 08:25:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41898) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNa5h-0006LG-O3 for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:20:43 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:25968) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNa5e-0006Ev-L1 for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:20:41 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-168-iD874eePO56ZV9DQydrd1g-1; Tue, 07 Sep 2021 08:20:35 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B4410188E3C1 for ; Tue, 7 Sep 2021 12:20:34 +0000 (UTC) Received: from localhost (unknown [10.39.208.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id 93D96781ED; Tue, 7 Sep 2021 12:20:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631017237; 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=+pM9YBBMfyGc8ihULzRDaBFtydsgznGpDpdOjwz7lH0=; b=jSin6aP2qeVMOnNPiWcl36ecVrpjvX7pMjWOAexkDIxvnnE+v0W6CcN8Kv+z5b+VSJJycU G8yX00tm0p00BV1qnW09q6MGwdGlPSGjCn/FoLc86oqNAK2qDzHxbaHL6ur84W+EBDAj38 vxcMRqseORhFjxtw2Ui4qWd+x9aXylo= X-MC-Unique: iD874eePO56ZV9DQydrd1g-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [RFC v3 03/32] scripts/qapi: teach c_param_type() to return const argument type Date: Tue, 7 Sep 2021 16:19:14 +0400 Message-Id: <20210907121943.3498701-4-marcandre.lureau@redhat.com> In-Reply-To: <20210907121943.3498701-1-marcandre.lureau@redhat.com> References: <20210907121943.3498701-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=marcandre.lureau@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, berrange@redhat.com, armbru@redhat.com, stefanha@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631017522716100001 From: Marc-Andr=C3=A9 Lureau The argument isn't owned by the callee, so it better be const. But a lot of code in QEMU rely on non-const arguments to tweak it (steal values etc). Since Rust types / bindings are derived from the C version, we have to be more accurate there to do correct ownership in the bindings. Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi/schema.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 3d72c7dfc9..1f6301c394 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -226,8 +226,15 @@ def c_type(self): pass =20 # Return the C type to be used in a parameter list. - def c_param_type(self): - return self.c_type() + # + # The argument should be considered const, since no ownership is given= to + # the callee, but qemu C code frequently tweaks it. Set const=3DTrue f= or a + # stricter declaration. + def c_param_type(self, const: bool =3D False): + c_type =3D self.c_type() + if const and c_type.endswith(POINTER_SUFFIX): + c_type =3D 'const ' + c_type + return c_type =20 # Return the C type to be used where we suppress boxing. def c_unboxed_type(self): @@ -280,10 +287,10 @@ def c_name(self): def c_type(self): return self._c_type_name =20 - def c_param_type(self): + def c_param_type(self, const: bool =3D False): if self.name =3D=3D 'str': return 'const ' + self._c_type_name - return self._c_type_name + return super().c_param_type(const) =20 def json_type(self): return self._json_type_name --=20 2.33.0.113.g6c40894d24 From nobody Tue May 7 11:02:16 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631017527610186.5106984362202; Tue, 7 Sep 2021 05:25:27 -0700 (PDT) Received: from localhost ([::1]:43802 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNaAI-0006TN-G6 for importer@patchew.org; Tue, 07 Sep 2021 08:25:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41958) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNa5q-0006dF-K3 for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:20:50 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:26470) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNa5o-0006LJ-LX for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:20:50 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-87-AhznjB7ZPRmpTs9r7HCQ6g-1; Tue, 07 Sep 2021 08:20:46 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B69CF188E3C2 for ; Tue, 7 Sep 2021 12:20:45 +0000 (UTC) Received: from localhost (unknown [10.39.208.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id D3B4110013D7; Tue, 7 Sep 2021 12:20:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631017247; 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=XAeWEZvjIXkGAYZ+H8tFtsLpCD/98+4IPunIltXcOxU=; b=L1/K+CXVKKy7Zzm9B0ImtPR/qyXHvmEfcoQJe2wdYq6jgWVmeNoqtFA+qrO/yoQLppgTCy FEQXHnf34hutCUu9Vvtdqa+iOLtmfuCcrROieC+YdmRaM0hiKVVXHjN/DZ0PsITZrkbMrm JZA76IU2mipwFrD9vfF/WNCLMZWzIlQ= X-MC-Unique: AhznjB7ZPRmpTs9r7HCQ6g-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [RFC v3 04/32] glib-compat: add G_SIZEOF_MEMBER Date: Tue, 7 Sep 2021 16:19:15 +0400 Message-Id: <20210907121943.3498701-5-marcandre.lureau@redhat.com> In-Reply-To: <20210907121943.3498701-1-marcandre.lureau@redhat.com> References: <20210907121943.3498701-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=marcandre.lureau@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, berrange@redhat.com, armbru@redhat.com, stefanha@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631017529060100001 From: Marc-Andr=C3=A9 Lureau The macro was introduced in 2.64. Let's redefine it, to allow its usage with older versions and silence the deprecation warning. Signed-off-by: Marc-Andr=C3=A9 Lureau --- include/glib-compat.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/glib-compat.h b/include/glib-compat.h index 9e95c888f5..e278e09d1d 100644 --- a/include/glib-compat.h +++ b/include/glib-compat.h @@ -110,4 +110,11 @@ qemu_g_test_slow(void) =20 #pragma GCC diagnostic pop =20 +/* introduced in 2.64 */ +#ifdef G_SIZEOF_MEMBER +#undef G_SIZEOF_MEMBER +#endif + +#define G_SIZEOF_MEMBER(type, member) sizeof(((type *)0)->member) + #endif --=20 2.33.0.113.g6c40894d24 From nobody Tue May 7 11:02:16 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631017368462220.81661351961543; Tue, 7 Sep 2021 05:22:48 -0700 (PDT) Received: from localhost ([::1]:36724 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNa7j-0001Lo-Bm for importer@patchew.org; Tue, 07 Sep 2021 08:22:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41974) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNa60-0006t3-8g for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:21:01 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:29777) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNa5y-0006T6-OI for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:21:00 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-36-OP1SMThyPO6yAeUOJ2p_zw-1; Tue, 07 Sep 2021 08:20:56 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 24403188E3D6 for ; Tue, 7 Sep 2021 12:20:56 +0000 (UTC) Received: from localhost (unknown [10.39.208.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9D47519736; Tue, 7 Sep 2021 12:20:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631017258; 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=vsPeXLVMoNfGTjP5mwOeVlJxyCx81Jkf/m76BRxp31I=; b=EHvqbZBPEUFf9g+QPdC8C0lF//fNZr8satbLKoG46tVJwFLiq9opVMeaelPieMpk1m2/fD B0EBViIHz9e49SAMCKbt7M9ciYcqvQimXMrucDiSx7AzGrfWbDF/gPcEKuixsMgljxBYKq 9Oq/x/YiK3UqmnGPB9K5/hNT3Eyrrfc= X-MC-Unique: OP1SMThyPO6yAeUOJ2p_zw-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [RFC v3 05/32] scripts/qapi: add QAPISchemaVisitor.visit_module_end Date: Tue, 7 Sep 2021 16:19:16 +0400 Message-Id: <20210907121943.3498701-6-marcandre.lureau@redhat.com> In-Reply-To: <20210907121943.3498701-1-marcandre.lureau@redhat.com> References: <20210907121943.3498701-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=marcandre.lureau@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, berrange@redhat.com, armbru@redhat.com, stefanha@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631017369184100003 From: Marc-Andr=C3=A9 Lureau Used in following patches to generate code after visiting a module. Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi/schema.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 1f6301c394..6455a8f425 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -128,6 +128,9 @@ def visit_end(self): def visit_module(self, name): pass =20 + def visit_module_end(self, name) -> None: + pass + def visit_needed(self, entity): # Default to visiting everything return True @@ -207,6 +210,7 @@ def visit(self, visitor): for entity in self._entity_list: if visitor.visit_needed(entity): entity.visit(visitor) + visitor.visit_module_end(self.name) =20 =20 class QAPISchemaInclude(QAPISchemaEntity): --=20 2.33.0.113.g6c40894d24 From nobody Tue May 7 11:02:16 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631017578594257.6962597480941; Tue, 7 Sep 2021 05:26:18 -0700 (PDT) Received: from localhost ([::1]:45392 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNaB7-0007ax-Ho for importer@patchew.org; Tue, 07 Sep 2021 08:26:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42116) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNa6J-0007ej-8T for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:21:19 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:40450) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNa6G-0006gQ-IW for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:21:18 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-436-lo3dDzczOC-GVelyvUgisA-1; Tue, 07 Sep 2021 08:21:11 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 99A806D58F for ; Tue, 7 Sep 2021 12:21:10 +0000 (UTC) Received: from localhost (unknown [10.39.208.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2801C5D6CF; Tue, 7 Sep 2021 12:20:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631017276; 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=MdWjztreNk1HSfZb6qrkgsYAfbyLwZ8/w91WuKIhg24=; b=KJ+Pw2PtuEXXINPk8XnHXcrl8fNXDaeEtCVIfDN3IHTpQ2ZKxdwFawrcZ3KdyoE2VXuTBj o/6xxTztHutU2G1A09rp7uK/aa1JIPrf0DxzZ6o2QXXp4hSlx8KptPlAPsToq/UrjB3Qw0 6io5GpyfJfUzOAB3DHEmwVnGtP1Ok9U= X-MC-Unique: lo3dDzczOC-GVelyvUgisA-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [RFC v3 06/32] scripts/qapi: add a CABI module Date: Tue, 7 Sep 2021 16:19:17 +0400 Message-Id: <20210907121943.3498701-7-marcandre.lureau@redhat.com> In-Reply-To: <20210907121943.3498701-1-marcandre.lureau@redhat.com> References: <20210907121943.3498701-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=marcandre.lureau@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, berrange@redhat.com, armbru@redhat.com, stefanha@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631017580740100001 From: Marc-Andr=C3=A9 Lureau This module will help to build C ABI tests for both Rust and C QAPI generated types. Currently, it will simply print basic struct layout (size and offset of members) and the enum size and maximum values. By diffing the output, it will help to ensure that the Rust definition is compatible with the C version, including with configuration specifics. Example output: GuestDeviceAddress struct: sizeof=3D16 type member: sizeof=3D4 offset=3D0 GuestDeviceAddressKind enum: sizeof=3D4 max=3D1 Signed-off-by: Marc-Andr=C3=A9 Lureau --- meson.build | 1 + scripts/qapi/cabi.py | 137 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 138 insertions(+) create mode 100644 scripts/qapi/cabi.py diff --git a/meson.build b/meson.build index 6e871af4d0..cbf3ce19ae 100644 --- a/meson.build +++ b/meson.build @@ -1966,6 +1966,7 @@ hxtool =3D find_program('scripts/hxtool') shaderinclude =3D find_program('scripts/shaderinclude.pl') qapi_gen =3D find_program('scripts/qapi-gen.py') qapi_gen_depends =3D [ meson.source_root() / 'scripts/qapi/__init__.py', + meson.source_root() / 'scripts/qapi/cabi.py', meson.source_root() / 'scripts/qapi/commands.py', meson.source_root() / 'scripts/qapi/common.py', meson.source_root() / 'scripts/qapi/error.py', diff --git a/scripts/qapi/cabi.py b/scripts/qapi/cabi.py new file mode 100644 index 0000000000..f33680477f --- /dev/null +++ b/scripts/qapi/cabi.py @@ -0,0 +1,137 @@ +# +# QAPI helper library +# C ABI verification test generator +# +# pylint: disable=3Dtoo-few-public-methods + +from typing import List, Optional + +from .common import c_enum_const, c_name, mcgen +from .schema import ( + QAPISchemaEnumMember, + QAPISchemaIfCond, + QAPISchemaObjectType, + QAPISchemaObjectTypeMember, + QAPISchemaVariants, +) + + +class CABI: + def __init__(self, name: str, ifcond: QAPISchemaIfCond): + self.name =3D name + self.ifcond =3D ifcond + + def gen_c(self) -> str: + raise NotImplementedError() + + +class CABIEnum(CABI): + def __init__( + self, + name: str, + ifcond: QAPISchemaIfCond, + members: List[QAPISchemaEnumMember], + prefix: Optional[str] =3D None, + ): + super().__init__(name, ifcond) + self.members =3D members + self.prefix =3D prefix + + def gen_c(self) -> str: + last =3D c_enum_const(self.name, "_MAX", self.prefix) + ret =3D self.ifcond.gen_if() + ret +=3D mcgen(""" + printf("%(name)s enum: sizeof=3D%%zu\\n", sizeof(%(cname)s)); + printf(" max=3D%%d\\n", %(last)s); + printf("\\n"); +""", name=3Dself.name, cname=3Dc_name(self.name), last=3Dlast) + ret +=3D self.ifcond.gen_endif() + return ret + + +class CABIStruct(CABI): + def __init__(self, name: str, ifcond: QAPISchemaIfCond): + super().__init__(name, ifcond) + self.members: List[CABIStructMember] =3D [] + + def add_members(self, members: List[QAPISchemaObjectTypeMember]) -> No= ne: + for memb in members: + if memb.optional: + self.add_member(memb.name, memb.ifcond, "has_") + self.add_member(memb.name, memb.ifcond) + + def add_variants(self, variants: QAPISchemaVariants) -> None: + for var in variants.variants: + if var.type.name =3D=3D "q_empty": + continue + self.add_member(var.name, var.ifcond, "u.") + + def add_member(self, member: str, + ifcond: Optional[QAPISchemaIfCond] =3D None, + prefix: str =3D '') -> None: + self.members.append(CABIStructMember(self, member, ifcond, prefix)) + + def gen_c(self) -> str: + ret =3D self.ifcond.gen_if() + ret +=3D mcgen(""" + printf("%(name)s struct: sizeof=3D%%zu\\n", sizeof(%(name)s)); +""", name=3Dself.name) + for member in self.members: + ret +=3D member.gen_c() + ret +=3D mcgen(""" + printf("\\n"); +""") + ret +=3D self.ifcond.gen_endif() + return ret + + +class CABIStructMember: + def __init__(self, struct: CABIStruct, name: str, + ifcond: Optional[QAPISchemaIfCond] =3D None, + prefix: str =3D ''): + self.struct =3D struct + self.name =3D name + self.ifcond =3D ifcond or QAPISchemaIfCond() + self.prefix =3D prefix + + def gen_c(self) -> str: + ret =3D self.ifcond.gen_if() + cmember =3D self.prefix + c_name(self.name) + ret +=3D mcgen(""" + printf(" %(member)s member: sizeof=3D%%zu offset=3D%%zu\\n", + G_SIZEOF_MEMBER(struct %(sname)s, %(cmember)s), + offsetof(struct %(sname)s, %(cmember)s)); +""", member=3Dself.name, sname=3Dself.struct.name, cmember=3Dcmember) + ret +=3D self.ifcond.gen_endif() + return ret + + +def gen_object_cabi( + name: str, + ifcond: QAPISchemaIfCond, + base: Optional[QAPISchemaObjectType], + members: List[QAPISchemaObjectTypeMember], + variants: Optional[QAPISchemaVariants], +) -> List[CABI]: + if name =3D=3D 'q_empty': + return [] + ret =3D [] + for var in variants.variants if variants else (): + obj =3D var.type + if not isinstance(obj, QAPISchemaObjectType): + continue + ret.extend( + gen_object_cabi( + obj.name, obj.ifcond, obj.base, obj.local_members, obj.var= iants + ) + ) + cabi =3D CABIStruct(c_name(name), ifcond) + if base: + cabi.add_members(base.members) + cabi.add_members(members) + if variants: + cabi.add_variants(variants) + if (not base or base.is_empty()) and not members and not variants: + cabi.add_member('qapi_dummy_for_empty_struct') + ret.append(cabi) + return ret --=20 2.33.0.113.g6c40894d24 From nobody Tue May 7 11:02:16 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631017796177734.1879514205216; Tue, 7 Sep 2021 05:29:56 -0700 (PDT) Received: from localhost ([::1]:52268 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNaEY-00040e-Ox for importer@patchew.org; Tue, 07 Sep 2021 08:29:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42182) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNa6T-00080E-EZ for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:21:30 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:53656) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNa6Q-0006kV-Kr for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:21:29 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-459-P1qsUGyAP-K7NWmjOvNxuw-1; Tue, 07 Sep 2021 08:21:24 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1CBBF6D58A for ; Tue, 7 Sep 2021 12:21:23 +0000 (UTC) Received: from localhost (unknown [10.39.208.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id 79AA61B46B; Tue, 7 Sep 2021 12:21:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631017285; 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=JjfIS7D5gRlY8u0FConsY0Eqp5GrMUohAFdsVp3sruY=; b=ViLOBIizEk9QdbBB88YGjKARHdaTvUqNvKHj7ZmRnPW3RKEwlUM9+SPFIm4V2bl8hWD6bi 776BUnbAZvLBzXPZtNSJ8FKihwArMkE38UuNTfeH5AFk2KpejfUFODVT88QwjMX8h8f3sb 5NxahAKzrbD8ao7PCEYRlceXSh52dKU= X-MC-Unique: P1qsUGyAP-K7NWmjOvNxuw-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [RFC v3 07/32] scripts/qapi: generate CABI dump for C types Date: Tue, 7 Sep 2021 16:19:18 +0400 Message-Id: <20210907121943.3498701-8-marcandre.lureau@redhat.com> In-Reply-To: <20210907121943.3498701-1-marcandre.lureau@redhat.com> References: <20210907121943.3498701-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=marcandre.lureau@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, berrange@redhat.com, armbru@redhat.com, stefanha@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631017797903100001 From: Marc-Andr=C3=A9 Lureau With type units, generate the C ABI dump functions (as blocks protected with QAPI_CABI define). The top-level function is qapi_cabi(), and it calls the sub-modules dump functions. Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi/types.py | 58 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/scripts/qapi/types.py b/scripts/qapi/types.py index 831294fe42..7ac3645d18 100644 --- a/scripts/qapi/types.py +++ b/scripts/qapi/types.py @@ -13,8 +13,15 @@ # See the COPYING file in the top-level directory. """ =20 -from typing import List, Optional +from pathlib import Path +from typing import ( + Dict, + List, + Optional, + Set, +) =20 +from .cabi import CABI, CABIEnum, gen_object_cabi from .common import c_enum_const, c_name, mcgen from .gen import QAPISchemaModularCVisitor, ifcontext from .schema import ( @@ -22,6 +29,7 @@ QAPISchemaEnumMember, QAPISchemaFeature, QAPISchemaIfCond, + QAPISchemaModule, QAPISchemaObjectType, QAPISchemaObjectTypeMember, QAPISchemaType, @@ -265,6 +273,13 @@ def __init__(self, prefix: str): super().__init__( prefix, 'qapi-types', ' * Schema-defined QAPI types', ' * Built-in QAPI types', __doc__) + self._cabi_functions: List[str] =3D [] + self._cabi_functions_called: Set[str] =3D set() + self._cabi: Dict[str, CABI] =3D {} + + def _cabi_add(self, cabis: List[CABI]) -> None: + for cabi in cabis: + self._cabi.setdefault(cabi.name, cabi) =20 def _begin_builtin_module(self) -> None: self._genc.preamble_add(mcgen(''' @@ -295,6 +310,43 @@ def visit_begin(self, schema: QAPISchema) -> None: # gen_object() is recursive, ensure it doesn't visit the empty type objects_seen.add(schema.the_empty_object_type.name) =20 + def _get_qapi_cabi_fn(self, name: str) -> str: + fn_name =3D 'qapi_cabi' + if QAPISchemaModule.is_builtin_module(name): + fn_name +=3D '_builtin' + elif name !=3D self._main_module: + name =3D Path(name).stem + fn_name +=3D '_' + c_name(name) + return fn_name + + def visit_include(self, name: str, info: Optional[QAPISourceInfo]) -> = None: + super().visit_include(name, info) + cabi_fn =3D self._get_qapi_cabi_fn(name) + if cabi_fn not in self._cabi_functions_called: + self._cabi_functions.append(cabi_fn) + + def visit_module_end(self, name: str) -> None: + cabi_gen =3D "".join(f' {fn}();\n' for fn in self._cabi_functio= ns) + self._cabi_functions_called |=3D set(self._cabi_functions) + self._cabi_functions =3D [] + cabi_gen +=3D "".join([c.gen_c() for _, c in sorted(self._cabi.ite= ms())]) + self._cabi =3D {} + fn_name =3D self._get_qapi_cabi_fn(name) + self._genh.add(mcgen(''' + +#ifdef QAPI_CABI +void %(fn_name)s(void); +#endif +''', fn_name=3Dfn_name)) + self._genc.add(mcgen(''' + +#ifdef QAPI_CABI +void %(fn_name)s(void) { +%(cabi_gen)s +} +#endif +''', fn_name=3Dfn_name, cabi_gen=3Dcabi_gen)) + def _gen_type_cleanup(self, name: str) -> None: self._genh.add(gen_type_cleanup_decl(name)) self._genc.add(gen_type_cleanup(name)) @@ -309,6 +361,7 @@ def visit_enum_type(self, with ifcontext(ifcond, self._genh, self._genc): self._genh.preamble_add(gen_enum(name, members, prefix)) self._genc.add(gen_enum_lookup(name, members, prefix)) + self._cabi_add([CABIEnum(name, ifcond, members, prefix)]) =20 def visit_array_type(self, name: str, @@ -334,6 +387,7 @@ def visit_object_type(self, with ifcontext(ifcond, self._genh): self._genh.preamble_add(gen_fwd_object_or_array(name)) self._genh.add(gen_object(name, ifcond, base, members, variants)) + self._cabi_add(gen_object_cabi(name, ifcond, base, members, varian= ts)) with ifcontext(ifcond, self._genh, self._genc): if base and not base.is_implicit(): self._genh.add(gen_upcast(name, base)) @@ -353,6 +407,8 @@ def visit_alternate_type(self, self._genh.preamble_add(gen_fwd_object_or_array(name)) self._genh.add(gen_object(name, ifcond, None, [variants.tag_member], variants)) + self._cabi_add(gen_object_cabi(name, ifcond, None, + [variants.tag_member], variants)) with ifcontext(ifcond, self._genh, self._genc): self._gen_type_cleanup(name) =20 --=20 2.33.0.113.g6c40894d24 From nobody Tue May 7 11:02:16 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 163101785607099.26546908144314; Tue, 7 Sep 2021 05:30:56 -0700 (PDT) Received: from localhost ([::1]:54066 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNaFa-0005EL-TR for importer@patchew.org; Tue, 07 Sep 2021 08:30:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42254) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNa6d-0008S2-NY for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:21:39 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:47049) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNa6c-0006vz-6S for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:21:39 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-416-iLhSaF51OOq8_chk8L5bow-1; Tue, 07 Sep 2021 08:21:36 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AEDAB107ACFE for ; Tue, 7 Sep 2021 12:21:35 +0000 (UTC) Received: from localhost (unknown [10.39.208.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6919660657; Tue, 7 Sep 2021 12:21:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631017297; 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=yhb2wO8zV56juJYIJDnx8N/SZLKEAf3mSq3zq9xR3OM=; b=XBM1+rV7bS1VjI4pQT2FkOTk10uvT4X++ArK4PQKW7dj9TUjeKUkKok4QU80+DVYJAzu1R FZwpdf+ALsAoY7AcDmiz5mmuMPXyZvgIFunQtVz4Bw467xFVFv9E1jXB1xFo//vxh7JrvB H/t3O/oni8H95PeAm5zxe+msXrMTnCM= X-MC-Unique: iLhSaF51OOq8_chk8L5bow-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [RFC v3 08/32] tests: build qapi-cabi (C ABI dump) Date: Tue, 7 Sep 2021 16:19:19 +0400 Message-Id: <20210907121943.3498701-9-marcandre.lureau@redhat.com> In-Reply-To: <20210907121943.3498701-1-marcandre.lureau@redhat.com> References: <20210907121943.3498701-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=marcandre.lureau@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, berrange@redhat.com, armbru@redhat.com, stefanha@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631017856700100001 From: Marc-Andr=C3=A9 Lureau Signed-off-by: Marc-Andr=C3=A9 Lureau --- tests/qapi-cabi.c | 9 +++++++++ tests/meson.build | 13 +++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 tests/qapi-cabi.c diff --git a/tests/qapi-cabi.c b/tests/qapi-cabi.c new file mode 100644 index 0000000000..2b94edb4ab --- /dev/null +++ b/tests/qapi-cabi.c @@ -0,0 +1,9 @@ +#include "qemu/osdep.h" + +#include "test-qapi-types.h" + +int main(int argc, char *argv[]) +{ + qapi_cabi(); + return 0; +} diff --git a/tests/meson.build b/tests/meson.build index 55a7b08275..be95223d62 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -54,8 +54,17 @@ foreach o: test_qapi_files.to_list() + test_qapi_files_e= xtra.to_list() test_qapi_sources +=3D o endforeach =20 -libtestqapi =3D static_library('testqapi', sources: [genh, test_qapi_sourc= es]) -testqapi =3D declare_dependency(link_with: libtestqapi, sources: [genh, te= st_qapi_headers]) +libtestqapi =3D static_library('testqapi', + sources: [genh, test_qapi_sources], + c_args: ['-DQAPI_CABI']) +testqapi =3D declare_dependency(link_with: libtestqapi, + dependencies: [qemuutil], + sources: [genh, test_qapi_headers]) + +executable('qapi-cabi', + files('qapi-cabi.c'), + dependencies: testqapi, + c_args: ['-DQAPI_CABI']) =20 test_deps =3D { 'test-qht-par': qht_bench, --=20 2.33.0.113.g6c40894d24 From nobody Tue May 7 11:02:16 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16310181847181011.2039605256056; Tue, 7 Sep 2021 05:36:24 -0700 (PDT) Received: from localhost ([::1]:34484 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNaKs-0002w6-Uz for importer@patchew.org; Tue, 07 Sep 2021 08:36:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42294) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNa6q-0000YB-Iv for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:21:52 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:43813) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNa6o-00071C-Vs for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:21:52 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-341-vt7h9C9oN5OXKSRezREk8Q-1; Tue, 07 Sep 2021 08:21:49 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 65CEB104FB69 for ; Tue, 7 Sep 2021 12:21:48 +0000 (UTC) Received: from localhost (unknown [10.39.208.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7E01660C05; Tue, 7 Sep 2021 12:21:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631017310; 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=cL5/XPLTGHu6CtOojeAQ9FFcxzQ35bhD7tEB+PHjy6A=; b=Hd1yfDxCgR3Tr66ovpKvXmduGcGK9nMgxinnRRTaTyZw6Er2yWnM9CZNGobNNtPjO/HF5H 1zTqAc1N0o0hUcKxsQGJe+Z5sV3YJ1u2bsaf8ooDIWlIXXZ9zwkEqrSX2E2nNFMFltv3rB ejpf3vyCwZnU2C/HqR++nE7GTNv2Y3A= X-MC-Unique: vt7h9C9oN5OXKSRezREk8Q-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [RFC v3 09/32] build-sys: add i686 cpu target Date: Tue, 7 Sep 2021 16:19:20 +0400 Message-Id: <20210907121943.3498701-10-marcandre.lureau@redhat.com> In-Reply-To: <20210907121943.3498701-1-marcandre.lureau@redhat.com> References: <20210907121943.3498701-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=marcandre.lureau@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, berrange@redhat.com, armbru@redhat.com, stefanha@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631018186566100001 From: Marc-Andr=C3=A9 Lureau Rust does not have i386 targets, so distinguish when target cpu is i686. Signed-off-by: Marc-Andr=C3=A9 Lureau --- configure | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/configure b/configure index 8adf2127c3..48ff2837d9 100755 --- a/configure +++ b/configure @@ -617,6 +617,8 @@ esac if test ! -z "$cpu" ; then # command line argument : +elif check_define __i686__ ; then + cpu=3D"i686" elif check_define __i386__ ; then cpu=3D"i386" elif check_define __x86_64__ ; then @@ -672,9 +674,12 @@ case "$cpu" in ppc64le) ARCH=3D"ppc64" ;; - i386|i486|i586|i686|i86pc|BePC) + i386|i486|i586|i86pc|BePC) cpu=3D"i386" ;; + i686) + ARCH=3D"i386" + ;; x86_64|amd64) cpu=3D"x86_64" ;; @@ -1673,7 +1678,7 @@ case "$cpu" in CPU_CFLAGS=3D"-m64" QEMU_LDFLAGS=3D"-m64 $QEMU_LDFLAGS" ;; - i386) + i386|i686) CPU_CFLAGS=3D"-m32" QEMU_LDFLAGS=3D"-m32 $QEMU_LDFLAGS" ;; @@ -4396,7 +4401,7 @@ QEMU_GA_MSI_MINGW_DLL_PATH=3D"$($pkg_config --variabl= e=3Dprefix glib-2.0)/bin" =20 # Mac OS X ships with a broken assembler roms=3D -if { test "$cpu" =3D "i386" || test "$cpu" =3D "x86_64"; } && \ +if { test "$cpu" =3D "i386" || test "$cpu" =3D "i686" || test "$cpu" =3D "= x86_64"; } && \ test "$targetos" !=3D "Darwin" && test "$targetos" !=3D "SunOS" &&= \ test "$targetos" !=3D "Haiku" && test "$softmmu" =3D yes ; then # Different host OS linkers have different ideas about the name of the= ELF @@ -4962,7 +4967,7 @@ fi if test "$linux" =3D "yes" ; then mkdir -p linux-headers case "$cpu" in - i386|x86_64|x32) + i386|i686|x86_64|x32) linux_arch=3Dx86 ;; ppc|ppc64|ppc64le) --=20 2.33.0.113.g6c40894d24 From nobody Tue May 7 11:02:16 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631018430884755.189543741207; Tue, 7 Sep 2021 05:40:30 -0700 (PDT) Received: from localhost ([::1]:43074 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNaOr-0000Qa-Th for importer@patchew.org; Tue, 07 Sep 2021 08:40:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42336) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNa75-0001Fz-6l for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:22:07 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:31193) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNa73-00076B-3h for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:22:06 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-188-_uA3K8xYPTu3sqD9kuUmjQ-1; Tue, 07 Sep 2021 08:22:01 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7E793835DE2 for ; Tue, 7 Sep 2021 12:22:00 +0000 (UTC) Received: from localhost (unknown [10.39.208.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id 33A456608B; Tue, 7 Sep 2021 12:21:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631017323; 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=boIguc3k702SLL3dtYGl6A5xhu1pXRPkXWlbNcoqd3Y=; b=Jt6WfeUhR8eFOSrMaV57KcO+PYjJyfvZfmLO5PUDD2lQzmKDVUQldzVvGtZ7O8ApMYilGp INrcqYvrGKoQfrC+znDcf+aUEx2sWKHENor9vap/PuhbhCyuuKpmCOduwZw6qszf/dxeqO Itpv6RWBc5JEpg1m5wdtaUg3pTy4fHc= X-MC-Unique: _uA3K8xYPTu3sqD9kuUmjQ-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [RFC v3 10/32] build-sys: add --with-rust{-target} & basic build infrastructure Date: Tue, 7 Sep 2021 16:19:21 +0400 Message-Id: <20210907121943.3498701-11-marcandre.lureau@redhat.com> In-Reply-To: <20210907121943.3498701-1-marcandre.lureau@redhat.com> References: <20210907121943.3498701-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=marcandre.lureau@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, berrange@redhat.com, armbru@redhat.com, stefanha@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631018432271100001 From: Marc-Andr=C3=A9 Lureau Add the build-sys infrastructure to optionally build Rust code. Introduce a top-level workspace, so various sub-projects (libraries, executables etc) can be developed together, sharing the dependencies and output directory. If not Tier 1 (aarch64 and x86), all of the host architecture QEMU supports should be Tier 2: https://doc.rust-lang.org/nightly/rustc/platform-support.html Rust is generally available on various distributions (thanks to Firefox, I suppose). If not, it can usually be installed with rustup. configure will enable Rust support automatically if cargo is present. Rust support can be disabled --without-rust. When detecting windows cross building, it will use the $cpu-pc-windows-gnu target by default (more default mappings could be added over time). This can be changed with --with-rust-target=3DRTT. Signed-off-by: Marc-Andr=C3=A9 Lureau --- configure | 11 +++++++++++ meson.build | 27 +++++++++++++++++++++++++++ .gitignore | 1 + Cargo.toml | 2 ++ meson_options.txt | 5 +++++ 5 files changed, 46 insertions(+) create mode 100644 Cargo.toml diff --git a/configure b/configure index 48ff2837d9..470b90543f 100755 --- a/configure +++ b/configure @@ -445,6 +445,8 @@ fuse=3D"auto" fuse_lseek=3D"auto" multiprocess=3D"auto" slirp_smbd=3D"$default_feature" +with_rust=3D"auto" +with_rust_target=3D"" =20 malloc_trim=3D"auto" gio=3D"$default_feature" @@ -1586,6 +1588,12 @@ for opt do ;; --disable-slirp-smbd) slirp_smbd=3Dno ;; + --with-rust) with_rust=3Denabled + ;; + --without-rust) with_rust=3Ddisabled + ;; + --with-rust-target=3D*) with_rust_target=3D"$optarg" + ;; *) echo "ERROR: unknown option $opt" echo "Try '$0 --help' for more information" @@ -1773,6 +1781,8 @@ Advanced options (experts only): --extra-ldflags=3DLDFLAGS append extra linker flags LDFLAGS --cross-cc-ARCH=3DCC use compiler when building ARCH guest test ca= ses --cross-cc-flags-ARCH=3D use compiler flags when building ARCH guest t= ests + --with-rust enable Rust compilation + --with-rust-target=3DRTT use the given Rust target triple --make=3DMAKE use specified make [$make] --python=3DPYTHON use specified python [$python] --sphinx-build=3DSPHINX use specified sphinx-build [$sphinx_build] @@ -5199,6 +5209,7 @@ if test "$skip_meson" =3D no; then -Db_coverage=3D$(if test "$gcov" =3D yes; then echo true; else ech= o false; fi) \ -Db_lto=3D$lto -Dcfi=3D$cfi -Dcfi_debug=3D$cfi_debug \ -Dmalloc=3D$malloc -Dmalloc_trim=3D$malloc_trim -Dsparse=3D$sparse= \ + -Dwith_rust=3D$with_rust -Dwith_rust_target=3D$with_rust_target \ -Dkvm=3D$kvm -Dhax=3D$hax -Dwhpx=3D$whpx -Dhvf=3D$hvf -Dnvmm=3D$nv= mm \ -Dxen=3D$xen -Dxen_pci_passthrough=3D$xen_pci_passthrough -Dtcg=3D= $tcg \ -Dcocoa=3D$cocoa -Dgtk=3D$gtk -Dmpath=3D$mpath -Dsdl=3D$sdl -Dsdl_= image=3D$sdl_image \ diff --git a/meson.build b/meson.build index cbf3ce19ae..63b61a2bc8 100644 --- a/meson.build +++ b/meson.build @@ -108,6 +108,29 @@ endif =20 bzip2 =3D find_program('bzip2', required: install_edk2_blobs) =20 +cargo =3D find_program('cargo', required: get_option('with_rust')) +with_rust =3D cargo.found() + +if with_rust + rust_target_triple =3D get_option('with_rust_target') + if meson.is_cross_build() + # more default target mappings may be added over time + if rust_target_triple =3D=3D '' and targetos =3D=3D 'windows' + rust_target_triple =3D host_machine.cpu() + '-pc-windows-gnu' + endif + if rust_target_triple =3D=3D '' + error('cross-compiling, but no Rust target-triple defined.') + endif + endif +endif +config_host_data.set('CONFIG_WITH_RUST', with_rust) + +if get_option('optimization') in ['0', '1', 'g'] + rs_build_type =3D 'debug' +else + rs_build_type =3D 'release' +endif + ################## # Compiler flags # ################## @@ -2916,6 +2939,10 @@ if targetos =3D=3D 'windows' summary_info +=3D {'Windows SDK': config_host['WIN_SDK']} endif endif +summary_info +=3D {'Rust support': with_rust} +if with_rust and rust_target_triple !=3D '' + summary_info +=3D {'Rust target': rust_target_triple} +endif summary_info +=3D {'CFLAGS': ' '.join(get_option('c_args') + ['-O' + get_option('optim= ization')] + (get_option('debug') ? ['= -g'] : []))} diff --git a/.gitignore b/.gitignore index eb2553026c..78715bc7c4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ /GNUmakefile /build/ +/target/ *.pyc .sdk .stgit-* diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000000..c4b464ff15 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,2 @@ +[workspace] +members =3D [] diff --git a/meson_options.txt b/meson_options.txt index a9a9b8f4c6..fe9f90634b 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -155,3 +155,8 @@ option('slirp', type: 'combo', value: 'auto', option('fdt', type: 'combo', value: 'auto', choices: ['disabled', 'enabled', 'auto', 'system', 'internal'], description: 'Whether and how to find the libfdt library') + +option('with_rust', type: 'feature', value: 'auto', + description: 'Enable Rust support') +option('with_rust_target', type : 'string', value: '', + description: 'Rust target triple') --=20 2.33.0.113.g6c40894d24 From nobody Tue May 7 11:02:16 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631018374926234.7473376392095; Tue, 7 Sep 2021 05:39:34 -0700 (PDT) Received: from localhost ([::1]:41218 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNaNu-0007c0-4G for importer@patchew.org; Tue, 07 Sep 2021 08:39:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42362) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNa7I-0001h7-8D for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:22:20 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:57835) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNa7G-0007Cs-1v for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:22:19 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-203-UiGAd1t9Na-el_nVXqaVaQ-1; Tue, 07 Sep 2021 08:22:14 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AE181835DE0 for ; Tue, 7 Sep 2021 12:22:13 +0000 (UTC) Received: from localhost (unknown [10.39.208.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7893560C05; Tue, 7 Sep 2021 12:22:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631017337; 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=QymyblDEC6rv1SaxuKQC3kFmPh5fKbgp+9dEys/vwcY=; b=TQ9Jsw1lTUoZOTPcfc2lInqsIqUae2bfjgCfQqI9rIPC41J6f4+KGUrbSWx2PmRQChpELu U4ACHR7KtHN10Okkis07dP0IOU8tuqcAzEH6PlMTsm0KXHSTHEMmlOWqMsNSq5muWTe5dJ z97j09fZK12BAehDQMgeYjmdUxc8hbA= X-MC-Unique: UiGAd1t9Na-el_nVXqaVaQ-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [RFC v3 11/32] build-sys: add a cargo-wrapper script Date: Tue, 7 Sep 2021 16:19:22 +0400 Message-Id: <20210907121943.3498701-12-marcandre.lureau@redhat.com> In-Reply-To: <20210907121943.3498701-1-marcandre.lureau@redhat.com> References: <20210907121943.3498701-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=marcandre.lureau@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, berrange@redhat.com, armbru@redhat.com, stefanha@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631018375372100001 From: Marc-Andr=C3=A9 Lureau Introduce a script to help calling cargo from Rust. This script will help to invoke cargo in different ways. For now, it supports building static libraries and binaries. It sets up a common environment, run the compiler with config-host options (config-target to be added later when needed) and grep the compile output for the linker flags. Finally it copies the built artefact to the expected meson output directory, and create a file with the linker arguments. cargo is the most convenient way to build Rust code, with various crate dependencies, tests, and has features that meson lacks in general for Rust. Trying to convert projects to meson automatically is an option I considered seriously (see for ex https://github.com/badboy/bygge for ninja conversion), but the complexity of the task makes this endeavour out of scope at this point. External dependencies would suffer various issues that would be hard to implement and get accepted. Signed-off-by: Marc-Andr=C3=A9 Lureau --- meson.build | 4 + scripts/cargo_wrapper.py | 182 ++++++++++++++++++++++++++++++++++++++ scripts/configh_to_cfg.py | 44 +++++++++ 3 files changed, 230 insertions(+) create mode 100644 scripts/cargo_wrapper.py create mode 100644 scripts/configh_to_cfg.py diff --git a/meson.build b/meson.build index 63b61a2bc8..a21c70d77f 100644 --- a/meson.build +++ b/meson.build @@ -110,6 +110,10 @@ bzip2 =3D find_program('bzip2', required: install_edk2= _blobs) =20 cargo =3D find_program('cargo', required: get_option('with_rust')) with_rust =3D cargo.found() +cargo_wrapper =3D [ + find_program('scripts/cargo_wrapper.py'), + '--configh', meson.current_build_dir() / 'config-host.h' +] =20 if with_rust rust_target_triple =3D get_option('with_rust_target') diff --git a/scripts/cargo_wrapper.py b/scripts/cargo_wrapper.py new file mode 100644 index 0000000000..75518e8c02 --- /dev/null +++ b/scripts/cargo_wrapper.py @@ -0,0 +1,182 @@ +#!/usr/bin/env python3 +# Copyright (c) 2020 Red Hat, Inc. +# +# Author: +# Marc-Andr=C3=A9 Lureau +# +# This work is licensed under the terms of the GNU GPL, version 2 or +# later. See the COPYING file in the top-level directory. + +import argparse +import configparser +import distutils.file_util +import json +import logging +import os +import os.path +import re +import subprocess +import sys +from pathlib import Path +from typing import Any, Dict, List, Tuple + +from configh_to_cfg import generate_cfg + + +def get_rustc_target_spec(target_triple: str) -> Any: + cmd =3D [ + "rustc", + "+nightly", + "-Z", + "unstable-options", + "--print", + "target-spec-json", + ] + if target_triple: + cmd +=3D ["--target", target_triple] + + out =3D subprocess.check_output(cmd) + return json.loads(out) + + +def get_exe_suffix(target_triple: str) -> str: + try: + # this will fail if nightly is not installed + spec =3D get_rustc_target_spec(target_triple) + return spec.get("exe-suffix", "") + except: # pylint: disable=3DW0702 + # let's implement a simple fallback + if 'windows' in target_triple: + return '.exe' + return '' + + +def get_cargo_target_dir(args: argparse.Namespace) -> str: + # avoid conflict with qemu "target" directory + return os.path.join(args.build_dir, "rs-target") + + +def get_manifest_path(args: argparse.Namespace) -> str: + return os.path.join(args.src_dir, "Cargo.toml") + + +def get_cargo_rustc( + cargo_rustc_args: List[str], args: argparse.Namespace +) -> Tuple[Dict[str, Any], List[str]]: + cfg =3D [c for h in args.configh for c in generate_cfg(h)] + target_dir =3D get_cargo_target_dir(args) + manifest_path =3D get_manifest_path(args) + + env =3D {} + env["MESON_CURRENT_BUILD_DIR"] =3D args.build_dir + env["MESON_BUILD_ROOT"] =3D args.build_root + env["WINAPI_NO_BUNDLED_LIBRARIES"] =3D "1" + cargo_cmd =3D [ + "cargo", + "rustc", + "--target-dir", + target_dir, + "--manifest-path", + manifest_path, + ] + cargo_cmd +=3D cargo_rustc_args + if args.target_triple: + cargo_cmd +=3D ["--target", args.target_triple] + if args.build_type =3D=3D "release": + cargo_cmd +=3D ["--release"] + cargo_cmd +=3D ["--"] + cfg + args.EXTRA + + return (env, cargo_cmd) + + +def run_cargo(env: Dict[str, Any], cargo_cmd: List[str]) -> str: + envlog =3D " ".join(["{}=3D{}".format(k, v) for k, v in env.items()]) + cmdlog =3D " ".join(cargo_cmd) + logging.debug("Running %s %s", envlog, cmdlog) + try: + out =3D subprocess.check_output( + cargo_cmd, + env=3Ddict(os.environ, **env), + stderr=3Dsubprocess.STDOUT, + universal_newlines=3DTrue, + ) + except subprocess.CalledProcessError as err: + print("Environment: " + envlog) + print("Command: " + cmdlog) + print(err.output) + sys.exit(1) + + return out + + +def build_lib(args: argparse.Namespace) -> None: + logging.debug('build-lib') + target_dir =3D get_cargo_target_dir(args) + manifest_path =3D get_manifest_path(args) + # let's pretend it's an INI file to avoid extra toml dependency + config =3D configparser.ConfigParser() + config.read(manifest_path) + package_name =3D config["package"]["name"].strip('"').replace('-', '_') + liba =3D os.path.join( + target_dir, args.target_triple, args.build_type, "lib" + package_n= ame + ".a" + ) + libargs =3D os.path.join(args.build_dir, "lib" + package_name + ".args= ") + + env, cargo_cmd =3D get_cargo_rustc(["--lib"], args) + cargo_cmd +=3D ["--print", "native-static-libs"] + out =3D run_cargo(env, cargo_cmd) + native_static_libs =3D re.search(r"native-static-libs:(.*)", out) + link_args =3D native_static_libs.group(1) + with open(libargs, "w") as file: + print(link_args, file=3Dfile) + logging.debug("cp %s %s", liba, args.build_dir) + distutils.file_util.copy_file(liba, args.build_dir, update=3DTrue) + + +def build_bin(args: argparse.Namespace) -> None: + logging.debug('build-bin') + env, cargo_cmd =3D get_cargo_rustc(["--bin", args.bin], args) + exe_suffix =3D get_exe_suffix(args.target_triple) + run_cargo(env, cargo_cmd) + target_dir =3D get_cargo_target_dir(args) + path =3D os.path.join( + target_dir, args.target_triple, args.build_type, args.bin + exe_su= ffix + ) + dest =3D args.build_dir + if args.rename: + dest =3D Path(dest) / args.rename + logging.debug("cp %s %s", path, dest) + distutils.file_util.copy_file(path, dest, update=3DTrue) + + +def main() -> None: + parser =3D argparse.ArgumentParser() + parser.add_argument("-v", "--verbose", action=3D'store_true') + parser.add_argument("--configh", action=3D'append', default=3D[]) + parser.add_argument("build_dir") + parser.add_argument("src_dir") + parser.add_argument("build_root") + parser.add_argument("build_type") + parser.add_argument("target_triple") + subparsers =3D parser.add_subparsers() + + buildlib =3D subparsers.add_parser("build-lib") + buildlib.add_argument("EXTRA", nargs=3D"*") + buildlib.set_defaults(func=3Dbuild_lib) + + buildbin =3D subparsers.add_parser("build-bin") + buildbin.add_argument("--rename") + buildbin.add_argument("bin") + buildbin.add_argument("EXTRA", nargs=3D"*") + buildbin.set_defaults(func=3Dbuild_bin) + + args =3D parser.parse_args() + if args.verbose: + logging.basicConfig(level=3Dlogging.DEBUG) + logging.debug('args: %s', args) + + args.func(args) + + +if __name__ =3D=3D "__main__": + main() diff --git a/scripts/configh_to_cfg.py b/scripts/configh_to_cfg.py new file mode 100644 index 0000000000..b8f0c2da9a --- /dev/null +++ b/scripts/configh_to_cfg.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python3 +# Copyright (c) 2020 Red Hat, Inc. +# +# Author: +# Marc-Andr=C3=A9 Lureau +# +# This work is licensed under the terms of the GNU GPL, version 2 or +# later. See the COPYING file in the top-level directory. + +import argparse +from typing import List + + +def cfg_name(name: str) -> str: + if name.startswith("CONFIG_") or name.startswith("TARGET_") or name.st= artswith("HAVE_"): + return name + return "" + + +def generate_cfg(header: str) -> List[str]: + with open(header, encoding=3D"utf-8") as cfg: + config =3D [l.split()[1:] for l in cfg if l.startswith("#define")] + + cfg_list =3D [] + for cfg in config: + name =3D cfg_name(cfg[0]) + if not name: + continue + if len(cfg) >=3D 2 and cfg[1] !=3D "1": + continue + cfg_list.append("--cfg") + cfg_list.append(name) + return cfg_list + + +def main() -> None: + parser =3D argparse.ArgumentParser() + parser.add_argument("HEADER") + args =3D parser.parse_args() + print(" ".join(generate_cfg(args.HEADER))) + + +if __name__ =3D=3D "__main__": + main() --=20 2.33.0.113.g6c40894d24 From nobody Tue May 7 11:02:16 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631018609705282.82630603177813; Tue, 7 Sep 2021 05:43:29 -0700 (PDT) Received: from localhost ([::1]:49816 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNaRk-00054N-Hw for importer@patchew.org; Tue, 07 Sep 2021 08:43:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42400) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNa7X-0002H4-Mq for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:22:35 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:55880) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNa7U-0007SU-60 for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:22:35 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-584--c2sdhmjO8205pYD-hgvfQ-1; Tue, 07 Sep 2021 08:22:29 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A0E74802947 for ; Tue, 7 Sep 2021 12:22:28 +0000 (UTC) Received: from localhost (unknown [10.39.208.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id C5504369A; Tue, 7 Sep 2021 12:22:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631017350; 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=DmqgzU2LG+o+OcknvY+PT66pHvYdgIWiDiBRiE4H3mQ=; b=ZD4/rrPXmggrS9yX4MqMiR2WwMr0D3oWqDF41XKG6MQvjO4IV1f/L7PzHY1C+Dw1vXEKya x6V6Wqac8Osrfk1G3boHxhE4vYy3Sll4vVCMnJ9jSZJTW5vgv92NKcyR7ZlEsv2JPfmPnl b/iks1VjWKh0vnajrq6+KY8ssBM/uRQ= X-MC-Unique: -c2sdhmjO8205pYD-hgvfQ-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [RFC v3 12/32] rust: provide a common crate for QEMU Date: Tue, 7 Sep 2021 16:19:23 +0400 Message-Id: <20210907121943.3498701-13-marcandre.lureau@redhat.com> In-Reply-To: <20210907121943.3498701-1-marcandre.lureau@redhat.com> References: <20210907121943.3498701-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=marcandre.lureau@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, berrange@redhat.com, armbru@redhat.com, stefanha@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631018611208100001 From: Marc-Andr=C3=A9 Lureau This crates provides common bindings and facilities for QEMU C API shared by various projects. Most importantly, it defines the conversion traits used to convert from C to Rust types. Those traits are largely adapted from glib-rs, since those have proved to be very flexible, and should guide us to bind further QEMU types such as QOM. If glib-rs becomes a dependency, we should consider adopting glib translate traits. For QAPI, we need a smaller subset. Cargo.lock is checked-in, as QEMU produces end-of-chain binaries, and it is desirable to track the exact set of packages that are involved in managed builds. Signed-off-by: Marc-Andr=C3=A9 Lureau --- Cargo.lock | 63 +++++ Cargo.toml | 4 +- rust/common/Cargo.toml | 11 + rust/common/src/error.rs | 113 ++++++++ rust/common/src/ffi.rs | 93 +++++++ rust/common/src/lib.rs | 21 ++ rust/common/src/qemu.rs | 101 ++++++++ rust/common/src/qmp.rs | 0 rust/common/src/translate.rs | 482 +++++++++++++++++++++++++++++++++++ 9 files changed, 887 insertions(+), 1 deletion(-) create mode 100644 Cargo.lock create mode 100644 rust/common/Cargo.toml create mode 100644 rust/common/src/error.rs create mode 100644 rust/common/src/ffi.rs create mode 100644 rust/common/src/lib.rs create mode 100644 rust/common/src/qemu.rs create mode 100644 rust/common/src/qmp.rs create mode 100644 rust/common/src/translate.rs diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000000..8dc2dd9da7 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,63 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version =3D 3 + +[[package]] +name =3D "autocfg" +version =3D "1.0.1" +source =3D "registry+https://github.com/rust-lang/crates.io-index" +checksum =3D "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a= 464a" + +[[package]] +name =3D "bitflags" +version =3D "1.2.1" +source =3D "registry+https://github.com/rust-lang/crates.io-index" +checksum =3D "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d69= 1693" + +[[package]] +name =3D "cc" +version =3D "1.0.70" +source =3D "registry+https://github.com/rust-lang/crates.io-index" +checksum =3D "d26a6ce4b6a484fa3edb70f7efa6fc430fd2b87285fe8b84304fd0936faa= 0dc0" + +[[package]] +name =3D "cfg-if" +version =3D "1.0.0" +source =3D "registry+https://github.com/rust-lang/crates.io-index" +checksum =3D "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da= 40fd" + +[[package]] +name =3D "common" +version =3D "0.1.0" +dependencies =3D [ + "libc", + "nix", +] + +[[package]] +name =3D "libc" +version =3D "0.2.101" +source =3D "registry+https://github.com/rust-lang/crates.io-index" +checksum =3D "3cb00336871be5ed2c8ed44b60ae9959dc5b9f08539422ed43f09e34ecae= ba21" + +[[package]] +name =3D "memoffset" +version =3D "0.6.4" +source =3D "registry+https://github.com/rust-lang/crates.io-index" +checksum =3D "59accc507f1338036a0477ef61afdae33cde60840f4dfe481319ce3ad116= ddf9" +dependencies =3D [ + "autocfg", +] + +[[package]] +name =3D "nix" +version =3D "0.20.1" +source =3D "registry+https://github.com/rust-lang/crates.io-index" +checksum =3D "df8e5e343312e7fbeb2a52139114e9e702991ef9c2aea6817ff2440b3564= 7d56" +dependencies =3D [ + "bitflags", + "cc", + "cfg-if", + "libc", + "memoffset", +] diff --git a/Cargo.toml b/Cargo.toml index c4b464ff15..14131eed3c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,2 +1,4 @@ [workspace] -members =3D [] +members =3D [ + "rust/common", +] diff --git a/rust/common/Cargo.toml b/rust/common/Cargo.toml new file mode 100644 index 0000000000..6c240447f3 --- /dev/null +++ b/rust/common/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name =3D "common" +version =3D "0.1.0" +edition =3D "2018" +publish =3D false + +[dependencies] +libc =3D "0.2.92" + +[target."cfg(unix)".dependencies] +nix =3D "0.20.0" diff --git a/rust/common/src/error.rs b/rust/common/src/error.rs new file mode 100644 index 0000000000..f166ac42ea --- /dev/null +++ b/rust/common/src/error.rs @@ -0,0 +1,113 @@ +use std::{self, ffi::CString, fmt, io, ptr}; + +use crate::translate::*; +use crate::{ffi, qemu}; + +/// Common error type for QEMU and related projects. +#[derive(Debug)] +pub enum Error { + /// A generic error with file and line location. + FailedAt(String, &'static str, u32), + /// An IO error. + Io(io::Error), + #[cfg(unix)] + /// A nix error. + Nix(nix::Error), +} + +/// Alias for a `Result` with the error type for QEMU. +pub type Result =3D std::result::Result; + +impl Error { + fn message(&self) -> String { + use Error::*; + match self { + FailedAt(msg, _, _) =3D> msg.into(), + Io(io) =3D> format!("IO error: {}", io), + #[cfg(unix)] + Nix(nix) =3D> format!("Nix error: {}", nix), + } + } + + fn location(&self) -> Option<(&'static str, u32)> { + use Error::*; + match self { + FailedAt(_, file, line) =3D> Some((file, *line)), + Io(_) =3D> None, + #[cfg(unix)] + Nix(_) =3D> None, + } + } +} + +impl fmt::Display for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + use Error::*; + match self { + FailedAt(msg, file, line) =3D> write!(f, "{} ({}:{})", msg, fi= le, line), + _ =3D> write!(f, "{}", self.message()), + } + } +} + +impl From for Error { + fn from(val: io::Error) -> Self { + Error::Io(val) + } +} + +#[cfg(unix)] +impl From for Error { + fn from(val: nix::Error) -> Self { + Error::Nix(val) + } +} + +impl QemuPtrDefault for Error { + type QemuType =3D *mut ffi::Error; +} + +impl<'a> ToQemuPtr<'a, *mut ffi::Error> for Error { + type Storage =3D qemu::CError; + + fn to_qemu_none(&'a self) -> Stash<'a, *mut ffi::Error, Self> { + let err =3D self.to_qemu_full(); + + Stash(err, unsafe { from_qemu_full(err) }) + } + + fn to_qemu_full(&self) -> *mut ffi::Error { + let cmsg =3D + CString::new(self.message()).expect("ToQemuPtr: unexpec= ted '\0' character"); + let mut csrc =3D CString::new("").unwrap(); + let (src, line) =3D self.location().map_or((ptr::null(), 0_i32), |= loc| { + csrc =3D CString::new(loc.0).expect("ToQemuPtr:: unexpe= cted '\0' character"); + (csrc.as_ptr() as *const libc::c_char, loc.1 as i32) + }); + let func =3D ptr::null(); + + let mut err: *mut ffi::Error =3D ptr::null_mut(); + unsafe { + ffi::error_setg_internal( + &mut err as *mut *mut _, + src, + line, + func, + cmsg.as_ptr() as *const libc::c_char, + ); + err + } + } +} + +/// Convenience macro to build a [`Error::FailedAt`] error. +/// +/// Returns a `Result::Err` with the file:line location. +/// (the error can then be converted to a QEMU `ffi::Error`) +#[allow(unused_macros)] +#[macro_export] +macro_rules! err { + ($msg:expr) =3D> { + Err(Error::FailedAt($msg.into(), file!(), line!())) + }; +} diff --git a/rust/common/src/ffi.rs b/rust/common/src/ffi.rs new file mode 100644 index 0000000000..82818d503a --- /dev/null +++ b/rust/common/src/ffi.rs @@ -0,0 +1,93 @@ +//! Bindings to the raw low-level C API commonly provided by QEMU projects. +//! +//! Manual bindings to C API availabe when linking QEMU projects. +//! It includes minimal glib allocation functions too, since it's the defa= ult +//! allocator used by QEMU, and we don't depend on glib-rs crate yet). +//! +//! Higher-level Rust-friendly bindings are provided by different modules. + +use libc::{c_char, c_void, size_t}; + +extern "C" { + pub fn g_malloc0(n_bytes: size_t) -> *mut c_void; + pub fn g_free(ptr: *mut c_void); + pub fn g_strndup(str: *const c_char, n: size_t) -> *mut c_char; +} + +#[repr(C)] +pub struct QObject(c_void); + +impl ::std::fmt::Debug for QObject { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + f.debug_struct(&format!("QObject @ {:?}", self as *const _)) + .finish() + } +} + +#[repr(C)] +pub struct QNull(c_void); + +impl ::std::fmt::Debug for QNull { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + f.debug_struct(&format!("QNull @ {:?}", self as *const _)) + .finish() + } +} + +#[repr(C)] +pub struct Error(c_void); + +impl ::std::fmt::Debug for Error { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + f.debug_struct(&format!("Error @ {:?}", self as *const _)) + .finish() + } +} + +extern "C" { + pub fn error_setg_internal( + errp: *mut *mut Error, + src: *const c_char, + line: i32, + func: *const c_char, + fmt: *const c_char, + ... + ); + pub fn error_get_pretty(err: *const Error) -> *const c_char; + pub fn error_free(err: *mut Error); +} + +/// Wrap a QMP hanlder. +#[macro_export] +macro_rules! qmp { + // the basic return value variant + ($e:expr, $errp:ident, $errval:expr) =3D> {{ + assert!(!$errp.is_null()); + unsafe { + *$errp =3D std::ptr::null_mut(); + } + + match $e { + Ok(val) =3D> val, + Err(err) =3D> unsafe { + *$errp =3D err.to_qemu_full(); + $errval + }, + } + }}; + // the ptr return value variant + ($e:expr, $errp:ident) =3D> {{ + assert!(!$errp.is_null()); + unsafe { + *$errp =3D std::ptr::null_mut(); + } + + match $e { + Ok(val) =3D> val.to_qemu_full().into(), + Err(err) =3D> unsafe { + *$errp =3D err.to_qemu_full(); + std::ptr::null_mut() + }, + } + }}; +} diff --git a/rust/common/src/lib.rs b/rust/common/src/lib.rs new file mode 100644 index 0000000000..4de826bc2e --- /dev/null +++ b/rust/common/src/lib.rs @@ -0,0 +1,21 @@ +//! Common code for QEMU +//! +//! This crates provides common bindings and facilities for QEMU C API sha= red by +//! various projects. Most importantly, it defines the conversion traits u= sed to +//! convert from C to Rust types. Those traits are largely adapted from gl= ib-rs, +//! since those have prooven to be very flexible, and should guide us to b= ind +//! further QEMU types such as QOM. If glib-rs becomes a dependency, we sh= ould +//! consider adopting glib translate traits. For QAPI, we need a smaller s= ubset. + +pub use libc; + +mod error; +pub use error::*; + +mod qemu; +pub use qemu::*; + +mod translate; +pub use translate::*; + +pub mod ffi; diff --git a/rust/common/src/qemu.rs b/rust/common/src/qemu.rs new file mode 100644 index 0000000000..dd01c6d92d --- /dev/null +++ b/rust/common/src/qemu.rs @@ -0,0 +1,101 @@ +use std::{ffi::CStr, ptr, str}; + +use crate::{ffi, translate}; +use translate::{FromQemuPtrFull, FromQemuPtrNone, QemuPtrDefault, Stash, T= oQemuPtr}; + +/// A type representing an owned C QEMU Error. +pub struct CError(ptr::NonNull); + +impl translate::FromQemuPtrFull<*mut ffi::Error> for CError { + unsafe fn from_qemu_full(ptr: *mut ffi::Error) -> Self { + assert!(!ptr.is_null()); + Self(ptr::NonNull::new_unchecked(ptr)) + } +} + +impl CError { + pub fn pretty(&self) -> &str { + unsafe { + let pretty =3D ffi::error_get_pretty(self.0.as_ptr()); + let bytes =3D CStr::from_ptr(pretty).to_bytes(); + str::from_utf8(bytes) + .unwrap_or_else(|err| str::from_utf8(&bytes[..err.valid_up= _to()]).unwrap()) + } + } +} + +impl Drop for CError { + fn drop(&mut self) { + unsafe { ffi::error_free(self.0.as_ptr()) } + } +} + +/// QObject (JSON object) +#[derive(Clone, Debug)] +pub struct QObject; + +impl QemuPtrDefault for QObject { + type QemuType =3D *mut ffi::QObject; +} + +impl FromQemuPtrFull<*mut ffi::QObject> for QObject { + #[inline] + unsafe fn from_qemu_full(_ffi: *mut ffi::QObject) -> Self { + unimplemented!() + } +} + +impl FromQemuPtrNone<*const ffi::QObject> for QObject { + #[inline] + unsafe fn from_qemu_none(_ffi: *const ffi::QObject) -> Self { + unimplemented!() + } +} + +impl<'a> ToQemuPtr<'a, *mut ffi::QObject> for QObject { + type Storage =3D (); + + #[inline] + fn to_qemu_none(&self) -> Stash<'a, *mut ffi::QObject, QObject> { + unimplemented!() + } + #[inline] + fn to_qemu_full(&self) -> *mut ffi::QObject { + unimplemented!() + } +} + +/// QNull (JSON null) +#[derive(Clone, Debug)] +pub struct QNull; + +impl QemuPtrDefault for QNull { + type QemuType =3D *mut ffi::QNull; +} + +impl FromQemuPtrFull<*mut ffi::QObject> for QNull { + #[inline] + unsafe fn from_qemu_full(_ffi: *mut ffi::QObject) -> Self { + unimplemented!() + } +} + +impl FromQemuPtrNone<*const ffi::QObject> for QNull { + #[inline] + unsafe fn from_qemu_none(_ffi: *const ffi::QObject) -> Self { + unimplemented!() + } +} + +impl<'a> ToQemuPtr<'a, *mut ffi::QNull> for QNull { + type Storage =3D (); + + #[inline] + fn to_qemu_none(&self) -> Stash<'a, *mut ffi::QNull, QNull> { + unimplemented!() + } + #[inline] + fn to_qemu_full(&self) -> *mut ffi::QNull { + unimplemented!() + } +} diff --git a/rust/common/src/qmp.rs b/rust/common/src/qmp.rs new file mode 100644 index 0000000000..e69de29bb2 diff --git a/rust/common/src/translate.rs b/rust/common/src/translate.rs new file mode 100644 index 0000000000..315e14fa25 --- /dev/null +++ b/rust/common/src/translate.rs @@ -0,0 +1,482 @@ +// largely adapted from glib-rs +// we don't depend on glib-rs as this brings a lot more code that we may n= ot need +// and also because there are issues with the conversion traits for our ff= i::*mut. +use libc::{c_char, size_t}; +use std::ffi::{CStr, CString}; +use std::ptr; + +use crate::ffi; + +/// A pointer. +pub trait Ptr: Copy + 'static { + fn is_null(&self) -> bool; + fn from(ptr: *mut X) -> Self; + fn to(self) -> *mut X; +} + +impl Ptr for *const T { + #[inline] + fn is_null(&self) -> bool { + (*self).is_null() + } + + #[inline] + fn from(ptr: *mut X) -> *const T { + ptr as *const T + } + + #[inline] + fn to(self) -> *mut X { + self as *mut X + } +} + +impl Ptr for *mut T { + #[inline] + fn is_null(&self) -> bool { + (*self).is_null() + } + + #[inline] + fn from(ptr: *mut X) -> *mut T { + ptr as *mut T + } + + #[inline] + fn to(self) -> *mut X { + self as *mut X + } +} + +/// Macro to declare a `NewPtr` struct. +/// +/// A macro to declare a newtype for pointers, to workaround that *T are n= ot +/// defined in our binding crates, and allow foreign traits implementation= s. +/// (this is used by qapi-gen bindings) +#[allow(unused_macros)] +#[macro_export] +#[doc(hidden)] +macro_rules! new_ptr { + () =3D> { + #[derive(Copy, Clone)] + pub struct NewPtr(pub P); + + impl Ptr for NewPtr

{ + #[inline] + fn is_null(&self) -> bool { + self.0.is_null() + } + + #[inline] + fn from(ptr: *mut X) -> Self { + NewPtr(P::from(ptr)) + } + + #[inline] + fn to(self) -> *mut X { + self.0.to() + } + } + }; +} + +/// Provides the default pointer type to be used in some container convers= ions. +/// +/// It's `*mut c_char` for `String`, `*mut ffi::GuestInfo` for `GuestInfo`= ... +pub trait QemuPtrDefault { + type QemuType: Ptr; +} + +impl QemuPtrDefault for String { + type QemuType =3D *mut c_char; +} + +/// A Stash contains the temporary storage and a pointer into it. +/// +/// The pointer is valid for the lifetime of the `Stash`. As the lifetime = of the +/// `Stash` returned from `to_qemu_none` is at least the enclosing stateme= nt, +/// you can avoid explicitly binding the stash in most cases and just take= the +/// pointer out of it: +/// +/// ```ignore +/// pub fn set_device_name(&self, name: &str) { +/// unsafe { +/// ffi::qemu_device_set_name(self.pointer, name.to_qemu_none(= ).0) +/// } +/// } +/// ``` +pub struct Stash<'a, P: Copy, T: ?Sized + ToQemuPtr<'a, P>>( + pub P, + pub >::Storage, +); + +/// Translate to a pointer. +pub trait ToQemuPtr<'a, P: Copy> { + type Storage; + + /// The pointer in the `Stash` is only valid for the lifetime of the `= Stash`. + fn to_qemu_none(&'a self) -> Stash<'a, P, Self>; + + /// Transfer the ownership to the ffi. + fn to_qemu_full(&self) -> P { + unimplemented!(); + } +} + +impl<'a, P: Ptr, T: ToQemuPtr<'a, P>> ToQemuPtr<'a, P> for Option { + type Storage =3D Option<>::Storage>; + + #[inline] + fn to_qemu_none(&'a self) -> Stash<'a, P, Option> { + self.as_ref() + .map_or(Stash(Ptr::from::<()>(ptr::null_mut()), None), |s| { + let s =3D s.to_qemu_none(); + Stash(s.0, Some(s.1)) + }) + } + + #[inline] + fn to_qemu_full(&self) -> P { + self.as_ref() + .map_or(Ptr::from::<()>(ptr::null_mut()), ToQemuPtr::to_qemu_f= ull) + } +} + +impl<'a, P: Ptr, T: ToQemuPtr<'a, P>> ToQemuPtr<'a, P> for Box { + type Storage =3D >::Storage; + + #[inline] + fn to_qemu_none(&'a self) -> Stash<'a, P, Box> { + let s =3D self.as_ref().to_qemu_none(); + Stash(s.0, s.1) + } + + #[inline] + fn to_qemu_full(&self) -> P { + ToQemuPtr::to_qemu_full(self.as_ref()) + } +} + +impl<'a> ToQemuPtr<'a, *mut c_char> for String { + type Storage =3D CString; + + #[inline] + fn to_qemu_none(&self) -> Stash<'a, *mut c_char, String> { + let tmp =3D CString::new(&self[..]) + .expect("String::ToQemuPtr<*mut c_char>: unexpected '\0' chara= cter"); + Stash(tmp.as_ptr() as *mut c_char, tmp) + } + + #[inline] + fn to_qemu_full(&self) -> *mut c_char { + unsafe { ffi::g_strndup(self.as_ptr() as *const c_char, self.len()= as size_t) } + } +} + +/// Translate from a pointer type, without taking ownership. +pub trait FromQemuPtrNone: Sized { + /// # Safety + /// + /// `ptr` must be a valid pointer. It is not referenced after the call. + unsafe fn from_qemu_none(ptr: P) -> Self; +} + +/// Translate from a pointer type, taking ownership. +pub trait FromQemuPtrFull: Sized { + /// # Safety + /// + /// `ptr` must be a valid pointer. Ownership is transferred. + unsafe fn from_qemu_full(ptr: P) -> Self; +} + +/// See [`FromQemuPtrNone`](trait.FromQemuPtrNone.html). +#[inline] +#[allow(clippy::missing_safety_doc)] +pub unsafe fn from_qemu_none>(ptr: P) -> T { + FromQemuPtrNone::from_qemu_none(ptr) +} + +/// See [`FromQemuPtrFull`](trait.FromQemuPtrFull.html). +#[inline] +#[allow(clippy::missing_safety_doc)] +pub unsafe fn from_qemu_full>(ptr: P) -> T { + FromQemuPtrFull::from_qemu_full(ptr) +} + +impl> FromQemuPtrNone

for Option { + #[inline] + unsafe fn from_qemu_none(ptr: P) -> Option { + if ptr.is_null() { + None + } else { + Some(from_qemu_none(ptr)) + } + } +} + +impl> FromQemuPtrFull

for Option { + #[inline] + unsafe fn from_qemu_full(ptr: P) -> Option { + if ptr.is_null() { + None + } else { + Some(from_qemu_full(ptr)) + } + } +} + +impl FromQemuPtrNone<*const c_char> for String { + #[inline] + unsafe fn from_qemu_none(ptr: *const c_char) -> Self { + assert!(!ptr.is_null()); + String::from_utf8_lossy(CStr::from_ptr(ptr).to_bytes()).into_owned= () + } +} + +impl FromQemuPtrFull<*mut c_char> for String { + #[inline] + unsafe fn from_qemu_full(ptr: *mut c_char) -> Self { + let res =3D from_qemu_none(ptr as *const _); + ffi::g_free(ptr as *mut _); + res + } +} + +#[doc(hidden)] +#[allow(unused_macros)] +#[macro_export] +macro_rules! vec_ffi_wrapper { + ($ffi:ident) =3D> { + #[allow(non_camel_case_types)] + pub struct $ffi(*mut qapi_ffi::$ffi); + + impl Drop for $ffi { + fn drop(&mut self) { + let mut list =3D self.0; + unsafe { + while !list.is_null() { + let next =3D (*list).next; + Box::from_raw(list); + list =3D next; + } + } + } + } + + impl From> for *mut qapi_ffi::$ffi { + fn from(p: NewPtr<*mut qapi_ffi::$ffi>) -> Self { + p.0 + } + } + }; +} + +#[doc(hidden)] +#[allow(unused_macros)] +#[macro_export] +macro_rules! impl_vec_scalars_to_qemu { + ($rs:ty, $ffi:ident) =3D> { + impl<'a> ToQemuPtr<'a, NewPtr<*mut qapi_ffi::$ffi>> for Vec<$rs> { + type Storage =3D $ffi; + + #[inline] + fn to_qemu_none(&self) -> Stash, S= elf> { + let mut list: *mut qapi_ffi::$ffi =3D std::ptr::null_mut(); + for value in self.iter().rev() { + let b =3D Box::new(qapi_ffi::$ffi { + next: list, + value: *value, + }); + list =3D Box::into_raw(b); + } + Stash(NewPtr(list), $ffi(list)) + } + + #[inline] + fn to_qemu_full(&self) -> NewPtr<*mut qapi_ffi::$ffi> { + let mut list: *mut qapi_ffi::$ffi =3D std::ptr::null_mut(); + unsafe { + for value in self.iter().rev() { + let l =3D ffi::g_malloc0(std::mem::size_of::()) + as *mut qapi_ffi::$ffi; + (*l).next =3D list; + (*l).value =3D *value; + list =3D l; + } + } + NewPtr(list) + } + } + }; +} + +#[doc(hidden)] +#[allow(unused_macros)] +#[macro_export] +macro_rules! impl_vec_scalars_from_qemu { + ($rs:ty, $ffi:ident, $free_ffi:ident) =3D> { + impl FromQemuPtrFull> for Vec<$rs> { + #[inline] + unsafe fn from_qemu_full(ffi: NewPtr<*mut qapi_ffi::$ffi>) -> = Self { + let ret =3D from_qemu_none(NewPtr(ffi.0 as *const _)); + qapi_ffi::$free_ffi(ffi.0); + ret + } + } + + impl FromQemuPtrNone> for Vec<$rs> { + #[inline] + unsafe fn from_qemu_none(ffi: NewPtr<*const qapi_ffi::$ffi>) -= > Self { + let mut ret =3D vec![]; + let mut it =3D ffi.0; + while !it.is_null() { + let e =3D &*it; + ret.push(e.value); + it =3D e.next; + } + ret + } + } + }; +} + +#[doc(hidden)] +#[allow(unused_macros)] +#[macro_export] +macro_rules! impl_vec_to_qemu { + ($rs:ty, $ffi:ident) =3D> { + // impl doesn't use only types from inside the current crate + // impl QemuPtrDefault for Vec<$rs> { + // type QemuType =3D NewPtr<*mut qapi_ffi::$ffi>; + // } + + impl<'a> ToQemuPtr<'a, NewPtr<*mut qapi_ffi::$ffi>> for Vec<$rs> { + type Storage =3D ($ffi, Vec:= :QemuType, $rs>>); + + #[inline] + fn to_qemu_none(&self) -> Stash, S= elf> { + let stash_vec: Vec<_> =3D self.iter().rev().map(ToQemuPtr:= :to_qemu_none).collect(); + let mut list: *mut qapi_ffi::$ffi =3D std::ptr::null_mut(); + for stash in &stash_vec { + let b =3D Box::new(qapi_ffi::$ffi { + next: list, + value: Ptr::to(stash.0), + }); + list =3D Box::into_raw(b); + } + Stash(NewPtr(list), ($ffi(list), stash_vec)) + } + + #[inline] + fn to_qemu_full(&self) -> NewPtr<*mut qapi_ffi::$ffi> { + let v: Vec<_> =3D self.iter().rev().map(ToQemuPtr::to_qemu= _full).collect(); + let mut list: *mut qapi_ffi::$ffi =3D std::ptr::null_mut(); + unsafe { + for val in v { + let l =3D ffi::g_malloc0(std::mem::size_of::()) + as *mut qapi_ffi::$ffi; + (*l).next =3D list; + (*l).value =3D val; + list =3D l; + } + } + NewPtr(list) + } + } + }; +} + +#[doc(hidden)] +#[allow(unused_macros)] +#[macro_export] +macro_rules! impl_vec_from_qemu { + ($rs:ty, $ffi:ident, $free_ffi:ident) =3D> { + impl FromQemuPtrFull> for Vec<$rs> { + #[inline] + unsafe fn from_qemu_full(ffi: NewPtr<*mut qapi_ffi::$ffi>) -> = Self { + let ret =3D from_qemu_none(NewPtr(ffi.0 as *const _)); + qapi_ffi::$free_ffi(ffi.0); + ret + } + } + + impl FromQemuPtrNone> for Vec<$rs> { + #[inline] + unsafe fn from_qemu_none(ffi: NewPtr<*const qapi_ffi::$ffi>) -= > Self { + let mut ret =3D vec![]; + let mut it =3D ffi.0; + while !it.is_null() { + let e =3D &*it; + ret.push(from_qemu_none(e.value as *const _)); + it =3D e.next; + } + ret + } + } + }; +} + +/// A macro to help the implementation of `Vec` translations. +#[allow(unused_macros)] +#[macro_export] +macro_rules! vec_type { + (Vec<$rs:ty>, $ffi:ident, $free_ffi:ident, 0) =3D> { + vec_ffi_wrapper!($ffi); + impl_vec_from_qemu!($rs, $ffi, $free_ffi); + impl_vec_to_qemu!($rs, $ffi); + }; + (Vec<$rs:ty>, $ffi:ident, $free_ffi:ident, 1) =3D> { + vec_ffi_wrapper!($ffi); + impl_vec_scalars_from_qemu!($rs, $ffi, $free_ffi); + impl_vec_scalars_to_qemu!($rs, $ffi); + }; +} + +/// A macro to implement [`ToQemuPtr`] as boxed scalars +#[allow(unused_macros)] +#[macro_export] +macro_rules! impl_to_qemu_scalar_boxed { + ($ty:ty) =3D> { + impl<'a> ToQemuPtr<'a, *mut $ty> for $ty { + type Storage =3D Box<$ty>; + + fn to_qemu_none(&'a self) -> Stash<'a, *mut $ty, Self> { + let mut box_ =3D Box::new(*self); + Stash(&mut *box_, box_) + } + + fn to_qemu_full(&self) -> *mut $ty { + unsafe { + let ptr =3D ffi::g_malloc0(std::mem::size_of::<$ty>())= as *mut _; + *ptr =3D *self; + ptr + } + } + } + }; +} + +/// A macro to implement [`FromQemuPtrNone`] for scalar pointers. +#[allow(unused_macros)] +#[macro_export] +macro_rules! impl_from_qemu_none_scalar { + ($ty:ty) =3D> { + impl FromQemuPtrNone<*const $ty> for $ty { + unsafe fn from_qemu_none(ptr: *const $ty) -> Self { + *ptr + } + } + }; +} + +macro_rules! impl_scalar_boxed { + ($($t:ident)*) =3D> ( + $( + impl_to_qemu_scalar_boxed!($t); + impl_from_qemu_none_scalar!($t); + )* + ) +} + +// the only built-in used so far, feel free to add more as needed +impl_scalar_boxed!(bool i64 f64); --=20 2.33.0.113.g6c40894d24 From nobody Tue May 7 11:02:16 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 163101781342515.806711405202009; Tue, 7 Sep 2021 05:30:13 -0700 (PDT) Received: from localhost ([::1]:52984 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNaEu-0004Tl-6p for importer@patchew.org; Tue, 07 Sep 2021 08:30:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42430) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNa7l-00030p-6f for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:22:49 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:20426) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNa7j-0007ih-4t for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:22:48 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-427-LTk4ZeZ0Mcew0-p8UmKfbw-1; Tue, 07 Sep 2021 08:22:44 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 87472188E3C1 for ; Tue, 7 Sep 2021 12:22:43 +0000 (UTC) Received: from localhost (unknown [10.39.208.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id 236BE6B545; Tue, 7 Sep 2021 12:22:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631017366; 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=oEILewch93OybQzOl1KrIHEQYi+z0OjUCe2lBj5iJTs=; b=Fo4xHWMORUGOZ1OFGPmm84h0BJ+TuGtB0NZmMFoAJUOMUqGyRNz1TXEvimE0T9BxHMHCYp HzhWMdrq3mcZJhcEPGyR5BeZZ0qFnbiyE1DD/eh8/t1Le1vHvtMuYvn6BbjcgQPFZicE+5 ezv4tliLkBwi1qmdqFlvorpnt7Q7Axw= X-MC-Unique: LTk4ZeZ0Mcew0-p8UmKfbw-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [RFC v3 13/32] rust: use vendored-sources Date: Tue, 7 Sep 2021 16:19:24 +0400 Message-Id: <20210907121943.3498701-14-marcandre.lureau@redhat.com> In-Reply-To: <20210907121943.3498701-1-marcandre.lureau@redhat.com> References: <20210907121943.3498701-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=marcandre.lureau@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, berrange@redhat.com, armbru@redhat.com, stefanha@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631017815026100003 From: Marc-Andr=C3=A9 Lureau Most likely, QEMU will want tighter control over the sources, rather than relying on crates.io downloading, use a git submodule with all the dependencies. However, cargo --offline was added in 1.36. "cargo vendor" helps gathering and updating the dependencies. Signed-off-by: Marc-Andr=C3=A9 Lureau --- configure | 8 ++++++++ meson.build | 7 ++++++- .cargo/config.toml.in | 5 +++++ .cargo/meson.build | 5 +++++ .gitmodules | 4 ++++ rust/vendored | 1 + scripts/archive-source.sh | 2 +- scripts/cargo_wrapper.py | 1 + 8 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 .cargo/config.toml.in create mode 100644 .cargo/meson.build create mode 160000 rust/vendored diff --git a/configure b/configure index 470b90543f..82a94ab93b 100755 --- a/configure +++ b/configure @@ -2068,6 +2068,14 @@ if test -z "$ninja"; then fi fi =20 +case "$with_rust" in + auto|enabled) + if test -e "${source_path}/.git"; then + git_submodules=3D"${git_submodules} rust/vendored" + fi + ;; +esac + # Check that the C compiler works. Doing this here before testing # the host CPU ensures that we had a valid CC to autodetect the # $cpu var (and we should bail right here if that's not the case). diff --git a/meson.build b/meson.build index a21c70d77f..29d218d35a 100644 --- a/meson.build +++ b/meson.build @@ -108,7 +108,11 @@ endif =20 bzip2 =3D find_program('bzip2', required: install_edk2_blobs) =20 -cargo =3D find_program('cargo', required: get_option('with_rust')) +cargo =3D find_program('cargo', + required: get_option('with_rust'), + # require --offline support (1.36), but fixed (1.42) + version: '>=3D 1.42') + with_rust =3D cargo.found() cargo_wrapper =3D [ find_program('scripts/cargo_wrapper.py'), @@ -126,6 +130,7 @@ if with_rust error('cross-compiling, but no Rust target-triple defined.') endif endif + subdir('.cargo') endif config_host_data.set('CONFIG_WITH_RUST', with_rust) =20 diff --git a/.cargo/config.toml.in b/.cargo/config.toml.in new file mode 100644 index 0000000000..d1531aa52a --- /dev/null +++ b/.cargo/config.toml.in @@ -0,0 +1,5 @@ +[source.crates-io] +replace-with =3D "vendored-sources" + +[source.vendored-sources] +directory =3D "@vendored_directory@" diff --git a/.cargo/meson.build b/.cargo/meson.build new file mode 100644 index 0000000000..4e7c296ab0 --- /dev/null +++ b/.cargo/meson.build @@ -0,0 +1,5 @@ +configure_file(output: 'config.toml', + input: 'config.toml.in', + configuration: { + 'vendored_directory': meson.source_root() / 'rust/vendo= red' + }) diff --git a/.gitmodules b/.gitmodules index 08b1b48a09..f767a4f386 100644 --- a/.gitmodules +++ b/.gitmodules @@ -64,3 +64,7 @@ [submodule "roms/vbootrom"] path =3D roms/vbootrom url =3D https://gitlab.com/qemu-project/vbootrom.git +[submodule "rust/vendored"] + path =3D rust/vendored + #url =3D https://gitlab.com/qemu-project/qemu-rust-vendored.git + url =3D https://github.com/elmarco/qemu-rust-vendored.git diff --git a/rust/vendored b/rust/vendored new file mode 160000 index 0000000000..7077bbbd11 --- /dev/null +++ b/rust/vendored @@ -0,0 +1 @@ +Subproject commit 7077bbbd11a67d60062a9483f996113a349a4ca1 diff --git a/scripts/archive-source.sh b/scripts/archive-source.sh index c6169db69f..03afcee8b9 100755 --- a/scripts/archive-source.sh +++ b/scripts/archive-source.sh @@ -26,7 +26,7 @@ sub_file=3D"${sub_tdir}/submodule.tar" # independent of what the developer currently has initialized # in their checkout, because the build environment is completely # different to the host OS. -submodules=3D"dtc slirp meson ui/keycodemapdb" +submodules=3D"dtc slirp meson ui/keycodemapdb rust/vendored" submodules=3D"$submodules tests/fp/berkeley-softfloat-3 tests/fp/berkeley-= testfloat-3" sub_deinit=3D"" =20 diff --git a/scripts/cargo_wrapper.py b/scripts/cargo_wrapper.py index 75518e8c02..c07f51494b 100644 --- a/scripts/cargo_wrapper.py +++ b/scripts/cargo_wrapper.py @@ -78,6 +78,7 @@ def get_cargo_rustc( target_dir, "--manifest-path", manifest_path, + "--offline", ] cargo_cmd +=3D cargo_rustc_args if args.target_triple: --=20 2.33.0.113.g6c40894d24 From nobody Tue May 7 11:02:16 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631018668157937.0532576914406; Tue, 7 Sep 2021 05:44:28 -0700 (PDT) Received: from localhost ([::1]:51664 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNaSg-0006QH-VM for importer@patchew.org; Tue, 07 Sep 2021 08:44:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42478) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNa7w-00036t-CZ for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:23:00 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:47844) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNa7u-0007li-QP for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:23:00 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-597-1EnQa6TRPue6ZgpO__LKBA-1; Tue, 07 Sep 2021 08:22:56 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D9718801B3D for ; Tue, 7 Sep 2021 12:22:55 +0000 (UTC) Received: from localhost (unknown [10.39.208.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id 94DC41B46B; Tue, 7 Sep 2021 12:22:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631017378; 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=EcNUWh89umV/1/EES3d61Y6beBZYrL8xwzLfr7verkc=; b=D/sBvAVP5VjAJFNWtrWKwKlffJ4TYkguU4FgvPjAcS0BYwo/NVwdOHJMghF6+JQf+zDZSF rD4z0E5rpifL58JDKQ5mNKn2KCwp43mNWOvLVTTVkCjbc2i0g5J37osY4RXAye7eznaDmU ukLri4Xr3/bQ73qbFYmzrC8jfTzgaHo= X-MC-Unique: 1EnQa6TRPue6ZgpO__LKBA-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [RFC v3 14/32] scripts/qapi: add QAPISchemaIfCond.rsgen() Date: Tue, 7 Sep 2021 16:19:25 +0400 Message-Id: <20210907121943.3498701-15-marcandre.lureau@redhat.com> In-Reply-To: <20210907121943.3498701-1-marcandre.lureau@redhat.com> References: <20210907121943.3498701-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=marcandre.lureau@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, berrange@redhat.com, armbru@redhat.com, stefanha@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631018668761100001 From: Marc-Andr=C3=A9 Lureau Generate Rust #[cfg(...)] guards from QAPI 'if' conditions. Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi/common.py | 16 ++++++++++++++++ scripts/qapi/schema.py | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index 5f8f76e5b2..6d22c66391 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -201,6 +201,22 @@ def guardend(name: str) -> str: name=3Dc_fname(name).upper()) =20 =20 +def rsgen_ifcond(ifcond: Union[str, Dict[str, Any]]) -> str: + + def cfg(ifcond: Union[str, Dict[str, Any]]): + if isinstance(ifcond, str): + return ifcond + if isinstance(ifcond, list): + return ', '.join([cfg(c) for c in ifcond]) + oper, operands =3D next(iter(ifcond.items())) + operands =3D cfg(operands) + return f'{oper}({operands})' + + if not ifcond: + return '' + return '#[cfg(%s)]' % cfg(ifcond) + + def gen_ifcond(ifcond: Optional[Union[str, Dict[str, Any]]], cond_fmt: str, not_fmt: str, all_operator: str, any_operator: str) -> str: diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 6455a8f425..c61f35e13f 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -26,6 +26,7 @@ docgen_ifcond, gen_endif, gen_if, + rsgen_ifcond, ) from .error import QAPIError, QAPISemError, QAPISourceError from .expr import check_exprs @@ -48,6 +49,9 @@ def gen_endif(self): def docgen(self): return docgen_ifcond(self.ifcond) =20 + def rsgen(self): + return rsgen_ifcond(self.ifcond) + def is_present(self): return bool(self.ifcond) =20 --=20 2.33.0.113.g6c40894d24 From nobody Tue May 7 11:02:16 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 163101816003069.58754341879433; Tue, 7 Sep 2021 05:36:00 -0700 (PDT) Received: from localhost ([::1]:33432 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNaKU-0002FV-Mk for importer@patchew.org; Tue, 07 Sep 2021 08:35:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42540) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNa8A-0003Xm-TC for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:23:14 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:23607) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNa89-0007qQ-6K for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:23:14 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-135-lWy_PX-UPpeF2o2lRqCLOQ-1; Tue, 07 Sep 2021 08:23:10 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C29341075649 for ; Tue, 7 Sep 2021 12:23:09 +0000 (UTC) Received: from localhost (unknown [10.39.208.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id DC8E55D6CF; Tue, 7 Sep 2021 12:22:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631017392; 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=luRxH5SQbRU2KNebvbCNYcXd8ewpucrD4evtz+2Y8UA=; b=XWQKqdRTFsN8Uf2mQwLzfxReaiDiJWdtllJxJS27In2WUaSPln70id+hLshxVNuwCDDJw9 WoSPMaNs2+xWzMHrIYAcV7PPxb59ZfvLAS/KdBCdSEIajDHx2D+0fFpEPvQd0Eck5AmzpN K+ZR5oPdY03bkaT2YZTb4eyPlS8wEY4= X-MC-Unique: lWy_PX-UPpeF2o2lRqCLOQ-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [RFC v3 15/32] scripts/qapi: strip trailing whitespaces Date: Tue, 7 Sep 2021 16:19:26 +0400 Message-Id: <20210907121943.3498701-16-marcandre.lureau@redhat.com> In-Reply-To: <20210907121943.3498701-1-marcandre.lureau@redhat.com> References: <20210907121943.3498701-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=marcandre.lureau@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, berrange@redhat.com, armbru@redhat.com, stefanha@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631018162377100001 From: Marc-Andr=C3=A9 Lureau This help workaround a rustfmt issue. Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi/gen.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py index ab26d5c937..fa23f43808 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -50,7 +50,11 @@ def add(self, text: str) -> None: self._body +=3D text =20 def get_content(self) -> str: - return self._top() + self._preamble + self._body + self._bottom() + content =3D self._top() + self._preamble + self._body + self._bott= om() + # delete trailing white-spaces (working around + # https://github.com/rust-lang/rustfmt/issues/4248) + content =3D re.sub(r'\s+$', '\n', content, 0, re.M) + return content =20 def _top(self) -> str: # pylint: disable=3Dno-self-use --=20 2.33.0.113.g6c40894d24 From nobody Tue May 7 11:02:16 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631018973039627.5281409061117; Tue, 7 Sep 2021 05:49:33 -0700 (PDT) Received: from localhost ([::1]:58836 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNaXa-0003AD-5u for importer@patchew.org; Tue, 07 Sep 2021 08:49:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42638) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNa8Y-0004k2-LY for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:23:38 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:48076) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNa8L-0007ti-GL for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:23:37 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-230-NGMCS6RJMnqDFWAmf3rvpw-1; Tue, 07 Sep 2021 08:23:23 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 88342835DE1 for ; Tue, 7 Sep 2021 12:23:22 +0000 (UTC) Received: from localhost (unknown [10.39.208.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id 51B9019733; Tue, 7 Sep 2021 12:23:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631017404; 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=8TzOn+P9Hh5f2yl0uOc582fZprACT7UpapXov530jGA=; b=EvLUx8AaGmfNREYpTSlpZA0yXzbsgewhmI8aQDlgTmMlveQSQtYmq3/C7moEBdL6SorJwe n5hfxfNNRgJjgn+0cOabLxGu8UXka6Hx0VMlNmh+CzFQWRHt5fjUs6M1IGGsKlVomrUs35 8nH63jm3yMwS3ogPTrFemW9ZM8s+lNM= X-MC-Unique: NGMCS6RJMnqDFWAmf3rvpw-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [RFC v3 16/32] scripts/qapi: add Rust FFI bindings generation Date: Tue, 7 Sep 2021 16:19:27 +0400 Message-Id: <20210907121943.3498701-17-marcandre.lureau@redhat.com> In-Reply-To: <20210907121943.3498701-1-marcandre.lureau@redhat.com> References: <20210907121943.3498701-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=marcandre.lureau@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@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.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, berrange@redhat.com, armbru@redhat.com, stefanha@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631018973651100001 From: Marc-Andr=C3=A9 Lureau Generate the C QAPI types in Rust, with a few common niceties to Debug/Clone/Copy the Rust type. Signed-off-by: Marc-Andr=C3=A9 Lureau --- meson.build | 4 +- scripts/qapi/main.py | 23 ++- scripts/qapi/rs.py | 170 ++++++++++++++++ scripts/qapi/rs_ffi.py | 446 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 635 insertions(+), 8 deletions(-) create mode 100644 scripts/qapi/rs.py create mode 100644 scripts/qapi/rs_ffi.py diff --git a/meson.build b/meson.build index 29d218d35a..b45f409eb4 100644 --- a/meson.build +++ b/meson.build @@ -2012,7 +2012,9 @@ qapi_gen_depends =3D [ meson.source_root() / 'scripts= /qapi/__init__.py', meson.source_root() / 'scripts/qapi/types.py', meson.source_root() / 'scripts/qapi/visit.py', meson.source_root() / 'scripts/qapi/common.py', - meson.source_root() / 'scripts/qapi-gen.py' + meson.source_root() / 'scripts/qapi/rs.py', + meson.source_root() / 'scripts/qapi/rs_ffi.py', + meson.source_root() / 'scripts/qapi-gen.py', ] =20 tracetool =3D [ diff --git a/scripts/qapi/main.py b/scripts/qapi/main.py index f2ea6e0ce4..deba72ee4e 100644 --- a/scripts/qapi/main.py +++ b/scripts/qapi/main.py @@ -16,6 +16,7 @@ from .error import QAPIError from .events import gen_events from .introspect import gen_introspect +from .rs_ffi import gen_rs_ffitypes from .schema import QAPISchema from .types import gen_types from .visit import gen_visit @@ -32,7 +33,8 @@ def generate(schema_file: str, output_dir: str, prefix: str, unmask: bool =3D False, - builtins: bool =3D False) -> None: + builtins: bool =3D False, + rust: bool =3D False) -> None: """ Generate C code for the given schema into the target directory. =20 @@ -41,17 +43,21 @@ def generate(schema_file: str, :param prefix: Optional C-code prefix for symbol names. :param unmask: Expose non-ABI names through introspection? :param builtins: Generate code for built-in types? + :param rust: Generate Rust binding code? =20 :raise QAPIError: On failures. """ assert invalid_prefix_char(prefix) is None =20 schema =3D QAPISchema(schema_file) - gen_types(schema, output_dir, prefix, builtins) - gen_visit(schema, output_dir, prefix, builtins) - gen_commands(schema, output_dir, prefix) - gen_events(schema, output_dir, prefix) - gen_introspect(schema, output_dir, prefix, unmask) + if rust: + gen_rs_ffitypes(schema, output_dir, prefix) + else: + gen_types(schema, output_dir, prefix, builtins) + gen_visit(schema, output_dir, prefix, builtins) + gen_commands(schema, output_dir, prefix) + gen_events(schema, output_dir, prefix) + gen_introspect(schema, output_dir, prefix, unmask) =20 =20 def main() -> int: @@ -74,6 +80,8 @@ def main() -> int: parser.add_argument('-u', '--unmask-non-abi-names', action=3D'store_tr= ue', dest=3D'unmask', help=3D"expose non-ABI names in introspection") + parser.add_argument('-r', '--rust', action=3D'store_true', + help=3D"generate Rust binding code") parser.add_argument('schema', action=3D'store') args =3D parser.parse_args() =20 @@ -88,7 +96,8 @@ def main() -> int: output_dir=3Dargs.output_dir, prefix=3Dargs.prefix, unmask=3Dargs.unmask, - builtins=3Dargs.builtins) + builtins=3Dargs.builtins, + rust=3Dargs.rust) except QAPIError as err: print(f"{sys.argv[0]}: {str(err)}", file=3Dsys.stderr) return 1 diff --git a/scripts/qapi/rs.py b/scripts/qapi/rs.py new file mode 100644 index 0000000000..be42329fa4 --- /dev/null +++ b/scripts/qapi/rs.py @@ -0,0 +1,170 @@ +# This work is licensed under the terms of the GNU GPL, version 2. +# See the COPYING file in the top-level directory. +""" +QAPI Rust generator +""" + +import os +import re +import subprocess +from typing import NamedTuple, Optional + +from .common import POINTER_SUFFIX +from .gen import QAPIGen +from .schema import QAPISchemaModule, QAPISchemaVisitor + + +# see to_snake_case() below +snake_case =3D re.compile(r'((?<=3D[a-z0-9])[A-Z]|(?!^)[A-Z](?=3D[a-z]))') + + +rs_name_trans =3D str.maketrans('.-', '__') + + +# Map @name to a valid Rust identifier. +# If @protect, avoid returning certain ticklish identifiers (like +# keywords) by prepending raw identifier prefix 'r#'. +def rs_name(name: str, protect: bool =3D True) -> str: + name =3D name.translate(rs_name_trans) + if name[0].isnumeric(): + name =3D '_' + name + if not protect: + return name + # based from the list: + # https://doc.rust-lang.org/reference/keywords.html + if name in ('Self', 'abstract', 'as', 'async', + 'await', 'become', 'box', 'break', + 'const', 'continue', 'crate', 'do', + 'dyn', 'else', 'enum', 'extern', + 'false', 'final', 'fn', 'for', + 'if', 'impl', 'in', 'let', + 'loop', 'macro', 'match', 'mod', + 'move', 'mut', 'override', 'priv', + 'pub', 'ref', 'return', 'self', + 'static', 'struct', 'super', 'trait', + 'true', 'try', 'type', 'typeof', + 'union', 'unsafe', 'unsized', 'use', + 'virtual', 'where', 'while', 'yield'): + name =3D 'r#' + name + # avoid some clashes with the standard library + if name in ('String',): + name =3D 'Qapi' + name + + return name + + +class CType(NamedTuple): + is_pointer: bool + is_const: bool + is_list: bool + c_type: str + + +def rs_ctype_parse(c_type: str) -> CType: + is_pointer =3D False + if c_type.endswith(POINTER_SUFFIX): + is_pointer =3D True + c_type =3D c_type[:-len(POINTER_SUFFIX)] + is_list =3D c_type.endswith('List') + is_const =3D False + if c_type.startswith('const '): + is_const =3D True + c_type =3D c_type[6:] + + c_type =3D rs_name(c_type) + return CType(is_pointer, is_const, is_list, c_type) + + +def rs_ffitype(c_type: str, ffi_ns: str =3D 'qapi_ffi::', + list_as_newp: bool =3D False) -> str: + (is_pointer, is_const, is_list, c_type) =3D rs_ctype_parse(c_type) + c_type =3D rs_name(c_type) + to_rs =3D { + 'bool': 'bool', + 'char': 'libc::c_char', # for clarity (i8) + 'double': 'f64', + 'int': 'i64', + 'int16': 'i16', + 'int16_t': 'i16', + 'int32': 'i32', + 'int32_t': 'i32', + 'int64': 'i64', + 'int64_t': 'i64', + 'int8': 'i8', + 'int8_t': 'i8', + 'uint16': 'u16', + 'uint16_t': 'u16', + 'uint32': 'u32', + 'uint32_t': 'u32', + 'uint64': 'u64', + 'uint64_t': 'u64', + 'uint8': 'u8', + 'uint8_t': 'u8', + 'QObject': 'common::ffi::QObject', + 'QNull': 'common::ffi::QNull', + } + + ret =3D '' + if is_const and is_pointer: + ret +=3D '*const ' + elif is_pointer: + ret +=3D '*mut ' + if c_type in to_rs: + ret +=3D to_rs[c_type] + else: + ret +=3D ffi_ns + c_type + + if is_list and list_as_newp: + ret =3D 'NewPtr<{}>'.format(ret) + + return ret + + +def to_camel_case(value: str) -> str: + # special case for last enum value + if value =3D=3D '_MAX': + return value + raw_id =3D False + if value.startswith('r#'): + raw_id =3D True + value =3D value[2:] + value =3D ''.join('_' + word if word[0].isdigit() + else word[:1].upper() + word[1:] + for word in filter(None, re.split("[-_]+", value))) + if raw_id: + return 'r#' + value + return value + + +def to_snake_case(value: str) -> str: + return snake_case.sub(r'_\1', value).lower() + + +class QAPIGenRs(QAPIGen): + pass + + +class QAPISchemaRsVisitor(QAPISchemaVisitor): + + def __init__(self, prefix: str, what: str): + super().__init__() + self._prefix =3D prefix + self._what =3D what + self._gen =3D QAPIGenRs(self._prefix + self._what + '.rs') + self._main_module: Optional[str] =3D None + + def visit_module(self, name: Optional[str]) -> None: + if name is None: + return + if QAPISchemaModule.is_user_module(name): + if self._main_module is None: + self._main_module =3D name + + def write(self, output_dir: str) -> None: + self._gen.write(output_dir) + + pathname =3D os.path.join(output_dir, self._gen.fname) + try: + subprocess.check_call(['rustfmt', pathname]) + except FileNotFoundError: + pass diff --git a/scripts/qapi/rs_ffi.py b/scripts/qapi/rs_ffi.py new file mode 100644 index 0000000000..59e834b36a --- /dev/null +++ b/scripts/qapi/rs_ffi.py @@ -0,0 +1,446 @@ +# This work is licensed under the terms of the GNU GPL, version 2. +# See the COPYING file in the top-level directory. +""" +QAPI Rust sys/ffi generator +""" + +from pathlib import Path +from typing import ( + Dict, + List, + Optional, + Set, +) + +from .cabi import CABI, CABIEnum, gen_object_cabi +from .common import mcgen +from .rs import ( + QAPISchemaRsVisitor, + rs_ffitype, + rs_name, + to_camel_case, + to_snake_case, +) +from .schema import ( + QAPISchema, + QAPISchemaEnumMember, + QAPISchemaFeature, + QAPISchemaIfCond, + QAPISchemaModule, + QAPISchemaObjectType, + QAPISchemaObjectTypeMember, + QAPISchemaType, + QAPISchemaVariants, +) +from .source import QAPISourceInfo + + +objects_seen =3D set() + + +def gen_rs_ffi_enum(name: str, + ifcond: QAPISchemaIfCond, + members: List[QAPISchemaEnumMember]) -> str: + # append automatically generated _max value + enum_members =3D members + [QAPISchemaEnumMember('_MAX', None)] + + ret =3D mcgen(''' + +%(cfg)s +#[derive(Copy, Clone, Debug, PartialEq, Eq)] +#[repr(C)] +pub enum %(rs_name)s { +''', + cfg=3Difcond.rsgen(), + rs_name=3Drs_name(name)) + + for member in enum_members: + ret +=3D mcgen(''' + %(cfg)s + %(c_enum)s, +''', + cfg=3Dmember.ifcond.rsgen(), + c_enum=3Dto_camel_case(rs_name(member.name))) + # picked the first, since that's what malloc0 does + # but arguably could use _MAX instead, or a qapi annotation + default =3D to_camel_case(rs_name(enum_members[0].name)) + ret +=3D mcgen(''' +} + +%(cfg)s +impl Default for %(rs_name)s { + #[inline] + fn default() -> %(rs_name)s { + Self::%(default)s + } +} +''', + cfg=3Difcond.rsgen(), + rs_name=3Drs_name(name), + default=3Ddefault) + return ret + + +def gen_rs_ffi_struct_members(members: + List[QAPISchemaObjectTypeMember]) -> str: + ret =3D '' + for memb in members: + if memb.optional: + ret +=3D mcgen(''' + %(cfg)s + pub has_%(rs_name)s: bool, +''', + cfg=3Dmemb.ifcond.rsgen(), + rs_name=3Dto_snake_case(rs_name(memb.name, + protect=3DFalse))) + ret +=3D mcgen(''' + %(cfg)s + pub %(rs_name)s: %(rs_ffitype)s, +''', + cfg=3Dmemb.ifcond.rsgen(), + rs_ffitype=3Drs_ffitype(memb.type.c_type(), ''), + rs_name=3Dto_snake_case(rs_name(memb.name))) + return ret + + +def gen_rs_ffi_free(name: str, ifcond: QAPISchemaIfCond) -> str: + name =3D rs_name(name, protect=3DFalse) + typ =3D rs_name(name) + return mcgen(''' + +%(cfg)s +extern "C" { + pub fn qapi_free_%(name)s(obj: *mut %(ty)s); +} +''', cfg=3Difcond.rsgen(), name=3Dname, ty=3Dtyp) + + +def gen_rs_ffi_variants(name: str, + ifcond: QAPISchemaIfCond, + variants: Optional[QAPISchemaVariants]) -> str: + ret =3D mcgen(''' + +%(cfg)s +#[repr(C)] +#[derive(Copy, Clone)] +pub union %(rs_name)s { /* union tag is @%(tag_name)s */ +''', + cfg=3Difcond.rsgen(), + tag_name=3Drs_name(variants.tag_member.name), + rs_name=3Drs_name(name)) + + empty =3D True + for var in variants.variants: + if var.type.name =3D=3D 'q_empty': + continue + empty =3D False + ret +=3D mcgen(''' + %(cfg)s + pub %(rs_name)s: %(rs_ffitype)s, +''', + cfg=3Dvar.ifcond.rsgen(), + rs_ffitype=3Drs_ffitype(var.type.c_unboxed_type(), ''= ), + rs_name=3Drs_name(var.name)) + + ret +=3D mcgen(''' + pub qapi_dummy: QapiDummy, +''') + + ret +=3D mcgen(''' +} + +%(cfg)s +impl ::std::fmt::Debug for %(rs_name)s { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + f.debug_struct(&format!("%(rs_name)s @ {:?}", self as *const _)) + .finish() + } +} +''', cfg=3Difcond.rsgen(), rs_name=3Drs_name(name)) + + if empty: + ret +=3D mcgen(''' + +%(cfg)s +impl ::std::default::Default for %(rs_name)s { + fn default() -> Self { + Self { qapi_dummy: QapiDummy } + } +} +''', cfg=3Difcond.rsgen(), rs_name=3Drs_name(name)) + return ret + + +def gen_rs_ffi_object(name: str, + ifcond: QAPISchemaIfCond, + base: Optional[QAPISchemaObjectType], + members: List[QAPISchemaObjectTypeMember], + variants: Optional[QAPISchemaVariants]) -> str: + if name in objects_seen: + return '' + + ret =3D '' + objects_seen.add(name) + unionty =3D name + 'Union' + if variants: + for var in variants.variants: + if isinstance(var.type, QAPISchemaObjectType): + ret +=3D gen_rs_ffi_object(var.type.name, + var.type.ifcond, + var.type.base, + var.type.local_members, + var.type.variants) + ret +=3D gen_rs_ffi_variants(unionty, ifcond, variants) + + ret +=3D gen_rs_ffi_free(name, ifcond) + ret +=3D mcgen(''' + +%(cfg)s +#[repr(C)] +#[derive(Copy, Clone, Debug)] +pub struct %(rs_name)s { +''', + cfg=3Difcond.rsgen(), + rs_name=3Drs_name(name)) + + if base: + if not base.is_implicit(): + ret +=3D mcgen(''' + // Members inherited: +''') + ret +=3D gen_rs_ffi_struct_members(base.members) + if not base.is_implicit(): + ret +=3D mcgen(''' + // Own members: +''') + + ret +=3D gen_rs_ffi_struct_members(members) + if variants: + ret +=3D mcgen(''' + pub u: %(unionty)s +''', unionty=3Drs_name(unionty)) + + empty =3D False + # for compatibility with C ABI + if (not base or base.is_empty()) and not members and not variants: + empty =3D True + ret +=3D mcgen(''' + pub qapi_dummy_for_empty_struct: u8, +''') + ret +=3D mcgen(''' +} +''') + + if empty: + ret +=3D mcgen(''' + +%(cfg)s +impl Default for %(rs_name)s { + fn default() -> Self { + Self { qapi_dummy_for_empty_struct: 0 } + } +} +''', + cfg=3Difcond.rsgen(), + rs_name=3Drs_name(name)) + + return ret + + +def gen_rs_ffi_variant(name: str, + ifcond: QAPISchemaIfCond, + variants: Optional[QAPISchemaVariants]) -> str: + if name in objects_seen: + return '' + + objects_seen.add(name) + + ret =3D '' + gen_variants =3D '' + for var in variants.variants: + if var.type.name =3D=3D 'q_empty': + continue + typ =3D rs_ffitype(var.type.c_unboxed_type(), '') + gen_variants +=3D mcgen(''' + %(cfg)s + pub %(mem_name)s: %(rs_ffitype)s, +''', + cfg=3Dvar.ifcond.rsgen(), + rs_ffitype=3Dtyp, + mem_name=3Drs_name(var.name)) + if not gen_variants: + ret +=3D mcgen(''' + impl ::std::default::Default for %(rs_name)sUnion { + fn default() -> Self { + Self { qapi_dummy: QapiDummy } + } + } +''') + gen_variants +=3D mcgen(''' + pub qapi_dummy: QapiDummy, +''') + + ret +=3D gen_rs_ffi_free(name, ifcond) + ret +=3D mcgen(''' + +%(cfg)s +#[repr(C)] +#[derive(Copy,Clone)] +pub union %(rs_name)sUnion { + %(variants)s +} + +%(cfg)s +impl ::std::fmt::Debug for %(rs_name)sUnion { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + f.debug_struct(&format!("%(rs_name)sUnion @ {:?}", self as *const = _)) + .finish() + } +} + +%(cfg)s +#[repr(C)] +#[derive(Copy, Clone, Debug)] +pub struct %(rs_name)s { + pub %(tag)s: QType, + pub u: %(rs_name)sUnion, +} +''', + cfg=3Difcond.rsgen(), + rs_name=3Drs_name(name), + tag=3Drs_name(variants.tag_member.name), + variants=3Dgen_variants) + return ret + + +def gen_rs_ffi_array(name: str, + ifcond: QAPISchemaIfCond, + element_type: QAPISchemaType) -> str: + ret =3D mcgen(''' + +%(cfg)s +#[repr(C)] +#[derive(Copy, Clone)] +pub struct %(rs_name)s { + pub next: *mut %(rs_name)s, + pub value: %(rs_ffitype)s, +} + +%(cfg)s +impl ::std::fmt::Debug for %(rs_name)s { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + f.debug_struct(&format!("%(rs_name)s @ {:?}", self as *const _)) + .finish() + } +} +''', + cfg=3Difcond.rsgen(), + rs_name=3Drs_name(name), + rs_ffitype=3Drs_ffitype(element_type.c_type(), '')) + ret +=3D gen_rs_ffi_free(name, ifcond) + return ret + + +class QAPISchemaGenRsFFITypeVisitor(QAPISchemaRsVisitor): + + def __init__(self, prefix: str): + super().__init__(prefix, 'qapi-ffi-types') + self._cabi: Dict[str, CABI] =3D {} + self._cabi_functions: List[str] =3D [] + self._cabi_functions_called: Set[str] =3D set() + + def _cabi_add(self, cabis: List[CABI]) -> None: + for cabi in cabis: + self._cabi.setdefault(cabi.name, cabi) + + def visit_begin(self, schema: QAPISchema) -> None: + # gen_object() is recursive, ensure it doesn't visit the empty type + objects_seen.add(schema.the_empty_object_type.name) + self._gen.preamble_add( + mcgen(''' +// generated by qapi-gen, DO NOT EDIT + +#[repr(C)] +#[derive(Copy, Clone, Debug)] +pub struct QapiDummy; +''')) + + def _get_qapi_cabi_fn(self, name: str) -> str: + fn_name =3D 'cabi' + if QAPISchemaModule.is_builtin_module(name): + fn_name +=3D '_builtin' + elif name !=3D self._main_module: + name =3D Path(name).stem + fn_name +=3D '_' + rs_name(name, False) + return fn_name + + def visit_include(self, name: str, info: Optional[QAPISourceInfo]) -> = None: + super().visit_include(name, info) + cabi_fn =3D self._get_qapi_cabi_fn(name) + if cabi_fn not in self._cabi_functions_called: + self._cabi_functions.append(cabi_fn) + + def visit_module_end(self, name: str) -> None: + cabi_gen =3D "".join(f' {fn}();\n' for fn in self._cabi_functio= ns) + self._cabi_functions_called |=3D set(self._cabi_functions) + self._cabi_functions =3D [] + cabi_gen +=3D "".join( + [c.gen_rs() for _, c in sorted(self._cabi.items())] + ) + self._cabi =3D {} + fn_name =3D self._get_qapi_cabi_fn(name) + self._gen.add(mcgen(''' +#[cfg(QAPI_CABI)] +pub(crate) fn %(fn_name)s() { +%(cabi_gen)s +} +''', fn_name=3Dfn_name, cabi_gen=3Dcabi_gen)) + + def visit_enum_type(self, + name: str, + info: Optional[QAPISourceInfo], + ifcond: QAPISchemaIfCond, + features: List[QAPISchemaFeature], + members: List[QAPISchemaEnumMember], + prefix: Optional[str]) -> None: + self._gen.add(gen_rs_ffi_enum(name, ifcond, members)) + self._cabi_add([CABIEnum(name, ifcond, members, prefix)]) + + def visit_array_type(self, + name: str, + info: Optional[QAPISourceInfo], + ifcond: QAPISchemaIfCond, + element_type: QAPISchemaType) -> None: + self._gen.add(gen_rs_ffi_array(name, ifcond, element_type)) + + def visit_object_type(self, + name: str, + info: Optional[QAPISourceInfo], + ifcond: QAPISchemaIfCond, + features: List[QAPISchemaFeature], + base: Optional[QAPISchemaObjectType], + members: List[QAPISchemaObjectTypeMember], + variants: Optional[QAPISchemaVariants]) -> None: + # Nothing to do for the special empty builtin + if name =3D=3D 'q_empty': + return + self._gen.add(gen_rs_ffi_object(name, ifcond, base, members, varia= nts)) + self._cabi_add(gen_object_cabi(name, ifcond, base, members, varian= ts)) + + def visit_alternate_type(self, + name: str, + info: QAPISourceInfo, + ifcond: QAPISchemaIfCond, + features: List[QAPISchemaFeature], + variants: QAPISchemaVariants) -> None: + self._gen.add(gen_rs_ffi_variant(name, ifcond, variants)) + self._cabi_add(gen_object_cabi(name, ifcond, None, + [variants.tag_member], variants)) + + +def gen_rs_ffitypes(schema: QAPISchema, + output_dir: str, + prefix: str) -> None: + vis =3D QAPISchemaGenRsFFITypeVisitor(prefix) + schema.visit(vis) + vis.write(output_dir) --=20 2.33.0.113.g6c40894d24 From nobody Tue May 7 11:02:16 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631017925851315.12457136324554; Tue, 7 Sep 2021 05:32:05 -0700 (PDT) Received: from localhost ([::1]:55266 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNaGi-00061m-Su for importer@patchew.org; Tue, 07 Sep 2021 08:32:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42754) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNa8n-0005Zk-MI for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:23:53 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:45097) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNa8Y-0007yH-R8 for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:23:53 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-270-rSO8CBfZP_O4I4OtgAMvWg-1; Tue, 07 Sep 2021 08:23:36 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3B7BA802934 for ; Tue, 7 Sep 2021 12:23:36 +0000 (UTC) Received: from localhost (unknown [10.39.208.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8054E781ED; Tue, 7 Sep 2021 12:23:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631017418; 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=zsnycfMms9ekn9IPgsoFbYxVec5TW2SQvovH+LP0zbA=; b=Gv/GVY6mrw92Gqd5C1JLgjkaJaxCB3Th2Fyej0aCIauEUKEWVOL2IycF2FuiHRvt6/Ko4B c/Hj1oLHHWUWSOZNzDj5aAGo4p0WcisN2Qa3fHbFOK0vIWvKuZYisSu8Tp/hLv/o2BWyPy xORCQtKiHR9uOw83ewGBysS3wntqmk0= X-MC-Unique: rSO8CBfZP_O4I4OtgAMvWg-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [RFC v3 17/32] scripts/qapi: learn to generate ABI dump for Rust FFI Date: Tue, 7 Sep 2021 16:19:28 +0400 Message-Id: <20210907121943.3498701-18-marcandre.lureau@redhat.com> In-Reply-To: <20210907121943.3498701-1-marcandre.lureau@redhat.com> References: <20210907121943.3498701-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=marcandre.lureau@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@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.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, berrange@redhat.com, armbru@redhat.com, stefanha@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631017927105100001 From: Marc-Andr=C3=A9 Lureau Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi/cabi.py | 50 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/scripts/qapi/cabi.py b/scripts/qapi/cabi.py index f33680477f..29c6d5144d 100644 --- a/scripts/qapi/cabi.py +++ b/scripts/qapi/cabi.py @@ -7,6 +7,7 @@ from typing import List, Optional =20 from .common import c_enum_const, c_name, mcgen +from .rs import rs_name, to_snake_case from .schema import ( QAPISchemaEnumMember, QAPISchemaIfCond, @@ -24,6 +25,9 @@ def __init__(self, name: str, ifcond: QAPISchemaIfCond): def gen_c(self) -> str: raise NotImplementedError() =20 + def gen_rs(self) -> str: + raise NotImplementedError() + =20 class CABIEnum(CABI): def __init__( @@ -48,6 +52,19 @@ def gen_c(self) -> str: ret +=3D self.ifcond.gen_endif() return ret =20 + def gen_rs(self) -> str: + return mcgen(""" +%(cfg)s +{ + println!("%(name)s enum: sizeof=3D{}", ::std::mem::size_of::<%(rs_name= )s>()); + println!(" max=3D{}", %(rs_name)s::_MAX as u32); + println!(); +} +""", + name=3Dself.name, + rs_name=3Drs_name(self.name), + cfg=3Dself.ifcond.rsgen()) + =20 class CABIStruct(CABI): def __init__(self, name: str, ifcond: QAPISchemaIfCond): @@ -84,6 +101,21 @@ def gen_c(self) -> str: ret +=3D self.ifcond.gen_endif() return ret =20 + def gen_rs(self) -> str: + ret =3D mcgen(""" +%(cfg)s +{ + println!("%(name)s struct: sizeof=3D{}", + ::std::mem::size_of::<%(rs_name)s>()); +""", name=3Dself.name, rs_name=3Drs_name(self.name), cfg=3Dself.ifcond.rsg= en()) + for member in self.members: + ret +=3D member.gen_rs() + ret +=3D mcgen(""" + println!(); +} +""") + return ret + =20 class CABIStructMember: def __init__(self, struct: CABIStruct, name: str, @@ -105,6 +137,24 @@ def gen_c(self) -> str: ret +=3D self.ifcond.gen_endif() return ret =20 + def gen_rs(self) -> str: + ret =3D '' + if self.ifcond: + ret +=3D self.ifcond.rsgen() + protect =3D not self.prefix or self.prefix[-1] =3D=3D '.' + rsmember =3D self.prefix + to_snake_case(rs_name(self.name, protec= t)) + ret +=3D mcgen(""" +unsafe { + println!(" %(member)s member: sizeof=3D{} offset=3D{}", + ::std::mem::size_of_val( + &(*::std::ptr::null::<%(sname)s>()).%(rsmember)s + ), + &(*(::std::ptr::null::<%(sname)s>())).%(rsmember)s as *const _ as = usize + ); +} +""", member=3Dself.name, sname=3Drs_name(self.struct.name), rsmember=3Drsm= ember) + return ret + =20 def gen_object_cabi( name: str, --=20 2.33.0.113.g6c40894d24 From nobody Tue May 7 11:02:16 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631018390581292.349587231085; Tue, 7 Sep 2021 05:39:50 -0700 (PDT) Received: from localhost ([::1]:41948 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNaOD-00084r-Hf for importer@patchew.org; Tue, 07 Sep 2021 08:39:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42786) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNa8v-000600-2b for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:24:01 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:28805) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNa8t-00083s-9b for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:24:00 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-496-HrnmVpIOMxm5LR4uwENq1g-1; Tue, 07 Sep 2021 08:23:56 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 888426D582 for ; Tue, 7 Sep 2021 12:23:55 +0000 (UTC) Received: from localhost (unknown [10.39.208.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3557E6C8D4; Tue, 7 Sep 2021 12:23:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631017438; 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=BLGXwvn9DS32kuAfVmPg9C/bCP9HyGaJIFcU+wIqyH0=; b=dFXM1Ry1ck4uI4wkdCIoOiF0KdrT3ShQ2WdlFxec9rp9uZVDTUBISYb96tScIEhvAIDkj4 1GXTjxVH5nx2uxMHtttMWhCzBqmetDuKhrS670BxSOFQm86AUuNq1Kx4sxr4hu69w331XW c337cmPu3Uj1WBh6jzuV0AnVVJg8PVA= X-MC-Unique: HrnmVpIOMxm5LR4uwENq1g-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [RFC v3 18/32] tests: generate Rust bindings Date: Tue, 7 Sep 2021 16:19:29 +0400 Message-Id: <20210907121943.3498701-19-marcandre.lureau@redhat.com> In-Reply-To: <20210907121943.3498701-1-marcandre.lureau@redhat.com> References: <20210907121943.3498701-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=marcandre.lureau@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, berrange@redhat.com, armbru@redhat.com, stefanha@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631018392684100001 From: Marc-Andr=C3=A9 Lureau Signed-off-by: Marc-Andr=C3=A9 Lureau --- tests/meson.build | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/tests/meson.build b/tests/meson.build index be95223d62..7292fe20df 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -31,15 +31,29 @@ test_qapi_outputs =3D [ 'test-qapi-visit.h', ] =20 +test_qapi_inputs =3D files( + 'qapi-schema/qapi-schema-test.json', + 'qapi-schema/include/sub-module.json', + 'qapi-schema/sub-sub-module.json' +) + test_qapi_files =3D custom_target('Test QAPI files', output: test_qapi_outputs, - input: files('qapi-schema/qapi-schema-test= .json', - 'qapi-schema/include/sub-modu= le.json', - 'qapi-schema/sub-sub-module.j= son'), + input: test_qapi_inputs, command: [ qapi_gen, '-o', meson.current_b= uild_dir(), '-b', '-p', 'test-', '@INPUT0@'= ], depend_files: qapi_gen_depends) =20 +if with_rust + test_qapi_rs_outputs =3D ['test-qapi-ffi-types.rs'] + test_qapi_rs =3D custom_target('Test QAPI Rust binding', + output: test_qapi_rs_outputs, + input: test_qapi_inputs, + command: [ qapi_gen, '-o', meson.current_bu= ild_dir(), + '-r', '-b', '-p', 'test-', '@INP= UT0@' ], + depend_files: qapi_gen_depends) +endif + # meson doesn't like generated output in other directories # perhaps change qapi_gen to replace / with _, like Meson itself does? subdir('include') --=20 2.33.0.113.g6c40894d24 From nobody Tue May 7 11:02:16 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631019190161252.60373232287134; Tue, 7 Sep 2021 05:53:10 -0700 (PDT) Received: from localhost ([::1]:39136 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNab6-0000jN-Vc for importer@patchew.org; Tue, 07 Sep 2021 08:53:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42868) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNa9B-0006RL-5K for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:24:18 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:43505) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNa97-00088P-4F for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:24:16 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-141-Rwbpqst-M4Gpb_IzXs_1Bw-1; Tue, 07 Sep 2021 08:24:10 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8066D80292A for ; Tue, 7 Sep 2021 12:24:09 +0000 (UTC) Received: from localhost (unknown [10.39.208.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id 13B6D60C05; Tue, 7 Sep 2021 12:23:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631017452; 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=fbBTM1e8ZMRefW54scV5nkMLt1N7KS1x+oha0mIM9NI=; b=PQUz2UVT6pa1ybZCSkYzbXQZLYQDRadCZUZlaRSfcd/tCqJFAhWbd9+LZyM6IggrLm7wxA 2vKS30OpZNz7hcf9jLIKT0N6uhpCaCpv57KCI3Q79iUhd8ds+E6Sg5xn+2XZ7CnBDxVm5H RF9VcF3tsh8uq0IEnS3RNM0sbM9KHJ4= X-MC-Unique: Rwbpqst-M4Gpb_IzXs_1Bw-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [RFC v3 19/32] tests: check Rust and C CABI diffs Date: Tue, 7 Sep 2021 16:19:30 +0400 Message-Id: <20210907121943.3498701-20-marcandre.lureau@redhat.com> In-Reply-To: <20210907121943.3498701-1-marcandre.lureau@redhat.com> References: <20210907121943.3498701-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=marcandre.lureau@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, berrange@redhat.com, armbru@redhat.com, stefanha@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631019190939100001 From: Marc-Andr=C3=A9 Lureau Signed-off-by: Marc-Andr=C3=A9 Lureau --- meson.build | 3 +++ Cargo.lock | 7 +++++++ Cargo.toml | 1 + scripts/diff_commands.py | 40 ++++++++++++++++++++++++++++++++++++++++ tests/Cargo.toml | 13 +++++++++++++ tests/meson.build | 29 +++++++++++++++++++++++++---- tests/qapi-cabi.rs | 5 +++++ tests/qapi_ffi.rs | 8 ++++++++ 8 files changed, 102 insertions(+), 4 deletions(-) create mode 100644 scripts/diff_commands.py create mode 100644 tests/Cargo.toml create mode 100644 tests/qapi-cabi.rs create mode 100644 tests/qapi_ffi.rs diff --git a/meson.build b/meson.build index b45f409eb4..74e90059c2 100644 --- a/meson.build +++ b/meson.build @@ -118,6 +118,7 @@ cargo_wrapper =3D [ find_program('scripts/cargo_wrapper.py'), '--configh', meson.current_build_dir() / 'config-host.h' ] +diff_commands =3D find_program('scripts/diff_commands.py') =20 if with_rust rust_target_triple =3D get_option('with_rust_target') @@ -212,7 +213,9 @@ iokit =3D [] emulator_link_args =3D [] nvmm =3Dnot_found hvf =3D not_found +exe_suffix =3D '' if targetos =3D=3D 'windows' + exe_suffix =3D '.exe' socket =3D cc.find_library('ws2_32') winmm =3D cc.find_library('winmm') =20 diff --git a/Cargo.lock b/Cargo.lock index 8dc2dd9da7..f2cd0ee96e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -61,3 +61,10 @@ dependencies =3D [ "libc", "memoffset", ] + +[[package]] +name =3D "qemu-tests" +version =3D "0.0.1" +dependencies =3D [ + "common", +] diff --git a/Cargo.toml b/Cargo.toml index 14131eed3c..f4a078e62d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,4 +1,5 @@ [workspace] members =3D [ "rust/common", + "tests", ] diff --git a/scripts/diff_commands.py b/scripts/diff_commands.py new file mode 100644 index 0000000000..eecc03dd76 --- /dev/null +++ b/scripts/diff_commands.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python3 +# Copyright (c) 2020 Red Hat, Inc. +# +# Author: +# Marc-Andr=C3=A9 Lureau +# +# This work is licensed under the terms of the GNU GPL, version 2 or +# later. See the COPYING file in the top-level directory. + +import argparse +import difflib +import subprocess +import sys + + +def main() -> None: + parser =3D argparse.ArgumentParser() + parser.add_argument("EXE1") + parser.add_argument("EXE2") + args =3D parser.parse_args() + + exe1_out =3D subprocess.check_output(args.EXE1, universal_newlines=3DT= rue) + exe2_out =3D subprocess.check_output(args.EXE2, universal_newlines=3DT= rue) + out_diff =3D difflib.unified_diff( + exe1_out.splitlines(True), + exe2_out.splitlines(True), + fromfile=3Dargs.EXE1, + tofile=3Dargs.EXE2, + ) + has_diff =3D False + for line in out_diff: + has_diff =3D True + sys.stdout.write(line) + + if has_diff: + sys.exit(1) + + +if __name__ =3D=3D "__main__": + main() diff --git a/tests/Cargo.toml b/tests/Cargo.toml new file mode 100644 index 0000000000..7a4f6060b1 --- /dev/null +++ b/tests/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name =3D "qemu-tests" +version =3D "0.0.1" +edition =3D "2018" +publish =3D false + +[dependencies] +common =3D { path =3D "../rust/common" } + +[[bin]] +name =3D "qapi-cabi-rs" +path =3D "qapi-cabi.rs" +doc =3D false diff --git a/tests/meson.build b/tests/meson.build index 7292fe20df..f9af42caba 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -52,6 +52,19 @@ if with_rust command: [ qapi_gen, '-o', meson.current_bu= ild_dir(), '-r', '-b', '-p', 'test-', '@INP= UT0@' ], depend_files: qapi_gen_depends) + qapi_cabi_rs =3D custom_target('qapi-cabi-rs', + output: ['qapi-cabi-rs' + exe_suffix], + build_always_stale: true, + depends: [test_qapi_rs], + command: [cargo_wrapper, + meson.current_build_dir(), + meson.current_source_dir(), + meson.build_root(), + rs_build_type, + rust_target_triple, + 'build-bin', + 'qapi-cabi-rs', + '--', '--cfg', 'QAPI_CABI']) endif =20 # meson doesn't like generated output in other directories @@ -75,10 +88,18 @@ testqapi =3D declare_dependency(link_with: libtestqapi, dependencies: [qemuutil], sources: [genh, test_qapi_headers]) =20 -executable('qapi-cabi', - files('qapi-cabi.c'), - dependencies: testqapi, - c_args: ['-DQAPI_CABI']) +qapi_cabi =3D executable('qapi-cabi', + files('qapi-cabi.c'), + dependencies: testqapi, + c_args: ['-DQAPI_CABI']) + +if with_rust + test('Test QAPI CABI diff', + diff_commands, + args: [qapi_cabi.full_path(), qapi_cabi_rs.full_path()], + depends: [qapi_cabi, qapi_cabi_rs], + suite: ['qapi']) +endif =20 test_deps =3D { 'test-qht-par': qht_bench, diff --git a/tests/qapi-cabi.rs b/tests/qapi-cabi.rs new file mode 100644 index 0000000000..0b4b99cc78 --- /dev/null +++ b/tests/qapi-cabi.rs @@ -0,0 +1,5 @@ +mod qapi_ffi; + +fn main() { + qapi_ffi::cabi() +} diff --git a/tests/qapi_ffi.rs b/tests/qapi_ffi.rs new file mode 100644 index 0000000000..d50a02efbe --- /dev/null +++ b/tests/qapi_ffi.rs @@ -0,0 +1,8 @@ +#![allow(dead_code)] + +use common::libc; + +include!(concat!( + env!("MESON_BUILD_ROOT"), + "/tests/test-qapi-ffi-types.rs" +)); --=20 2.33.0.113.g6c40894d24 From nobody Tue May 7 11:02:16 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631019383419261.52861431568056; Tue, 7 Sep 2021 05:56:23 -0700 (PDT) Received: from localhost ([::1]:47910 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNaeA-0006lZ-De for importer@patchew.org; Tue, 07 Sep 2021 08:56:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42978) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNa9S-0007Eq-0J for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:24:34 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:54668) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNa9O-0008D2-5V for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:24:33 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-70-xzLggpJKNYGGXxHl2oUWyQ-1; Tue, 07 Sep 2021 08:24:22 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 041F7107ACCD for ; Tue, 7 Sep 2021 12:24:22 +0000 (UTC) Received: from localhost (unknown [10.39.208.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id 225E710013D7; Tue, 7 Sep 2021 12:24:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631017468; 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=W3M1F8GEkUCk9wCGHM8RpT/NIDPmq2FRxLHZG7uAr5k=; b=a2Xu4BuPFGxdd/TrPegG8ZnWBhE8pVmybeAiUTv8ghczyJyGlKa5AXiRHSWE3obm8v59WM EgmdpcHydF9kEgrBWLjFpek8vw7vb2Q6jIj/eMe/FjTxPdiSqAJRm4pQIhg1iSE9ueeIub mTHKWW5xRq/iHWKkSE+fLwmEg8HG6ps= X-MC-Unique: xzLggpJKNYGGXxHl2oUWyQ-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [RFC v3 20/32] scripts/qapi: generate high-level Rust bindings Date: Tue, 7 Sep 2021 16:19:31 +0400 Message-Id: <20210907121943.3498701-21-marcandre.lureau@redhat.com> In-Reply-To: <20210907121943.3498701-1-marcandre.lureau@redhat.com> References: <20210907121943.3498701-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=marcandre.lureau@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, berrange@redhat.com, armbru@redhat.com, stefanha@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631019384555100001 From: Marc-Andr=C3=A9 Lureau Generate high-level idiomatic Rust code for the QAPI types, with to/from translations for the C FFI. - char* is mapped to String, scalars to there corresponding Rust types - enums are simply aliased from FFI - has_foo/foo members are mapped to Option - lists are represented as Vec - structures have Rust versions, with To/From FFI conversions - alternate are represented as Rust enum - unions are represented in a similar way as in C: a struct S with a "u" member (since S may have extra 'base' fields). However, the discriminant isn't a member of S, since Rust enum already include it. Signed-off-by: Marc-Andr=C3=A9 Lureau --- meson.build | 1 + scripts/qapi/main.py | 2 + scripts/qapi/rs.py | 94 +++- scripts/qapi/rs_types.py | 966 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 1062 insertions(+), 1 deletion(-) create mode 100644 scripts/qapi/rs_types.py diff --git a/meson.build b/meson.build index 74e90059c2..8e12a4dd70 100644 --- a/meson.build +++ b/meson.build @@ -2017,6 +2017,7 @@ qapi_gen_depends =3D [ meson.source_root() / 'scripts= /qapi/__init__.py', meson.source_root() / 'scripts/qapi/common.py', meson.source_root() / 'scripts/qapi/rs.py', meson.source_root() / 'scripts/qapi/rs_ffi.py', + meson.source_root() / 'scripts/qapi/rs_types.py', meson.source_root() / 'scripts/qapi-gen.py', ] =20 diff --git a/scripts/qapi/main.py b/scripts/qapi/main.py index deba72ee4e..9756c0c35d 100644 --- a/scripts/qapi/main.py +++ b/scripts/qapi/main.py @@ -17,6 +17,7 @@ from .events import gen_events from .introspect import gen_introspect from .rs_ffi import gen_rs_ffitypes +from .rs_types import gen_rs_types from .schema import QAPISchema from .types import gen_types from .visit import gen_visit @@ -52,6 +53,7 @@ def generate(schema_file: str, schema =3D QAPISchema(schema_file) if rust: gen_rs_ffitypes(schema, output_dir, prefix) + gen_rs_types(schema, output_dir, prefix) else: gen_types(schema, output_dir, prefix, builtins) gen_visit(schema, output_dir, prefix, builtins) diff --git a/scripts/qapi/rs.py b/scripts/qapi/rs.py index be42329fa4..b53930eab2 100644 --- a/scripts/qapi/rs.py +++ b/scripts/qapi/rs.py @@ -9,7 +9,7 @@ import subprocess from typing import NamedTuple, Optional =20 -from .common import POINTER_SUFFIX +from .common import POINTER_SUFFIX, mcgen from .gen import QAPIGen from .schema import QAPISchemaModule, QAPISchemaVisitor =20 @@ -53,6 +53,64 @@ def rs_name(name: str, protect: bool =3D True) -> str: return name =20 =20 +def rs_type(c_type: str, + qapi_ns: Optional[str] =3D 'qapi::', + optional: Optional[bool] =3D False, + box: bool =3D False) -> str: + (is_pointer, _, is_list, c_type) =3D rs_ctype_parse(c_type) + # accepts QAPI types ('any', 'str', ...) as we translate + # qapiList to Rust FFI types here. + to_rs =3D { + 'any': 'QObject', + 'bool': 'bool', + 'char': 'i8', + 'double': 'f64', + 'int': 'i64', + 'int16': 'i16', + 'int16_t': 'i16', + 'int32': 'i32', + 'int32_t': 'i32', + 'int64': 'i64', + 'int64_t': 'i64', + 'int8': 'i8', + 'int8_t': 'i8', + 'null': 'QNull', + 'number': 'f64', + 'size': 'u64', + 'str': 'String', + 'uint16': 'u16', + 'uint16_t': 'u16', + 'uint32': 'u32', + 'uint32_t': 'u32', + 'uint64': 'u64', + 'uint64_t': 'u64', + 'uint8': 'u8', + 'uint8_t': 'u8', + 'String': 'QapiString', + } + if is_pointer: + to_rs.update({ + 'char': 'String', + }) + + if is_list: + c_type =3D c_type[:-4] + + to_rs =3D to_rs.get(c_type) + if to_rs: + ret =3D to_rs + else: + ret =3D qapi_ns + c_type + + if is_list: + ret =3D 'Vec<%s>' % ret + elif is_pointer and not to_rs and box: + ret =3D 'Box<%s>' % ret + if optional: + ret =3D 'Option<%s>' % ret + return ret + + class CType(NamedTuple): is_pointer: bool is_const: bool @@ -140,6 +198,40 @@ def to_snake_case(value: str) -> str: return snake_case.sub(r'_\1', value).lower() =20 =20 +def to_qemu_none(c_type: str, name: str) -> str: + (is_pointer, _, is_list, _) =3D rs_ctype_parse(c_type) + + if is_pointer: + if c_type =3D=3D 'char': + return mcgen(''' + let %(name)s_ =3D CString::new(%(name)s).unwrap(); + let %(name)s =3D %(name)s_.as_ptr(); +''', name=3Dname) + if is_list: + return mcgen(''' + let %(name)s_ =3D NewPtr(%(name)s).to_qemu_none(); + let %(name)s =3D %(name)s_.0.0; +''', name=3Dname) + return mcgen(''' + let %(name)s_ =3D %(name)s.to_qemu_none(); + let %(name)s =3D %(name)s_.0; +''', name=3Dname) + return '' + + +def from_qemu(var_name: str, c_type: str, full: Optional[bool] =3D False) = -> str: + (is_pointer, _, is_list, c_type) =3D rs_ctype_parse(c_type) + ptr =3D '{} as *{} _'.format(var_name, 'mut' if full else 'const') + if is_list: + ptr =3D 'NewPtr({})'.format(ptr) + if is_pointer: + ret =3D 'from_qemu_{}({})'.format('full' if full else 'none', ptr) + if c_type !=3D 'char' and not is_list: + ret =3D 'Box::new(%s)' % ret + return ret + return var_name + + class QAPIGenRs(QAPIGen): pass =20 diff --git a/scripts/qapi/rs_types.py b/scripts/qapi/rs_types.py new file mode 100644 index 0000000000..eb9877a0de --- /dev/null +++ b/scripts/qapi/rs_types.py @@ -0,0 +1,966 @@ +# This work is licensed under the terms of the GNU GPL, version 2. +# See the COPYING file in the top-level directory. +""" +QAPI Rust types generator +""" + +from typing import List, Optional + +from .common import POINTER_SUFFIX, mcgen +from .rs import ( + QAPISchemaRsVisitor, + from_qemu, + rs_ctype_parse, + rs_ffitype, + rs_name, + rs_type, + to_camel_case, + to_snake_case, +) +from .schema import ( + QAPISchema, + QAPISchemaEnumMember, + QAPISchemaEnumType, + QAPISchemaFeature, + QAPISchemaIfCond, + QAPISchemaObjectType, + QAPISchemaObjectTypeMember, + QAPISchemaType, + QAPISchemaVariants, +) +from .source import QAPISourceInfo + + +objects_seen =3D set() + + +def gen_rs_variants_to_tag(name: str, + ifcond: QAPISchemaIfCond, + variants: Optional[QAPISchemaVariants]) -> str: + ret =3D mcgen(''' + +%(cfg)s +impl From<&%(rs_name)sVariant> for %(tag)s { + fn from(e: &%(rs_name)sVariant) -> Self { + match e { + ''', + cfg=3Difcond.rsgen(), + rs_name=3Drs_name(name), + tag=3Drs_type(variants.tag_member.type.c_type(), '')) + + for var in variants.variants: + type_name =3D var.type.name + var_name =3D to_camel_case(rs_name(var.name)) + patt =3D '(_)' + if type_name =3D=3D 'q_empty': + patt =3D '' + ret +=3D mcgen(''' + %(cfg)s + %(rs_name)sVariant::%(var_name)s%(patt)s =3D> Self::%(var_name)s, +''', + cfg=3Dvar.ifcond.rsgen(), + rs_name=3Drs_name(name), + var_name=3Dvar_name, + patt=3Dpatt) + + ret +=3D mcgen(''' + } + } +} +''') + return ret + + +def variants_to_qemu_inner(name: str, + variants: Optional[QAPISchemaVariants]) -> str: + members =3D '' + none_arms =3D '' + full_arms =3D '' + lifetime =3D '' + for var in variants.variants: + var_name =3D to_camel_case(rs_name(var.name)) + type_name =3D var.type.name + if type_name =3D=3D 'q_empty': + members +=3D mcgen(''' + %(cfg)s + %(var_name)s, +''', + cfg=3Dvar.ifcond.rsgen(), + var_name=3Dvar_name) + none_arms +=3D mcgen(''' + %(cfg)s + %(rs_name)sVariant::%(var_name)s =3D> { + (std::ptr::null_mut(), + %(rs_name)sVariantStorage::%(var_name)s) + }, +''', + cfg=3Dvar.ifcond.rsgen(), + rs_name=3Drs_name(name), + var_name=3Dvar_name) + full_arms +=3D mcgen(''' + %(cfg)s + %(rs_name)sVariant::%(var_name)s =3D> { + std::ptr::null_mut() + } +''', + cfg=3Dvar.ifcond.rsgen(), + rs_name=3Drs_name(name), + var_name=3Dvar_name) + continue + c_type =3D var.type.c_unboxed_type() + if type_name.endswith('-wrapper'): + wrap =3D list(var.type.members)[0] + type_name =3D wrap.type.name + c_type =3D wrap.type.c_unboxed_type() + + lifetime =3D "<'a>" + (_, _, is_list, ffitype) =3D rs_ctype_parse(c_type) + ffitype =3D rs_ffitype(ffitype) + ptr_ty =3D 'NewPtr<*mut %s>' % ffitype if is_list else '*mut ' + f= fitype + stash_ty =3D ': Stash<%s, _>' % ptr_ty if is_list else '' + + members +=3D mcgen(''' + %(cfg)s + %(var_name)s(<%(rs_type)s as ToQemuPtr<'a, %(ptr_ty)s>>::Storage), +''', + cfg=3Dvar.ifcond.rsgen(), + var_name=3Dvar_name, + rs_type=3Drs_type(c_type, ''), + ptr_ty=3Dptr_ty) + none_arms +=3D mcgen(''' + %(cfg)s + %(rs_name)sVariant::%(var_name)s(v) =3D> { + let stash_%(stash_ty)s =3D v.to_qemu_none(); + (stash_.0.to() as *mut std::ffi::c_void, + %(rs_name)sVariantStorage::%(var_name)s(stash_.1)) + }, +''', + cfg=3Dvar.ifcond.rsgen(), + rs_name=3Drs_name(name), + var_name=3Dvar_name, + stash_ty=3Dstash_ty) + ptr_ty =3D ': %s' % ptr_ty if is_list else '' + full_arms +=3D mcgen(''' + %(cfg)s + %(rs_name)sVariant::%(var_name)s(v) =3D> { + let ptr%(ptr_ty)s =3D v.to_qemu_full(); + ptr.to() as *mut std::ffi::c_void + }, +''', + cfg=3Dvar.ifcond.rsgen(), + rs_name=3Drs_name(name), + var_name=3Dvar_name, + ptr_ty=3Dptr_ty) + return (members, none_arms, full_arms, lifetime) + + +def gen_rs_variants_to_qemu(name: str, + ifcond: QAPISchemaIfCond, + variants: Optional[QAPISchemaVariants]) -> str: + (members, none_arms, full_arms, lifetime) =3D \ + variants_to_qemu_inner(name, variants) + return mcgen(''' + +%(cfg)s +impl QemuPtrDefault for %(rs_name)sVariant { + type QemuType =3D *mut std::ffi::c_void; +} + +%(cfg)s +pub enum %(rs_name)sVariantStorage%(lt)s { + %(members)s +} + +%(cfg)s +impl<'a> ToQemuPtr<'a, *mut std::ffi::c_void> for %(rs_name)sVariant { + type Storage =3D %(rs_name)sVariantStorage%(lt)s; + + #[inline] + fn to_qemu_none(&'a self) + -> Stash<'a, *mut std::ffi::c_void, %(rs_name)sVariant> { + let (ptr_, cenum_) =3D match self { + %(none_arms)s + }; + + Stash(ptr_, cenum_) + } + + #[inline] + fn to_qemu_full(&self) -> *mut std::ffi::c_void { + match self { + %(full_arms)s + } + } +} +''', + cfg=3Difcond.rsgen(), + rs_name=3Drs_name(name), + lt=3Dlifetime, + members=3Dmembers, + none_arms=3Dnone_arms, + full_arms=3Dfull_arms) + + +def gen_rs_variants(name: str, + ifcond: QAPISchemaIfCond, + variants: Optional[QAPISchemaVariants]) -> str: + ret =3D mcgen(''' + +%(cfg)s +#[derive(Clone,Debug)] +pub enum %(rs_name)sVariant { +''', + cfg=3Difcond.rsgen(), + rs_name=3Drs_name(name)) + + for var in variants.variants: + type_name =3D var.type.name + var_name =3D to_camel_case(rs_name(var.name, False)) + if type_name =3D=3D 'q_empty': + ret +=3D mcgen(''' + %(cfg)s + %(var_name)s, +''', + cfg=3Dvar.ifcond.rsgen(), + var_name=3Dvar_name) + else: + c_type =3D var.type.c_unboxed_type() + if c_type.endswith('_wrapper'): + c_type =3D c_type[6:-8] # remove q_obj*-wrapper + ret +=3D mcgen(''' + %(cfg)s + %(var_name)s(%(rs_type)s), +''', + cfg=3Dvar.ifcond.rsgen(), + var_name=3Dvar_name, + rs_type=3Drs_type(c_type, '')) + + ret +=3D mcgen(''' +} +''') + + ret +=3D gen_rs_variants_to_tag(name, ifcond, variants) + # implement ToQemu trait for the storage handling + # no need for gen_rs_variants_from_qemu() however + ret +=3D gen_rs_variants_to_qemu(name, ifcond, variants) + + return ret + + +def gen_rs_object_to_qemu(name: str, + ifcond: QAPISchemaIfCond, + base: Optional[QAPISchemaObjectType], + members: List[QAPISchemaObjectTypeMember], + variants: Optional[QAPISchemaVariants]) -> str: + storage =3D [] + stash =3D [] + ffi_memb =3D [] + memb_none =3D '' + memb_full =3D '' + if base: + members =3D list(base.members) + members + for memb in members: + if variants and variants.tag_member.name =3D=3D memb.name: + continue + memb_name =3D to_snake_case(rs_name(memb.name)) + c_type =3D memb.type.c_type() + (is_pointer, _, is_list, _) =3D rs_ctype_parse(c_type) + if is_pointer: + if memb.ifcond.is_present(): + raise NotImplementedError("missing support for condition h= ere") + typ =3D rs_type(memb.type.c_type(), + optional=3Dmemb.optional, + qapi_ns=3D'', + box=3DTrue) + styp =3D rs_ffitype(memb.type.c_type(), list_as_newp=3DTrue) + storage.append("Stash<'a, %s, %s>" % (styp, typ)) + if memb.optional: + has_memb_name =3D 'has_%s' % rs_name(memb.name, protect=3DFals= e) + ffi_memb.append(f"{memb.ifcond.rsgen()} {has_memb_name}") + has_memb =3D mcgen(''' + %(cfg)s + let %(has_memb_name)s =3D self.%(memb_name)s.is_some(); +''', + cfg=3Dmemb.ifcond.rsgen(), + memb_name=3Dmemb_name, + has_memb_name=3Dhas_memb_name) + memb_none +=3D has_memb + memb_full +=3D has_memb + + if is_pointer: + stash_name =3D '{}_stash_'.format(memb_name) + stash.append(stash_name) + var =3D 'NewPtr(%s)' % memb_name if is_list else memb_name + memb_none +=3D mcgen(''' + let %(stash_name)s =3D self.%(memb_name)s.to_qemu_none(); + let %(var)s =3D %(stash_name)s.0; +''', stash_name=3Dstash_name, memb_name=3Dmemb_name, var=3Dvar) + memb_full +=3D mcgen(''' + let %(var)s =3D self.%(memb_name)s.to_qemu_full(); +''', memb_name=3Dmemb_name, var=3Dvar) + else: + unwrap =3D '' + if memb.optional: + unwrap =3D '.unwrap_or_default()' + assign =3D mcgen(''' + %(cfg)s + let %(memb_name)s =3D self.%(memb_name)s%(unwrap)s; +''', + cfg=3Dmemb.ifcond.rsgen(), + memb_name=3Dmemb_name, + unwrap=3Dunwrap) + memb_none +=3D assign + memb_full +=3D assign + + ffi_memb.append(f"{memb.ifcond.rsgen()} {memb_name}") + + if variants: + tag_name =3D rs_name(variants.tag_member.name) + ffi_memb.append(tag_name) + ffi_memb.append('u') + voidp =3D '*mut std::ffi::c_void' + storage.append("Stash<'a, %s, %sVariant>" % (voidp, rs_name(name))) + tag =3D mcgen(''' + let %(tag_name)s =3D (&self.u).into(); +''', tag_name=3Dtag_name) + memb_none +=3D tag + memb_full +=3D tag + arms_none =3D '' + arms_full =3D '' + for variant in variants.variants: + typ =3D variant.type + if typ.name =3D=3D 'q_empty': + arms_none +=3D mcgen(''' + %(cfg)s + %(rs_name)sVariantStorage::%(kind)s =3D> qapi_ffi::%(rs_name)sUnion { + qapi_dummy: qapi_ffi::QapiDummy, + },''', + cfg=3Dvariant.ifcond.rsgen(), + rs_name=3Drs_name(name), + kind=3Dto_camel_case(rs_name(variant.na= me))) + arms_full +=3D mcgen(''' + %(cfg)s + %(rs_name)sVariant::%(kind)s =3D> qapi_ffi::%(rs_name)sUnion { + qapi_dummy: qapi_ffi::QapiDummy, + },''', + cfg=3Dvariant.ifcond.rsgen(), + rs_name=3Drs_name(name), + kind=3Dto_camel_case(rs_name(variant.na= me))) + else: + if typ.name.endswith('-wrapper'): + wrap_ty =3D list(typ.members)[0].type.c_type() + ptr =3D wrap_ty.endswith(POINTER_SUFFIX) + val =3D ( + rs_ffitype(variant.type.c_unboxed_type()) + + ' { data: u_stash_.0.to() as *mut _ }' if ptr else + ' { data: unsafe { *(u_stash_.0.to() as *const _) = } }' + ) + else: + val =3D '*_s.0' + arms_none +=3D mcgen(''' + %(cfg)s + %(rs_name)sVariantStorage::%(kind)s(ref _s) =3D> qapi_ffi::%(rs_name)s= Union { + %(var_name)s: %(val)s, + },''', + cfg=3Dvariant.ifcond.rsgen(), + rs_name=3Drs_name(name), + kind=3Dto_camel_case(rs_name(variant.na= me)), + var_name=3Drs_name(variant.name), + val=3Dval) + arms_full +=3D mcgen(''' + %(cfg)s + %(rs_name)sVariant::%(kind)s(_) =3D> qapi_ffi::%(rs_name)sUnion { + %(var_name)s: *(u_ptr_.to() as *const _), + },''', + cfg=3Dvariant.ifcond.rsgen(), + rs_name=3Drs_name(name), + kind=3Dto_camel_case(rs_name(variant.na= me)), + var_name=3Drs_name(variant.name)) + memb_none +=3D mcgen(''' + let u_stash_ =3D self.u.to_qemu_none(); + let u =3D match u_stash_.1 { + %(arms)s + }; +''', arms=3Darms_none) + stash.append('u_stash_') + memb_full +=3D mcgen(''' + let u_ptr_ =3D self.u.to_qemu_full(); + let u =3D match self.u { + %(arms)s + }; + ffi::g_free(u_ptr_); +''', arms=3Darms_full) + + if not ffi_memb: + ffi_memb =3D ['qapi_dummy_for_empty_struct: 0'] + + return mcgen(''' + +%(cfg)s +impl QemuPtrDefault for %(rs_name)s { + type QemuType =3D *mut qapi_ffi::%(rs_name)s; +} + +%(cfg)s +impl<'a> ToQemuPtr<'a, *mut qapi_ffi::%(rs_name)s> for %(rs_name)s { + type Storage =3D (Box, %(storage)s); + + #[inline] + fn to_qemu_none(&'a self) + -> Stash<'a, *mut qapi_ffi::%(rs_name)s, %(rs_name)s> { + %(memb_none)s + let mut box_ =3D Box::new(qapi_ffi::%(rs_name)s { %(ffi_memb)s }); + + Stash(&mut *box_, (box_, %(stash)s)) + } + + #[inline] + fn to_qemu_full(&self) -> *mut qapi_ffi::%(rs_name)s { + unsafe { + %(memb_full)s + let ptr =3D ffi::g_malloc0( + std::mem::size_of::<%(rs_name)s>()) as *mut _; + *ptr =3D qapi_ffi::%(rs_name)s { %(ffi_memb)s }; + ptr + } + } +} +''', + cfg=3Difcond.rsgen(), + rs_name=3Drs_name(name), + storage=3D', '.join(storage), + ffi_memb=3D', '.join(ffi_memb), + memb_none=3Dmemb_none, + memb_full=3Dmemb_full, + stash=3D', '.join(stash)) + + +def gen_rs_members(members: List[QAPISchemaObjectTypeMember], + exclude: List[str] =3D None) -> str: + exclude =3D exclude or [] + return [f"{m.ifcond.rsgen()} {to_snake_case(rs_name(m.name))}" + for m in members if m.name not in exclude] + + +def gen_rs_object_from_qemu(name: str, + ifcond: QAPISchemaIfCond, + base: Optional[QAPISchemaObjectType], + members: List[QAPISchemaObjectTypeMember], + variants: Optional[QAPISchemaVariants]) -> str: + exclude =3D [variants.tag_member.name] if variants else [] + memb_names =3D [] + if base: + names =3D gen_rs_members(base.members, exclude) + memb_names.extend(names) + names =3D gen_rs_members(members, exclude) + memb_names.extend(names) + + ret =3D mcgen(''' + +%(cfg)s +impl FromQemuPtrFull<*mut qapi_ffi::%(rs_name)s> for %(rs_name)s { + unsafe fn from_qemu_full(ffi: *mut qapi_ffi::%(rs_name)s) -> Self { + let ret =3D from_qemu_none(ffi as *const _); + qapi_ffi::qapi_free_%(name)s(ffi); + ret + } +} + +%(cfg)s +impl FromQemuPtrNone<*const qapi_ffi::%(rs_name)s> for %(rs_name)s { + unsafe fn from_qemu_none(ffi: *const qapi_ffi::%(rs_name)s) -> Self { + let _ffi =3D &*ffi; +''', + cfg=3Difcond.rsgen(), + name=3Drs_name(name, protect=3DFalse), + rs_name=3Drs_name(name)) + + if base: + members =3D list(base.members) + members + + tag_member =3D variants.tag_member if variants else None + for memb in members: + if memb =3D=3D tag_member: + continue + memb_name =3D rs_name(memb.name) + val =3D from_qemu('_ffi.' + to_snake_case(memb_name), memb.type.c_= type()) + if memb.optional: + val =3D mcgen('''{ + if _ffi.has_%(memb_name)s { + Some(%(val)s) + } else { + None + } +}''', + memb_name=3Drs_name(memb.name, protect=3DFalse), + val=3Dval) + + ret +=3D mcgen(''' + %(cfg)s + let %(snake_memb_name)s =3D %(val)s; +''', + cfg=3Dmemb.ifcond.rsgen(), + snake_memb_name=3Dto_snake_case(memb_name), + memb_name=3Dmemb_name, + val=3Dval) + + if variants: + arms =3D '' + assert isinstance(variants.tag_member.type, QAPISchemaEnumType) + for variant in variants.variants: + typ =3D variant.type + if typ.name =3D=3D 'q_empty': + memb =3D '' + else: + ptr =3D True + is_list =3D False + memb =3D to_snake_case(rs_name(variant.name)) + if typ.name.endswith('-wrapper'): + memb =3D '_ffi.u.%s.data' % memb + wrap_ty =3D list(typ.members)[0].type.c_type() + (ptr, _, is_list, _) =3D rs_ctype_parse(wrap_ty) + else: + memb =3D '&_ffi.u.%s' % memb + if ptr: + memb =3D '%s as *const _' % memb + if is_list: + memb =3D 'NewPtr(%s)' % memb + memb =3D 'from_qemu_none(%s)' % memb + memb =3D '(%s)' % memb + arms +=3D mcgen(''' +%(cfg)s +%(enum)s::%(variant)s =3D> { %(rs_name)sVariant::%(variant)s%(memb)s }, +''', + cfg=3Dvariant.ifcond.rsgen(), + enum=3Drs_name(variants.tag_member.type.name), + memb=3Dmemb, + variant=3Dto_camel_case(rs_name(variant.name)), + rs_name=3Drs_name(name)) + ret +=3D mcgen(''' + let u =3D match _ffi.%(tag)s { + %(arms)s + _ =3D> panic!("Variant with invalid tag"), + }; +''', + tag=3Drs_name(variants.tag_member.name), + arms=3Darms) + memb_names.append('u') + + ret +=3D mcgen(''' + Self { %(memb_names)s } + } +} +''', + memb_names=3D', '.join(memb_names)) + return ret + + +def gen_struct_members(members: List[QAPISchemaObjectTypeMember]) -> str: + ret =3D '' + for memb in members: + typ =3D rs_type(memb.type.c_type(), '', optional=3Dmemb.optional, = box=3DTrue) + ret +=3D mcgen(''' + %(cfg)s + pub %(rs_name)s: %(rs_type)s, +''', + cfg=3Dmemb.ifcond.rsgen(), + rs_type=3Dtyp, + rs_name=3Dto_snake_case(rs_name(memb.name))) + return ret + + +def gen_rs_object(name: str, + ifcond: QAPISchemaIfCond, + base: Optional[QAPISchemaObjectType], + members: List[QAPISchemaObjectTypeMember], + variants: Optional[QAPISchemaVariants]) -> str: + if name in objects_seen: + return '' + + if variants: + members =3D [m for m in members + if m.name !=3D variants.tag_member.name] + + ret =3D '' + objects_seen.add(name) + + if variants: + ret +=3D gen_rs_variants(name, ifcond, variants) + + ret +=3D mcgen(''' + +%(cfg)s +#[derive(Clone, Debug)] +pub struct %(rs_name)s { +''', + cfg=3Difcond.rsgen(), + rs_name=3Drs_name(name)) + + if base: + if not base.is_implicit(): + ret +=3D mcgen(''' + // Members inherited: +''', + c_name=3Dbase.c_name()) + base_members =3D base.members + if variants: + base_members =3D [m for m in base.members + if m.name !=3D variants.tag_member.name] + ret +=3D gen_struct_members(base_members) + if not base.is_implicit(): + ret +=3D mcgen(''' + // Own members: +''') + + ret +=3D gen_struct_members(members) + + if variants: + ret +=3D mcgen(''' + pub u: %(rs_type)sVariant, +''', rs_type=3Drs_name(name)) + ret +=3D mcgen(''' +} +''') + + ret +=3D gen_rs_object_from_qemu(name, ifcond, base, members, variants) + ret +=3D gen_rs_object_to_qemu(name, ifcond, base, members, variants) + return ret + + +def gen_rs_alternate_from_qemu(name: str, + ifcond: QAPISchemaIfCond, + variants: Optional[QAPISchemaVariants]) -> = str: + arms =3D '' + for var in variants.variants: + qtype =3D to_camel_case(var.type.alternate_qtype()[6:].lower()) + ptr =3D var.type.c_unboxed_type().endswith(POINTER_SUFFIX) + memb =3D 'ffi.u.%s' % rs_name(var.name) + if not ptr: + memb =3D '&' + memb + arms +=3D mcgen(''' + %(cfg)s + QType::%(qtype)s =3D> { + Self::%(kind)s(from_qemu_none(%(memb)s as *const _)) + } +''', + qtype=3Dqtype, + cfg=3Dvar.ifcond.rsgen(), + kind=3Dto_camel_case(rs_name(var.name)), + memb=3Dmemb) + + ret =3D mcgen(''' + +%(cfg)s +impl FromQemuPtrFull<*mut qapi_ffi::%(rs_name)s> for %(rs_name)s { + unsafe fn from_qemu_full(ffi: *mut qapi_ffi::%(rs_name)s) -> Self { + let ret =3D from_qemu_none(ffi as *const _); + qapi_ffi::qapi_free_%(name)s(ffi); + ret + } +} + +%(cfg)s +impl FromQemuPtrNone<*const qapi_ffi::%(rs_name)s> for %(rs_name)s { + unsafe fn from_qemu_none(ffi: *const qapi_ffi::%(rs_name)s) -> Self { + let ffi =3D &*ffi; + + match ffi.r#type { + %(arms)s + _ =3D> panic!() + } + } +} +''', + cfg=3Difcond.rsgen(), + name=3Drs_name(name, protect=3DFalse), + rs_name=3Drs_name(name), + arms=3Darms) + return ret + + +def gen_rs_alternate_to_qemu(name: str, + ifcond: QAPISchemaIfCond, + variants: Optional[QAPISchemaVariants], + lifetime: str) -> str: + arms_none =3D '' + arms_full =3D '' + for var in variants.variants: + if var.type.name =3D=3D 'q_empty': + continue + ptr =3D var.type.c_unboxed_type().endswith(POINTER_SUFFIX) + val =3D 'val.0' if ptr else 'unsafe { *(val.0.to() as *const _) }' + stor =3D '(val.1)' if var.type.c_type().endswith(POINTER_SUFFIX) e= lse '' + qtype =3D var.type.alternate_qtype()[6:].lower() + arms_none +=3D mcgen(''' + %(cfg)s + Self::%(memb_name)s(val) =3D> { + let val =3D val.to_qemu_none(); + ( + QType::%(qtype)s, + qapi_ffi::%(rs_name)sUnion { %(ffi_memb_name)s: %(val)s }, + %(rs_name)sStorage::%(memb_name)s%(stor)s + ) + } +''', + rs_name=3Drs_name(name), + cfg=3Dvar.ifcond.rsgen(), + memb_name=3Dto_camel_case(rs_name(var.name)), + ffi_memb_name=3Drs_name(var.name), + qtype=3Dto_camel_case(qtype), + val=3Dval, + stor=3Dstor) + val =3D 'val' if ptr else '*val' + free =3D '' if ptr else 'ffi::g_free(val as *mut _);' + arms_full +=3D mcgen(''' + %(cfg)s + Self::%(memb_name)s(val) =3D> { + let val =3D val.to_qemu_full(); + let ret =3D (QType::%(qtype)s, qapi_ffi::%(rs_name)sUnion { + %(ffi_memb_name)s: %(val)s + } ); + %(free)s + ret + } +''', + rs_name=3Drs_name(name), + cfg=3Dvar.ifcond.rsgen(), + memb_name=3Dto_camel_case(rs_name(var.name)), + ffi_memb_name=3Drs_name(var.name), + qtype=3Dto_camel_case(qtype), + val=3Dval, + free=3Dfree) + + memb_none =3D mcgen(''' + let (r#type, u, stor) =3D match self { + %(arms_none)s + }; +''', arms_none=3Darms_none) + memb_full =3D mcgen(''' + let (r#type, u) =3D match self { + %(arms_full)s + }; +''', arms_full=3Darms_full) + ffi_memb =3D ['r#type', 'u'] + return mcgen(''' + +%(cfg)s +impl QemuPtrDefault for %(rs_name)s { + type QemuType =3D *mut qapi_ffi::%(rs_name)s; +} + +%(cfg)s +impl<'a> ToQemuPtr<'a, *mut qapi_ffi::%(rs_name)s> for %(rs_name)s { + // Additional boxing of storage needed due to recursive types + type Storage =3D (Box, Box<%(rs_name)sStorage%(= lt)s>); + + #[inline] + fn to_qemu_none(&'a self) + -> Stash<'a, *mut qapi_ffi::%(rs_name)s, %(rs_name)s> { + %(memb_none)s + let mut box_ =3D Box::new(qapi_ffi::%(rs_name)s { %(ffi_memb)s }); + + Stash(&mut *box_, (box_, Box::new(stor))) + } + + #[inline] + fn to_qemu_full(&self) -> *mut qapi_ffi::%(rs_name)s { + unsafe { + %(memb_full)s + let ptr =3D ffi::g_malloc0( + std::mem::size_of::<%(rs_name)s>()) as *mut _; + *ptr =3D qapi_ffi::%(rs_name)s { %(ffi_memb)s }; + ptr + } + } +} +''', + cfg=3Difcond.rsgen(), + rs_name=3Drs_name(name), + lt=3Dlifetime, + ffi_memb=3D', '.join(ffi_memb), + memb_none=3Dmemb_none, + memb_full=3Dmemb_full) + + +def gen_rs_alternate(name: str, + ifcond: QAPISchemaIfCond, + variants: Optional[QAPISchemaVariants]) -> str: + if name in objects_seen: + return '' + + ret =3D '' + objects_seen.add(name) + + ret +=3D mcgen(''' +%(cfg)s +#[derive(Clone, Debug)] +pub enum %(rs_name)s { +''', + cfg=3Difcond.rsgen(), + rs_name=3Drs_name(name)) + + for var in variants.variants: + if var.type.name =3D=3D 'q_empty': + continue + ret +=3D mcgen(''' + %(cfg)s + %(mem_name)s(%(rs_type)s), +''', + cfg=3Dvar.ifcond.rsgen(), + rs_type=3Drs_type(var.type.c_unboxed_type(), ''), + mem_name=3Dto_camel_case(rs_name(var.name))) + + membs =3D '' + lifetime =3D '' + for var in variants.variants: + var_name =3D to_camel_case(rs_name(var.name)) + type_name =3D var.type.name + if type_name =3D=3D 'q_empty': + continue + if not var.type.c_type().endswith(POINTER_SUFFIX): + membs +=3D mcgen(''' + %(cfg)s + %(var_name)s, +''', + cfg=3Dvar.ifcond.rsgen(), + var_name=3Dvar_name) + else: + lifetime =3D "<'a>" + c_type =3D var.type.c_type() + ptr_ty =3D rs_ffitype(c_type) + membs +=3D mcgen(''' + %(cfg)s + %(var_name)s(<%(rs_type)s as ToQemuPtr<'a, %(ptr_ty)s>>::Storage), +''', + cfg=3Dvar.ifcond.rsgen(), + var_name=3Dvar_name, + rs_type=3Drs_type(c_type, ''), + ptr_ty=3Dptr_ty) + ret +=3D mcgen(''' +} + +%(cfg)s +pub enum %(rs_name)sStorage%(lt)s { + %(membs)s +} +''', + cfg=3Difcond.rsgen(), + rs_name=3Drs_name(name), + lt=3Dlifetime, + membs=3Dmembs) + + ret +=3D gen_rs_alternate_from_qemu(name, ifcond, variants) + ret +=3D gen_rs_alternate_to_qemu(name, ifcond, variants, lifetime) + + return ret + + +def gen_rs_enum(name: str, ifcond: QAPISchemaIfCond) -> str: + return mcgen(''' + +%(cfg)s +pub type %(rs_name)s =3D qapi_ffi::%(ffi_name)s; + +%(cfg)s +impl_to_qemu_scalar_boxed!(%(rs_name)s); + +%(cfg)s +impl_from_qemu_none_scalar!(%(rs_name)s); +''', + cfg=3Difcond.rsgen(), + rs_name=3Drs_name(name), + ffi_name=3Drs_name(name)) + + +class QAPISchemaGenRsTypeVisitor(QAPISchemaRsVisitor): + + def __init__(self, prefix: str) -> None: + super().__init__(prefix, 'qapi-types') + + def visit_begin(self, schema: QAPISchema) -> None: + # don't visit the empty type + objects_seen.add(schema.the_empty_object_type.name) + self._gen.preamble_add( + mcgen(''' +// generated by qapi-gen, DO NOT EDIT + +use common::{QNull, QObject}; +use crate::qapi_ffi; + +''')) + + def visit_array_type(self, + name: str, + info: Optional[QAPISourceInfo], + ifcond: QAPISchemaIfCond, + element_type: QAPISchemaType) -> None: + typ =3D rs_type(name, qapi_ns=3D'') + scalar =3D False + if name[:-4] in {'number', + 'int', + 'int8', + 'int16', + 'int32', + 'int64', + 'uint8', + 'uint16', + 'uint32', + 'uint64', + 'size', + 'bool'}: + scalar =3D True + if isinstance(element_type, QAPISchemaEnumType): + scalar =3D True + + self._gen.add(mcgen(''' +%(cfg)s +mod %(mod)s_module { + use super::*; + + vec_type!(%(rs)s, %(ffi)s, qapi_free_%(name)s, %(scalar)i); +} + +%(cfg)s +pub use %(mod)s_module::*; +''', + cfg=3Difcond.rsgen(), + name=3Drs_name(name, protect=3DFalse), + mod=3Drs_name(name).lower(), + ffi=3Drs_name(name), + rs=3Dtyp, + scalar=3Dscalar)) + + def visit_object_type(self, + name: str, + info: Optional[QAPISourceInfo], + ifcond: QAPISchemaIfCond, + features: List[QAPISchemaFeature], + base: Optional[QAPISchemaObjectType], + members: List[QAPISchemaObjectTypeMember], + variants: Optional[QAPISchemaVariants]) -> None: + if name.startswith('q_'): + return + self._gen.add(gen_rs_object(name, ifcond, base, members, variants)) + + def visit_enum_type(self, + name: str, + info: Optional[QAPISourceInfo], + ifcond: QAPISchemaIfCond, + features: List[QAPISchemaFeature], + members: List[QAPISchemaEnumMember], + prefix: Optional[str]) -> None: + self._gen.add(gen_rs_enum(name, ifcond)) + + def visit_alternate_type(self, + name: str, + info: QAPISourceInfo, + ifcond: QAPISchemaIfCond, + features: List[QAPISchemaFeature], + variants: QAPISchemaVariants) -> None: + self._gen.add(gen_rs_alternate(name, ifcond, variants)) + + +def gen_rs_types(schema: QAPISchema, output_dir: str, prefix: str) -> None: + vis =3D QAPISchemaGenRsTypeVisitor(prefix) + schema.visit(vis) + vis.write(output_dir) --=20 2.33.0.113.g6c40894d24 From nobody Tue May 7 11:02:16 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631018226610581.6588007239262; Tue, 7 Sep 2021 05:37:06 -0700 (PDT) Received: from localhost ([::1]:35720 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNaLZ-0003oF-Fj for importer@patchew.org; Tue, 07 Sep 2021 08:37:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43062) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNa9i-0007S3-TL for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:24:54 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:33733) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNa9Z-0008H2-52 for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:24:46 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-423-jX6zQ6ENMtiyeZGmy8fXRA-1; Tue, 07 Sep 2021 08:24:35 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7C222107ACC7 for ; Tue, 7 Sep 2021 12:24:34 +0000 (UTC) Received: from localhost (unknown [10.39.208.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id C3E6460657; Tue, 7 Sep 2021 12:24:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631017480; 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=gk4x+XbLHcqFfUpeSw0A0MHUBHJf0doVmVjshzimK5w=; b=IxXjzvvEG6D6aHIL1Fkrr77x7wW5h73NnB+X6UcE/gZawbESfy7isudeZeddMEBCKcRnCU ntrjBIoQg42zI13oR9xx3BhCmSFLzNUYvSSnU4a4URJ+Vvm2jOcqCQ67OKRQZtmjtWppkP dvmZhCLPRL9Ni1h/ZbDXi+T+heE7e7I= X-MC-Unique: jX6zQ6ENMtiyeZGmy8fXRA-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [RFC v3 21/32] tests/rust: build a common library, checking bindings compile Date: Tue, 7 Sep 2021 16:19:32 +0400 Message-Id: <20210907121943.3498701-22-marcandre.lureau@redhat.com> In-Reply-To: <20210907121943.3498701-1-marcandre.lureau@redhat.com> References: <20210907121943.3498701-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=marcandre.lureau@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, berrange@redhat.com, armbru@redhat.com, stefanha@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631018227321100001 From: Marc-Andr=C3=A9 Lureau Meson doesn't integrate very smoothly with Cargo. Use the cargo-wrapper script as a custom_target() always stale to build the Rust code. The "build-lib" command will produce a static library in the meson expected output directory, as well as link flags that must be employed to do the final link. Those link flags can't be queried during configure time (Cargo doesn't have a user-queriable configure step), so we pass them to the linker thanks to @file argument support at build time. Signed-off-by: Marc-Andr=C3=A9 Lureau --- tests/Cargo.toml | 4 ++++ tests/lib.rs | 2 ++ tests/meson.build | 20 +++++++++++++++++++- tests/qapi.rs | 11 +++++++++++ 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 tests/lib.rs create mode 100644 tests/qapi.rs diff --git a/tests/Cargo.toml b/tests/Cargo.toml index 7a4f6060b1..8a014dff89 100644 --- a/tests/Cargo.toml +++ b/tests/Cargo.toml @@ -7,6 +7,10 @@ publish =3D false [dependencies] common =3D { path =3D "../rust/common" } =20 +[lib] +path =3D "lib.rs" +crate-type =3D ["staticlib"] + [[bin]] name =3D "qapi-cabi-rs" path =3D "qapi-cabi.rs" diff --git a/tests/lib.rs b/tests/lib.rs new file mode 100644 index 0000000000..e6fdf60a55 --- /dev/null +++ b/tests/lib.rs @@ -0,0 +1,2 @@ +mod qapi_ffi; +mod qapi; diff --git a/tests/meson.build b/tests/meson.build index f9af42caba..09aa2bdf55 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -45,7 +45,10 @@ test_qapi_files =3D custom_target('Test QAPI files', depend_files: qapi_gen_depends) =20 if with_rust - test_qapi_rs_outputs =3D ['test-qapi-ffi-types.rs'] + test_qapi_rs_outputs =3D [ + 'test-qapi-ffi-types.rs', + 'test-qapi-types.rs', + ] test_qapi_rs =3D custom_target('Test QAPI Rust binding', output: test_qapi_rs_outputs, input: test_qapi_inputs, @@ -65,6 +68,21 @@ if with_rust 'build-bin', 'qapi-cabi-rs', '--', '--cfg', 'QAPI_CABI']) + libtest_rs =3D custom_target('Test Rust library', + build_by_default: true, + output: ['libqemu_tests.args', 'libqemu_tests= .a'], + build_always_stale: true, + depends: [test_qapi_rs], + command: [cargo_wrapper, + meson.current_build_dir(), + meson.current_source_dir(), + meson.build_root(), + rs_build_type, + rust_target_triple, + 'build-lib']) + libtest_rs =3D declare_dependency( + link_args: '@' + libtest_rs[0].full_path(), + sources: libtest_rs) endif =20 # meson doesn't like generated output in other directories diff --git a/tests/qapi.rs b/tests/qapi.rs new file mode 100644 index 0000000000..93e3e714e7 --- /dev/null +++ b/tests/qapi.rs @@ -0,0 +1,11 @@ +#![allow(dead_code)] +#![allow(non_camel_case_types)] + +use common::*; + +new_ptr!(); + +include!(concat!( + env!("MESON_BUILD_ROOT"), + "/tests/test-qapi-types.rs" +)); --=20 2.33.0.113.g6c40894d24 From nobody Tue May 7 11:02:16 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631019227962854.9694845161202; Tue, 7 Sep 2021 05:53:47 -0700 (PDT) Received: from localhost ([::1]:40372 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNabi-0001Yq-TH for importer@patchew.org; Tue, 07 Sep 2021 08:53:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43066) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNa9j-0007S5-HD for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:24:55 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:60618) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNa9a-0008Hi-M5 for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:24:46 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-43-hHf4MAIyNg-O-71yyivfYg-1; Tue, 07 Sep 2021 08:24:40 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CBF641006C85 for ; Tue, 7 Sep 2021 12:24:39 +0000 (UTC) Received: from localhost (unknown [10.39.208.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id 95D4860657; Tue, 7 Sep 2021 12:24:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631017481; 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=ZGt+B4w/EtTevt91wzwwGAAD7XdUTOF5gSRxxJjaZWs=; b=SoSE/6job9rnT0Hlmh+eMk7lz4t78KkRYiQo9rs9AEAWMfp1OgKQ7Dfz/ApiEnfuQzDNfu Hj6oWo8DV0Ok6j3Lo0TqSaV+yDpj4U4ACFfNxlwSZRZ1zyFpHeTwBe0/Q5mgdb/rZRgKbc 4t9/Th7XOngmASwqbTkuDnBjzRN10EA= X-MC-Unique: hHf4MAIyNg-O-71yyivfYg-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [RFC v3 22/32] qga: build qapi-cabi binary (ABI from C) Date: Tue, 7 Sep 2021 16:19:33 +0400 Message-Id: <20210907121943.3498701-23-marcandre.lureau@redhat.com> In-Reply-To: <20210907121943.3498701-1-marcandre.lureau@redhat.com> References: <20210907121943.3498701-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=marcandre.lureau@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, berrange@redhat.com, armbru@redhat.com, stefanha@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631019228393100001 From: Marc-Andr=C3=A9 Lureau Build a binary to dump the QAPI ABI (from C code). Ex: $ qga/qapi-cabi GuestAgentCommandInfo struct: sizeof=3D16 name member: sizeof=3D8 offset=3D0 enabled member: sizeof=3D1 offset=3D8 success_response member: sizeof=3D1 offset=3D9 ... Signed-off-by: Marc-Andr=C3=A9 Lureau --- qga/qapi-cabi.c | 9 +++++++++ qga/meson.build | 12 ++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 qga/qapi-cabi.c diff --git a/qga/qapi-cabi.c b/qga/qapi-cabi.c new file mode 100644 index 0000000000..0704e70869 --- /dev/null +++ b/qga/qapi-cabi.c @@ -0,0 +1,9 @@ +#include "qemu/osdep.h" + +#include "qga-qapi-types.h" + +int main(int argc, const char *argv[]) +{ + qapi_cabi(); + return 0; +} diff --git a/qga/meson.build b/qga/meson.build index cfb1fbc085..1b050d8c53 100644 --- a/qga/meson.build +++ b/qga/meson.build @@ -21,6 +21,18 @@ qga_qapi_files =3D custom_target('QGA QAPI files', command: [ qapi_gen, '-o', 'qga', '-p', 'qg= a-', '@INPUT0@' ], depend_files: qapi_gen_depends) =20 +i =3D 0 +srcs =3D [files('qapi-cabi.c')] +foreach output: qga_qapi_outputs + if output.startswith('qga-qapi-types') or output.startswith('qga-qapi-vi= sit') + srcs +=3D qga_qapi_files[i] + endif + i +=3D 1 +endforeach +qga_qapi_cabi =3D executable('qapi-cabi', srcs, + dependencies: [qemuutil], + c_args: ['-DQAPI_CABI']) + qga_ss =3D ss.source_set() qga_ss.add(qga_qapi_files.to_list()) qga_ss.add(files( --=20 2.33.0.113.g6c40894d24 From nobody Tue May 7 11:02:16 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631019570808785.8606084519478; Tue, 7 Sep 2021 05:59:30 -0700 (PDT) Received: from localhost ([::1]:56642 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNahF-0004Oz-NB for importer@patchew.org; Tue, 07 Sep 2021 08:59:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43128) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNa9s-0007VK-TM for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:25:03 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:23755) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNa9o-0008Ky-1W for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:25:00 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-538-n3ZDuuajOXijXA5gQcKA-w-1; Tue, 07 Sep 2021 08:24:50 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 14FCF107ACE4 for ; Tue, 7 Sep 2021 12:24:50 +0000 (UTC) Received: from localhost (unknown [10.39.208.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9EF1D1972D; Tue, 7 Sep 2021 12:24:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631017494; 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=9791jZ10f+guLwmYZ4PgfVHbEm9I+Y2Hi55Pr1OZiLA=; b=edR5y4+XGySs3FMR92/eJfVGQWRA+WckSZquUSYC7XFgsTvCNoBq9EwQqkdTeOAOjY3ugi eQPPT38YGMU2+a8tCkplMMVcK1ZJ7kQvIsoHisxIJypBquD0kkMCgoxIqAiev3ASxDT9lw pISD79egXVfwydnJLhHr45UtmUv3ZMY= X-MC-Unique: n3ZDuuajOXijXA5gQcKA-w-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [RFC v3 23/32] qga/rust: build and link an empty static library Date: Tue, 7 Sep 2021 16:19:34 +0400 Message-Id: <20210907121943.3498701-24-marcandre.lureau@redhat.com> In-Reply-To: <20210907121943.3498701-1-marcandre.lureau@redhat.com> References: <20210907121943.3498701-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=marcandre.lureau@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_PASS=-0.001, T_SPF_HELO_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, berrange@redhat.com, armbru@redhat.com, stefanha@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631019571384100001 From: Marc-Andr=C3=A9 Lureau Signed-off-by: Marc-Andr=C3=A9 Lureau --- Cargo.lock | 4 ++++ Cargo.toml | 1 + qga/Cargo.toml | 9 +++++++++ qga/lib.rs | 0 qga/meson.build | 20 +++++++++++++++++++- 5 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 qga/Cargo.toml create mode 100644 qga/lib.rs diff --git a/Cargo.lock b/Cargo.lock index f2cd0ee96e..2f5b202605 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -68,3 +68,7 @@ version =3D "0.0.1" dependencies =3D [ "common", ] + +[[package]] +name =3D "qga" +version =3D "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index f4a078e62d..3db0646413 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,6 @@ [workspace] members =3D [ + "qga", "rust/common", "tests", ] diff --git a/qga/Cargo.toml b/qga/Cargo.toml new file mode 100644 index 0000000000..a3bffd1fec --- /dev/null +++ b/qga/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name =3D "qga" +version =3D "0.1.0" +edition =3D "2018" +publish =3D false + +[lib] +path =3D "lib.rs" +crate-type =3D ["staticlib"] diff --git a/qga/lib.rs b/qga/lib.rs new file mode 100644 index 0000000000..e69de29bb2 diff --git a/qga/meson.build b/qga/meson.build index 1b050d8c53..d272892ced 100644 --- a/qga/meson.build +++ b/qga/meson.build @@ -54,9 +54,27 @@ qga_ss.add(when: 'CONFIG_WIN32', if_true: files( =20 qga_ss =3D qga_ss.apply(config_host, strict: false) =20 +qga_rs =3D declare_dependency() +if with_rust + cargo_qga =3D custom_target('cargo-qga', + build_by_default: true, + output: ['libqga.args', 'libqga.a'], + build_always_stale: true, + command: [cargo_wrapper, + meson.current_build_dir(), + meson.current_source_dir(), + meson.build_root(), + rs_build_type, + rust_target_triple, + 'build-lib']) + qga_rs =3D declare_dependency( + link_args: '@' + cargo_qga[0].full_path(), + sources: cargo_qga) +endif + qga =3D executable('qemu-ga', qga_ss.sources(), link_args: config_host['LIBS_QGA'].split(), - dependencies: [qemuutil, libudev], + dependencies: [qemuutil, libudev, qga_rs], install: true) all_qga =3D [qga] =20 --=20 2.33.0.113.g6c40894d24 From nobody Tue May 7 11:02:16 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631018980419662.1719898077804; Tue, 7 Sep 2021 05:49:40 -0700 (PDT) Received: from localhost ([::1]:58990 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNaXi-0003Gu-Sh for importer@patchew.org; Tue, 07 Sep 2021 08:49:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43176) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNaA3-0007Yv-8S for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:25:13 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:21909) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNa9z-0008O6-2S for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:25:10 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-15-YvYcT9rvPneGZowcM3LXyQ-1; Tue, 07 Sep 2021 08:25:03 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F04BA84A5E0 for ; Tue, 7 Sep 2021 12:25:02 +0000 (UTC) Received: from localhost (unknown [10.39.208.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5E90377701; Tue, 7 Sep 2021 12:24:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631017506; 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=RKPtpOZMSLrfi3J3GNueFxhqe6Xhi8tG3kmnxuyuDJo=; b=CjES8Tju0jEUIzEJjQWd6gLB8mDO1P+SbMdcuMGVlpHqwR3XJrqMucTWn7ug+CHWR2zUkh nmrtW7HpC76zFSKO8Hinn4Wwb30QlVIEh0smFe/M+JtB9sWqLdewffB9y4yTZClHmJvijM 5925fYiNsrA8wbPUVnL+08oH7HrEZTU= X-MC-Unique: YvYcT9rvPneGZowcM3LXyQ-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [RFC v3 24/32] qga/rust: generate QGA QAPI types FFI bindings Date: Tue, 7 Sep 2021 16:19:35 +0400 Message-Id: <20210907121943.3498701-25-marcandre.lureau@redhat.com> In-Reply-To: <20210907121943.3498701-1-marcandre.lureau@redhat.com> References: <20210907121943.3498701-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=marcandre.lureau@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, berrange@redhat.com, armbru@redhat.com, stefanha@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631018982097100001 From: Marc-Andr=C3=A9 Lureau Use qapi-gen to generate low-level C FFI bindings for QAPI types, include them to the build. Signed-off-by: Marc-Andr=C3=A9 Lureau --- Cargo.lock | 3 +++ qga/Cargo.toml | 3 +++ qga/lib.rs | 1 + qga/meson.build | 11 +++++++++++ qga/qapi_ffi.rs | 8 ++++++++ 5 files changed, 26 insertions(+) create mode 100644 qga/qapi_ffi.rs diff --git a/Cargo.lock b/Cargo.lock index 2f5b202605..ad5bb47762 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -72,3 +72,6 @@ dependencies =3D [ [[package]] name =3D "qga" version =3D "0.1.0" +dependencies =3D [ + "common", +] diff --git a/qga/Cargo.toml b/qga/Cargo.toml index a3bffd1fec..807acc947e 100644 --- a/qga/Cargo.toml +++ b/qga/Cargo.toml @@ -4,6 +4,9 @@ version =3D "0.1.0" edition =3D "2018" publish =3D false =20 +[dependencies] +common =3D { path =3D "../rust/common" } + [lib] path =3D "lib.rs" crate-type =3D ["staticlib"] diff --git a/qga/lib.rs b/qga/lib.rs index e69de29bb2..17cf43a5e9 100644 --- a/qga/lib.rs +++ b/qga/lib.rs @@ -0,0 +1 @@ +mod qapi_ffi; diff --git a/qga/meson.build b/qga/meson.build index d272892ced..88d59bef0c 100644 --- a/qga/meson.build +++ b/qga/meson.build @@ -56,10 +56,21 @@ qga_ss =3D qga_ss.apply(config_host, strict: false) =20 qga_rs =3D declare_dependency() if with_rust + qga_qapi_rs_outputs =3D [ + 'qga-qapi-ffi-types.rs', + ] + + qapi_gen_rs_files =3D custom_target('QGA QAPI Rust bindings', + output: qga_qapi_rs_outputs, + input: 'qapi-schema.json', + command: [ qapi_gen, '-r', '-o', 'qga'= , '-p', 'qga-', '@INPUT0@' ], + depend_files: qapi_gen_depends) + cargo_qga =3D custom_target('cargo-qga', build_by_default: true, output: ['libqga.args', 'libqga.a'], build_always_stale: true, + depends: [qapi_gen_rs_files], command: [cargo_wrapper, meson.current_build_dir(), meson.current_source_dir(), diff --git a/qga/qapi_ffi.rs b/qga/qapi_ffi.rs new file mode 100644 index 0000000000..1f4ade9318 --- /dev/null +++ b/qga/qapi_ffi.rs @@ -0,0 +1,8 @@ +#![allow(dead_code)] + +use common::libc; + +include!(concat!( + env!("MESON_BUILD_ROOT"), + "/qga/qga-qapi-ffi-types.rs" +)); --=20 2.33.0.113.g6c40894d24 From nobody Tue May 7 11:02:16 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631019825538137.33842837911095; Tue, 7 Sep 2021 06:03:45 -0700 (PDT) Received: from localhost ([::1]:36742 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNalM-0001pY-Bm for importer@patchew.org; Tue, 07 Sep 2021 09:03:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43332) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNaAT-0008Fo-6b for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:25:37 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:52323) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNaAQ-00006t-IH for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:25:36 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-558-fhDCwfTEPVmXqur3MZMfuw-1; Tue, 07 Sep 2021 08:25:32 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 28D24835DE0 for ; Tue, 7 Sep 2021 12:25:32 +0000 (UTC) Received: from localhost (unknown [10.39.208.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5C39A5D9DE; Tue, 7 Sep 2021 12:25:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631017534; 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=89LlslZG8FOzbo9cnS9vGM+7j7JqNGCajUpflvHBaoE=; b=isfkG+hS876lNcH2EdEmIFwPKA9GiFYvuERNXjKbiiLCAQyjp1MkNusvSZejpw8pDOQ7UQ JhNuJ7OHkew5uNKN6GQHlBR7PyooMkZpCZMt9clfY5d9Dpqanty0+udtysJcP/GmHxWilt hXyFYI+2giCN+l0kFVpfT0X7i5W1DE4= X-MC-Unique: fhDCwfTEPVmXqur3MZMfuw-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [RFC v3 25/32] qga/rust: build a qga-cabi-rs executable (ABI from Rust) Date: Tue, 7 Sep 2021 16:19:36 +0400 Message-Id: <20210907121943.3498701-26-marcandre.lureau@redhat.com> In-Reply-To: <20210907121943.3498701-1-marcandre.lureau@redhat.com> References: <20210907121943.3498701-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=marcandre.lureau@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, berrange@redhat.com, armbru@redhat.com, stefanha@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631019826302100001 From: Marc-Andr=C3=A9 Lureau Signed-off-by: Marc-Andr=C3=A9 Lureau --- qga/Cargo.toml | 5 +++++ qga/meson.build | 15 +++++++++++++++ qga/qapi-cabi.rs | 6 ++++++ 3 files changed, 26 insertions(+) create mode 100644 qga/qapi-cabi.rs diff --git a/qga/Cargo.toml b/qga/Cargo.toml index 807acc947e..d262b847fa 100644 --- a/qga/Cargo.toml +++ b/qga/Cargo.toml @@ -10,3 +10,8 @@ common =3D { path =3D "../rust/common" } [lib] path =3D "lib.rs" crate-type =3D ["staticlib"] + +[[bin]] +name =3D "qapi-cabi-rs" +path =3D "qapi-cabi.rs" +doc =3D false diff --git a/qga/meson.build b/qga/meson.build index 88d59bef0c..fd840f5c73 100644 --- a/qga/meson.build +++ b/qga/meson.build @@ -81,6 +81,21 @@ if with_rust qga_rs =3D declare_dependency( link_args: '@' + cargo_qga[0].full_path(), sources: cargo_qga) + + cargo_qga_cabi =3D custom_target('qga-qapi-cabi-rs', + output: ['qapi-cabi-rs' + exe_suffix], + build_always_stale: true, + depends: [qapi_gen_rs_files], + command: [cargo_wrapper, + meson.current_build_dir(), + meson.current_source_dir(), + meson.build_root(), + rs_build_type, + rust_target_triple, + 'build-bin', + 'qapi-cabi-rs', + '--', '--cfg', 'QAPI_CABI']) + endif =20 qga =3D executable('qemu-ga', qga_ss.sources(), diff --git a/qga/qapi-cabi.rs b/qga/qapi-cabi.rs new file mode 100644 index 0000000000..d98a819ef7 --- /dev/null +++ b/qga/qapi-cabi.rs @@ -0,0 +1,6 @@ +pub use common::{err, Error, Result}; +mod qapi_ffi; + +fn main() { + qapi_ffi::cabi() +} --=20 2.33.0.113.g6c40894d24 From nobody Tue May 7 11:02:16 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631018516493225.09093537078024; Tue, 7 Sep 2021 05:41:56 -0700 (PDT) Received: from localhost ([::1]:47196 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNaQF-0003J9-9K for importer@patchew.org; Tue, 07 Sep 2021 08:41:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43364) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNaAf-0000DY-13 for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:25:49 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:39605) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNaAd-0000Ax-J4 for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:25:48 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-318-c5z-wWgcOx-MaXSjRkIz3w-1; Tue, 07 Sep 2021 08:25:46 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4F040194092C for ; Tue, 7 Sep 2021 12:25:45 +0000 (UTC) Received: from localhost (unknown [10.39.208.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3AE6B68D7A; Tue, 7 Sep 2021 12:25:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631017547; 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=VDwZXCjEM5XnH20/7boa1NK72U/Rb4QIQRCe6M3ph1g=; b=bZ864QX5yTWPq4lb6r5Qf/zgw61rpAGzr9D2e9voe2QSMQOfjVaLPFnvaQ+jJ/fW5cxhTF 0cRMqMXl/DB2ckfEGNvgbQ4mPx4jVVlpn1Zho6kU4eDZhPREY0iRg0rpttDf4HKCZcUEoi dU6I/1YcuXAWld+vqeekCA0ong+X61A= X-MC-Unique: c5z-wWgcOx-MaXSjRkIz3w-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [RFC v3 26/32] qga/rust: check the Rust C binding Date: Tue, 7 Sep 2021 16:19:37 +0400 Message-Id: <20210907121943.3498701-27-marcandre.lureau@redhat.com> In-Reply-To: <20210907121943.3498701-1-marcandre.lureau@redhat.com> References: <20210907121943.3498701-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=marcandre.lureau@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, berrange@redhat.com, armbru@redhat.com, stefanha@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631018518301100001 From: Marc-Andr=C3=A9 Lureau Compare the matching C and the Rust C ABI FFI dumps. Signed-off-by: Marc-Andr=C3=A9 Lureau --- qga/meson.build | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/qga/meson.build b/qga/meson.build index fd840f5c73..f2064c1874 100644 --- a/qga/meson.build +++ b/qga/meson.build @@ -96,6 +96,11 @@ if with_rust 'qapi-cabi-rs', '--', '--cfg', 'QAPI_CABI']) =20 + test('QGA CABI', + diff_commands, + args: [qga_qapi_cabi.full_path(), cargo_qga_cabi.full_path()], + depends: [qga_qapi_cabi, cargo_qga_cabi], + suite: ['qga']) endif =20 qga =3D executable('qemu-ga', qga_ss.sources(), --=20 2.33.0.113.g6c40894d24 From nobody Tue May 7 11:02:16 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631018837917658.2684935076987; Tue, 7 Sep 2021 05:47:17 -0700 (PDT) Received: from localhost ([::1]:55742 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNaVQ-0000sl-Hz for importer@patchew.org; Tue, 07 Sep 2021 08:47:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43408) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNaAt-0000JX-Ec for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:26:04 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:56740) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNaAr-0000Jp-Ru for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:26:03 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-557-7yy-U3vFM0SkPpKHajt3_Q-1; Tue, 07 Sep 2021 08:25:58 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EBC321940931 for ; Tue, 7 Sep 2021 12:25:57 +0000 (UTC) Received: from localhost (unknown [10.39.208.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id 756F21B46B; Tue, 7 Sep 2021 12:25:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631017561; 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=Mdv3b2msb03EqP0PY7CD7P4L1hhwmn0WvmDdViJ4O/8=; b=O+TztxIRxb7QJwjawMwZukKj6CstMSJejGWekt1rAwentIbpkiC/LGe7mwZVu/BGacbsWH 9ApSqZFEhOS8q1r09FW4V+f2N8ZhCsGgU5RYyZV5yqsp+O9KICecjTIvEI+VHdbscpaeIC o95jDqsteoHDxwNNe6LtZFjZ8p80xO4= X-MC-Unique: 7yy-U3vFM0SkPpKHajt3_Q-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [RFC v3 27/32] qga/rust: build high-level Rust QAPI types Date: Tue, 7 Sep 2021 16:19:38 +0400 Message-Id: <20210907121943.3498701-28-marcandre.lureau@redhat.com> In-Reply-To: <20210907121943.3498701-1-marcandre.lureau@redhat.com> References: <20210907121943.3498701-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=marcandre.lureau@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, berrange@redhat.com, armbru@redhat.com, stefanha@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631018840138100001 From: Marc-Andr=C3=A9 Lureau Signed-off-by: Marc-Andr=C3=A9 Lureau --- qga/lib.rs | 1 + qga/meson.build | 1 + qga/qapi.rs | 6 ++++++ 3 files changed, 8 insertions(+) create mode 100644 qga/qapi.rs diff --git a/qga/lib.rs b/qga/lib.rs index 17cf43a5e9..7f62788ff6 100644 --- a/qga/lib.rs +++ b/qga/lib.rs @@ -1 +1,2 @@ +mod qapi; mod qapi_ffi; diff --git a/qga/meson.build b/qga/meson.build index f2064c1874..16775bc905 100644 --- a/qga/meson.build +++ b/qga/meson.build @@ -58,6 +58,7 @@ qga_rs =3D declare_dependency() if with_rust qga_qapi_rs_outputs =3D [ 'qga-qapi-ffi-types.rs', + 'qga-qapi-types.rs', ] =20 qapi_gen_rs_files =3D custom_target('QGA QAPI Rust bindings', diff --git a/qga/qapi.rs b/qga/qapi.rs new file mode 100644 index 0000000000..e4b9113300 --- /dev/null +++ b/qga/qapi.rs @@ -0,0 +1,6 @@ +#![allow(dead_code)] +use common::*; + +new_ptr!(); + +include!(concat!(env!("MESON_BUILD_ROOT"), "/qga/qga-qapi-types.rs")); --=20 2.33.0.113.g6c40894d24 From nobody Tue May 7 11:02:16 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 163102000404893.42299267383396; Tue, 7 Sep 2021 06:06:44 -0700 (PDT) Received: from localhost ([::1]:45036 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNaoE-0007Sv-WC for importer@patchew.org; Tue, 07 Sep 2021 09:06:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43484) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNaB3-0000Rg-Q5 for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:26:13 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:45593) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNaAx-0000Kx-CX for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:26:13 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-567-hE2zLGVJOtmbzxZ1thhw6g-1; Tue, 07 Sep 2021 08:26:04 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 39DDD101371B for ; Tue, 7 Sep 2021 12:26:03 +0000 (UTC) Received: from localhost (unknown [10.39.208.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id D3AED78433; Tue, 7 Sep 2021 12:26:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631017566; 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=hhGnKr6ZqWdteqsKevxCBVGezoJVsxx1I6b8HFCfc74=; b=adhBMWtfAyQjOP7zpxrk6EQZtMSPu4I7HjLeYp2o6aQRHtnMlXjGMdRX1cY/Zd60AwJ391 gp98/aza7boExnbjE9gNKlnsn+5wx+P8T1NuAzdH4Ma+EBFa6gJQWbqMoDCyx6bHJ41lB4 kAgd69JZdSBn59TUeguYnEGtn9ndB40= X-MC-Unique: hE2zLGVJOtmbzxZ1thhw6g-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [RFC v3 28/32] qga/rust: implement get-host-name in Rust (example) Date: Tue, 7 Sep 2021 16:19:39 +0400 Message-Id: <20210907121943.3498701-29-marcandre.lureau@redhat.com> In-Reply-To: <20210907121943.3498701-1-marcandre.lureau@redhat.com> References: <20210907121943.3498701-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=marcandre.lureau@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_PASS=-0.001, T_SPF_HELO_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, berrange@redhat.com, armbru@redhat.com, stefanha@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631020006708100001 From: Marc-Andr=C3=A9 Lureau Use the "hostname" crate (https://github.com/svartalf/hostname) (notice the wrong error message in our win32 implementation) Signed-off-by: Marc-Andr=C3=A9 Lureau --- include/qemu/osdep.h | 10 ---------- qga/commands.c | 20 ++++---------------- tests/unit/test-qga.c | 2 ++ util/oslib-posix.c | 35 ----------------------------------- util/oslib-win32.c | 13 ------------- Cargo.lock | 40 ++++++++++++++++++++++++++++++++++++++++ qga/Cargo.toml | 1 + qga/lib.rs | 3 +++ qga/qmp/hostname.rs | 9 +++++++++ qga/qmp/mod.rs | 10 ++++++++++ 10 files changed, 69 insertions(+), 74 deletions(-) create mode 100644 qga/qmp/hostname.rs create mode 100644 qga/qmp/mod.rs diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index 60718fc342..ca8f3465d2 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -740,16 +740,6 @@ static inline void qemu_reset_optind(void) #endif } =20 -/** - * qemu_get_host_name: - * @errp: Error object - * - * Operating system agnostic way of querying host name. - * - * Returns allocated hostname (caller should free), NULL on failure. - */ -char *qemu_get_host_name(Error **errp); - /** * qemu_get_host_physmem: * diff --git a/qga/commands.c b/qga/commands.c index 80501e4a73..117c219ac4 100644 --- a/qga/commands.c +++ b/qga/commands.c @@ -508,25 +508,13 @@ int ga_parse_whence(GuestFileWhence *whence, Error **= errp) return -1; } =20 +#ifndef CONFIG_WITH_RUST GuestHostName *qmp_guest_get_host_name(Error **errp) { - GuestHostName *result =3D NULL; - g_autofree char *hostname =3D qemu_get_host_name(errp); - - /* - * We want to avoid using g_get_host_name() because that - * caches the result and we wouldn't reflect changes in the - * host name. - */ - - if (!hostname) { - hostname =3D g_strdup("localhost"); - } - - result =3D g_new0(GuestHostName, 1); - result->host_name =3D g_steal_pointer(&hostname); - return result; + error_setg(errp, QERR_UNSUPPORTED); + return NULL; } +#endif =20 GuestTimezone *qmp_guest_get_timezone(Error **errp) { diff --git a/tests/unit/test-qga.c b/tests/unit/test-qga.c index 5cb140d1b5..a22ab8c82c 100644 --- a/tests/unit/test-qga.c +++ b/tests/unit/test-qga.c @@ -864,6 +864,7 @@ static void test_qga_guest_exec_invalid(gconstpointer f= ix) =20 static void test_qga_guest_get_host_name(gconstpointer fix) { +#ifdef CONFIG_WITH_RUST const TestFixture *fixture =3D fix; QDict *ret, *val; =20 @@ -875,6 +876,7 @@ static void test_qga_guest_get_host_name(gconstpointer = fix) g_assert(qdict_haskey(val, "host-name")); =20 qobject_unref(ret); +#endif } =20 static void test_qga_guest_get_timezone(gconstpointer fix) diff --git a/util/oslib-posix.c b/util/oslib-posix.c index e8bdb02e1d..1498e0b7f5 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -809,41 +809,6 @@ void sigaction_invoke(struct sigaction *action, action->sa_sigaction(info->ssi_signo, &si, NULL); } =20 -#ifndef HOST_NAME_MAX -# ifdef _POSIX_HOST_NAME_MAX -# define HOST_NAME_MAX _POSIX_HOST_NAME_MAX -# else -# define HOST_NAME_MAX 255 -# endif -#endif - -char *qemu_get_host_name(Error **errp) -{ - long len =3D -1; - g_autofree char *hostname =3D NULL; - -#ifdef _SC_HOST_NAME_MAX - len =3D sysconf(_SC_HOST_NAME_MAX); -#endif /* _SC_HOST_NAME_MAX */ - - if (len < 0) { - len =3D HOST_NAME_MAX; - } - - /* Unfortunately, gethostname() below does not guarantee a - * NULL terminated string. Therefore, allocate one byte more - * to be sure. */ - hostname =3D g_new0(char, len + 1); - - if (gethostname(hostname, len) < 0) { - error_setg_errno(errp, errno, - "cannot get hostname"); - return NULL; - } - - return g_steal_pointer(&hostname); -} - size_t qemu_get_host_physmem(void) { #ifdef _SC_PHYS_PAGES diff --git a/util/oslib-win32.c b/util/oslib-win32.c index af559ef339..575f697815 100644 --- a/util/oslib-win32.c +++ b/util/oslib-win32.c @@ -629,19 +629,6 @@ bool qemu_write_pidfile(const char *filename, Error **= errp) return true; } =20 -char *qemu_get_host_name(Error **errp) -{ - wchar_t tmp[MAX_COMPUTERNAME_LENGTH + 1]; - DWORD size =3D G_N_ELEMENTS(tmp); - - if (GetComputerNameW(tmp, &size) =3D=3D 0) { - error_setg_win32(errp, GetLastError(), "failed close handle"); - return NULL; - } - - return g_utf16_to_utf8(tmp, size, NULL, NULL, NULL); -} - size_t qemu_get_host_physmem(void) { MEMORYSTATUSEX statex; diff --git a/Cargo.lock b/Cargo.lock index ad5bb47762..8752dbf2ac 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -34,12 +34,29 @@ dependencies =3D [ "nix", ] =20 +[[package]] +name =3D "hostname" +version =3D "0.3.1" +source =3D "registry+https://github.com/rust-lang/crates.io-index" +checksum =3D "3c731c3e10504cc8ed35cfe2f1db4c9274c3d35fa486e3b31df46f068ef3= e867" +dependencies =3D [ + "libc", + "match_cfg", + "winapi", +] + [[package]] name =3D "libc" version =3D "0.2.101" source =3D "registry+https://github.com/rust-lang/crates.io-index" checksum =3D "3cb00336871be5ed2c8ed44b60ae9959dc5b9f08539422ed43f09e34ecae= ba21" =20 +[[package]] +name =3D "match_cfg" +version =3D "0.1.0" +source =3D "registry+https://github.com/rust-lang/crates.io-index" +checksum =3D "ffbee8634e0d45d258acb448e7eaab3fce7a0a467395d4d9f228e3c1f01f= b2e4" + [[package]] name =3D "memoffset" version =3D "0.6.4" @@ -74,4 +91,27 @@ name =3D "qga" version =3D "0.1.0" dependencies =3D [ "common", + "hostname", ] + +[[package]] +name =3D "winapi" +version =3D "0.3.9" +source =3D "registry+https://github.com/rust-lang/crates.io-index" +checksum =3D "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00= f419" +dependencies =3D [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name =3D "winapi-i686-pc-windows-gnu" +version =3D "0.4.0" +source =3D "registry+https://github.com/rust-lang/crates.io-index" +checksum =3D "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51= b7b6" + +[[package]] +name =3D "winapi-x86_64-pc-windows-gnu" +version =3D "0.4.0" +source =3D "registry+https://github.com/rust-lang/crates.io-index" +checksum =3D "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931= 183f" diff --git a/qga/Cargo.toml b/qga/Cargo.toml index d262b847fa..387af59a30 100644 --- a/qga/Cargo.toml +++ b/qga/Cargo.toml @@ -6,6 +6,7 @@ publish =3D false =20 [dependencies] common =3D { path =3D "../rust/common" } +hostname =3D "0.3.1" =20 [lib] path =3D "lib.rs" diff --git a/qga/lib.rs b/qga/lib.rs index 7f62788ff6..e51e211006 100644 --- a/qga/lib.rs +++ b/qga/lib.rs @@ -1,2 +1,5 @@ +pub use common::{err, libc, Error, Result}; + mod qapi; mod qapi_ffi; +mod qmp; diff --git a/qga/qmp/hostname.rs b/qga/qmp/hostname.rs new file mode 100644 index 0000000000..c3eb1f6fd2 --- /dev/null +++ b/qga/qmp/hostname.rs @@ -0,0 +1,9 @@ +use crate::*; + +pub(crate) fn get() -> Result { + let host_name =3D hostname::get()? + .into_string() + .or_else(|_| err!("Invalid hostname"))?; + + Ok(qapi::GuestHostName { host_name }) +} diff --git a/qga/qmp/mod.rs b/qga/qmp/mod.rs new file mode 100644 index 0000000000..c192e4247d --- /dev/null +++ b/qga/qmp/mod.rs @@ -0,0 +1,10 @@ +use common::*; + +use crate::qapi_ffi; + +mod hostname; + +#[no_mangle] +extern "C" fn qmp_guest_get_host_name(errp: *mut *mut ffi::Error) -> *mut = qapi_ffi::GuestHostName { + qmp!(hostname::get(), errp) +} --=20 2.33.0.113.g6c40894d24 From nobody Tue May 7 11:02:16 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631019193323151.5069088964077; Tue, 7 Sep 2021 05:53:13 -0700 (PDT) Received: from localhost ([::1]:39354 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNabA-0000sZ-79 for importer@patchew.org; Tue, 07 Sep 2021 08:53:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43496) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNaB7-0000Vr-H1 for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:26:17 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:53033) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNaB3-0000NV-D6 for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:26:15 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-153-YygMETnKNgmpWIhQSIV8aQ-1; Tue, 07 Sep 2021 08:26:10 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 94B886F303 for ; Tue, 7 Sep 2021 12:26:09 +0000 (UTC) Received: from localhost (unknown [10.39.208.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id BECF61B46B; Tue, 7 Sep 2021 12:26:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631017572; 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=xDSOvQHHwljQVtxLeHxQnkkpRBmp5a4O7Ndy4k1bOLs=; b=VWsZY0HfEFTeiy3rrdH32QnFjLKEZ3dvKG30hnSY4SlbB8tkWkBfBbXL4PMZoFPjFUWJlR X8Zf8LdVYVnHEgMBd6cpP/BQ6hCRn2Ott11e6ar3+iSwLxMYoBgaOVxbRDvCEPrQBleJtP WNHOiv+ZxDCev6prNmbp+EIel/GKO20= X-MC-Unique: YygMETnKNgmpWIhQSIV8aQ-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [RFC v3 29/32] qga/rust: implement {get,set}-vcpus in Rust (example) Date: Tue, 7 Sep 2021 16:19:40 +0400 Message-Id: <20210907121943.3498701-30-marcandre.lureau@redhat.com> In-Reply-To: <20210907121943.3498701-1-marcandre.lureau@redhat.com> References: <20210907121943.3498701-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=marcandre.lureau@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -11 X-Spam_score: -1.2 X-Spam_bar: - X-Spam_report: (-1.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_OTHER_BAD_TLD=1.999, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, berrange@redhat.com, armbru@redhat.com, stefanha@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631019195244100001 From: Marc-Andr=C3=A9 Lureau This is a rewrite of the C version (using the nix & winapi crates). The main difference is that Rust doesn't let you mix const/mut logic, the way transfer_vcpu in C does. The Rust version does introduce some duplication, but is also more strict and can prevent mistakes. Signed-off-by: Marc-Andr=C3=A9 Lureau --- qga/commands-posix.c | 152 --------------------------------------- qga/commands-win32.c | 71 ------------------- qga/commands.c | 14 ++++ tests/unit/test-qga.c | 2 + Cargo.lock | 2 + qga/Cargo.toml | 6 ++ qga/qmp/mod.rs | 20 +++++- qga/qmp/vcpus.rs | 161 ++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 204 insertions(+), 224 deletions(-) create mode 100644 qga/qmp/vcpus.rs diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 75dbaab68e..97ca70e762 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -2371,146 +2371,6 @@ error: return NULL; } =20 -/* Transfer online/offline status between @vcpu and the guest system. - * - * On input either @errp or *@errp must be NULL. - * - * In system-to-@vcpu direction, the following @vcpu fields are accessed: - * - R: vcpu->logical_id - * - W: vcpu->online - * - W: vcpu->can_offline - * - * In @vcpu-to-system direction, the following @vcpu fields are accessed: - * - R: vcpu->logical_id - * - R: vcpu->online - * - * Written members remain unmodified on error. - */ -static void transfer_vcpu(GuestLogicalProcessor *vcpu, bool sys2vcpu, - char *dirpath, Error **errp) -{ - int fd; - int res; - int dirfd; - static const char fn[] =3D "online"; - - dirfd =3D open(dirpath, O_RDONLY | O_DIRECTORY); - if (dirfd =3D=3D -1) { - error_setg_errno(errp, errno, "open(\"%s\")", dirpath); - return; - } - - fd =3D openat(dirfd, fn, sys2vcpu ? O_RDONLY : O_RDWR); - if (fd =3D=3D -1) { - if (errno !=3D ENOENT) { - error_setg_errno(errp, errno, "open(\"%s/%s\")", dirpath, fn); - } else if (sys2vcpu) { - vcpu->online =3D true; - vcpu->can_offline =3D false; - } else if (!vcpu->online) { - error_setg(errp, "logical processor #%" PRId64 " can't be " - "offlined", vcpu->logical_id); - } /* otherwise pretend successful re-onlining */ - } else { - unsigned char status; - - res =3D pread(fd, &status, 1, 0); - if (res =3D=3D -1) { - error_setg_errno(errp, errno, "pread(\"%s/%s\")", dirpath, fn); - } else if (res =3D=3D 0) { - error_setg(errp, "pread(\"%s/%s\"): unexpected EOF", dirpath, - fn); - } else if (sys2vcpu) { - vcpu->online =3D (status !=3D '0'); - vcpu->can_offline =3D true; - } else if (vcpu->online !=3D (status !=3D '0')) { - status =3D '0' + vcpu->online; - if (pwrite(fd, &status, 1, 0) =3D=3D -1) { - error_setg_errno(errp, errno, "pwrite(\"%s/%s\")", dirpath, - fn); - } - } /* otherwise pretend successful re-(on|off)-lining */ - - res =3D close(fd); - g_assert(res =3D=3D 0); - } - - res =3D close(dirfd); - g_assert(res =3D=3D 0); -} - -GuestLogicalProcessorList *qmp_guest_get_vcpus(Error **errp) -{ - GuestLogicalProcessorList *head, **tail; - const char *cpu_dir =3D "/sys/devices/system/cpu"; - const gchar *line; - g_autoptr(GDir) cpu_gdir =3D NULL; - Error *local_err =3D NULL; - - head =3D NULL; - tail =3D &head; - cpu_gdir =3D g_dir_open(cpu_dir, 0, NULL); - - if (cpu_gdir =3D=3D NULL) { - error_setg_errno(errp, errno, "failed to list entries: %s", cpu_di= r); - return NULL; - } - - while (local_err =3D=3D NULL && (line =3D g_dir_read_name(cpu_gdir)) != =3D NULL) { - GuestLogicalProcessor *vcpu; - int64_t id; - if (sscanf(line, "cpu%" PRId64, &id)) { - g_autofree char *path =3D g_strdup_printf("/sys/devices/system= /cpu/" - "cpu%" PRId64 "/", id); - vcpu =3D g_malloc0(sizeof *vcpu); - vcpu->logical_id =3D id; - vcpu->has_can_offline =3D true; /* lolspeak ftw */ - transfer_vcpu(vcpu, true, path, &local_err); - QAPI_LIST_APPEND(tail, vcpu); - } - } - - if (local_err =3D=3D NULL) { - /* there's no guest with zero VCPUs */ - g_assert(head !=3D NULL); - return head; - } - - qapi_free_GuestLogicalProcessorList(head); - error_propagate(errp, local_err); - return NULL; -} - -int64_t qmp_guest_set_vcpus(GuestLogicalProcessorList *vcpus, Error **errp) -{ - int64_t processed; - Error *local_err =3D NULL; - - processed =3D 0; - while (vcpus !=3D NULL) { - char *path =3D g_strdup_printf("/sys/devices/system/cpu/cpu%" PRId= 64 "/", - vcpus->value->logical_id); - - transfer_vcpu(vcpus->value, false, path, &local_err); - g_free(path); - if (local_err !=3D NULL) { - break; - } - ++processed; - vcpus =3D vcpus->next; - } - - if (local_err !=3D NULL) { - if (processed =3D=3D 0) { - error_propagate(errp, local_err); - } else { - error_free(local_err); - } - } - - return processed; -} - void qmp_guest_set_user_password(const char *username, const char *password, bool crypted, @@ -2946,18 +2806,6 @@ GuestNetworkInterfaceList *qmp_guest_network_get_int= erfaces(Error **errp) return NULL; } =20 -GuestLogicalProcessorList *qmp_guest_get_vcpus(Error **errp) -{ - error_setg(errp, QERR_UNSUPPORTED); - return NULL; -} - -int64_t qmp_guest_set_vcpus(GuestLogicalProcessorList *vcpus, Error **errp) -{ - error_setg(errp, QERR_UNSUPPORTED); - return -1; -} - void qmp_guest_set_user_password(const char *username, const char *password, bool crypted, diff --git a/qga/commands-win32.c b/qga/commands-win32.c index 4e84afd83b..33a3fd7218 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -1816,77 +1816,6 @@ void qmp_guest_set_time(bool has_time, int64_t time_= ns, Error **errp) } } =20 -GuestLogicalProcessorList *qmp_guest_get_vcpus(Error **errp) -{ - PSYSTEM_LOGICAL_PROCESSOR_INFORMATION pslpi, ptr; - DWORD length; - GuestLogicalProcessorList *head, **tail; - Error *local_err =3D NULL; - int64_t current; - - ptr =3D pslpi =3D NULL; - length =3D 0; - current =3D 0; - head =3D NULL; - tail =3D &head; - - if ((GetLogicalProcessorInformation(pslpi, &length) =3D=3D FALSE) && - (GetLastError() =3D=3D ERROR_INSUFFICIENT_BUFFER) && - (length > sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION))) { - ptr =3D pslpi =3D g_malloc0(length); - if (GetLogicalProcessorInformation(pslpi, &length) =3D=3D FALSE) { - error_setg(&local_err, "Failed to get processor information: %= d", - (int)GetLastError()); - } - } else { - error_setg(&local_err, - "Failed to get processor information buffer length: %d", - (int)GetLastError()); - } - - while ((local_err =3D=3D NULL) && (length > 0)) { - if (pslpi->Relationship =3D=3D RelationProcessorCore) { - ULONG_PTR cpu_bits =3D pslpi->ProcessorMask; - - while (cpu_bits > 0) { - if (!!(cpu_bits & 1)) { - GuestLogicalProcessor *vcpu; - - vcpu =3D g_malloc0(sizeof *vcpu); - vcpu->logical_id =3D current++; - vcpu->online =3D true; - vcpu->has_can_offline =3D true; - - QAPI_LIST_APPEND(tail, vcpu); - } - cpu_bits >>=3D 1; - } - } - length -=3D sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION); - pslpi++; /* next entry */ - } - - g_free(ptr); - - if (local_err =3D=3D NULL) { - if (head !=3D NULL) { - return head; - } - /* there's no guest with zero VCPUs */ - error_setg(&local_err, "Guest reported zero VCPUs"); - } - - qapi_free_GuestLogicalProcessorList(head); - error_propagate(errp, local_err); - return NULL; -} - -int64_t qmp_guest_set_vcpus(GuestLogicalProcessorList *vcpus, Error **errp) -{ - error_setg(errp, QERR_UNSUPPORTED); - return -1; -} - static gchar * get_net_error_message(gint error) { diff --git a/qga/commands.c b/qga/commands.c index 117c219ac4..d5ad904480 100644 --- a/qga/commands.c +++ b/qga/commands.c @@ -573,3 +573,17 @@ GuestFileRead *qmp_guest_file_read(int64_t handle, boo= l has_count, =20 return read_data; } + +#ifndef CONFIG_WITH_RUST +GuestLogicalProcessorList *qmp_guest_get_vcpus(Error **errp) +{ + error_setg(errp, QERR_UNSUPPORTED); + return NULL; +} + +int64_t qmp_guest_set_vcpus(GuestLogicalProcessorList *vcpus, Error **errp) +{ + error_setg(errp, QERR_UNSUPPORTED); + return 0; +} +#endif diff --git a/tests/unit/test-qga.c b/tests/unit/test-qga.c index a22ab8c82c..47fd8eb717 100644 --- a/tests/unit/test-qga.c +++ b/tests/unit/test-qga.c @@ -308,6 +308,7 @@ static void test_qga_info(gconstpointer fix) =20 static void test_qga_get_vcpus(gconstpointer fix) { +#ifdef CONFIG_WITH_RUST const TestFixture *fixture =3D fix; QDict *ret; QList *list; @@ -324,6 +325,7 @@ static void test_qga_get_vcpus(gconstpointer fix) g_assert(qdict_haskey(qobject_to(QDict, entry->value), "logical-id")); =20 qobject_unref(ret); +#endif } =20 static void test_qga_get_fsinfo(gconstpointer fix) diff --git a/Cargo.lock b/Cargo.lock index 8752dbf2ac..f3d2631865 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -92,6 +92,8 @@ version =3D "0.1.0" dependencies =3D [ "common", "hostname", + "nix", + "winapi", ] =20 [[package]] diff --git a/qga/Cargo.toml b/qga/Cargo.toml index 387af59a30..0661b8b7c6 100644 --- a/qga/Cargo.toml +++ b/qga/Cargo.toml @@ -8,6 +8,12 @@ publish =3D false common =3D { path =3D "../rust/common" } hostname =3D "0.3.1" =20 +[target."cfg(unix)".dependencies] +nix =3D "0.20.0" + +[target."cfg(windows)".dependencies] +winapi =3D { version =3D "0.3.9", features =3D ["sysinfoapi", "winnt"] } + [lib] path =3D "lib.rs" crate-type =3D ["staticlib"] diff --git a/qga/qmp/mod.rs b/qga/qmp/mod.rs index c192e4247d..5b4f17a07d 100644 --- a/qga/qmp/mod.rs +++ b/qga/qmp/mod.rs @@ -1,6 +1,6 @@ use common::*; =20 -use crate::qapi_ffi; +use crate::{qapi::NewPtr, qapi_ffi}; =20 mod hostname; =20 @@ -8,3 +8,21 @@ mod hostname; extern "C" fn qmp_guest_get_host_name(errp: *mut *mut ffi::Error) -> *mut = qapi_ffi::GuestHostName { qmp!(hostname::get(), errp) } + +mod vcpus; + +#[no_mangle] +extern "C" fn qmp_guest_get_vcpus( + errp: *mut *mut ffi::Error, +) -> *mut qapi_ffi::GuestLogicalProcessorList { + qmp!(vcpus::get(), errp) +} + +#[no_mangle] +extern "C" fn qmp_guest_set_vcpus( + vcpus: *const qapi_ffi::GuestLogicalProcessorList, + errp: *mut *mut ffi::Error, +) -> libc::c_longlong { + let vcpus =3D unsafe { from_qemu_none(NewPtr(vcpus)) }; + qmp!(vcpus::set(vcpus), errp, -1) +} diff --git a/qga/qmp/vcpus.rs b/qga/qmp/vcpus.rs new file mode 100644 index 0000000000..f86838355e --- /dev/null +++ b/qga/qmp/vcpus.rs @@ -0,0 +1,161 @@ +#[cfg(unix)] +use std::fs::OpenOptions; +#[cfg(unix)] +use std::io::ErrorKind; +#[cfg(unix)] +use std::os::unix::fs::FileExt; + +#[cfg(windows)] +use winapi::um::{sysinfoapi, winnt}; + +use crate::*; + +#[cfg(target_os =3D "linux")] +fn get_sysfs_cpu_path(id: i64) -> String { + format!("/sys/devices/system/cpu/cpu{}", id) +} + +#[cfg(target_os =3D "linux")] +fn set_vcpu(vcpu: &qapi::GuestLogicalProcessor) -> Result<()> { + let path =3D get_sysfs_cpu_path(vcpu.logical_id); + std::fs::metadata(&path)?; + + let path =3D format!("{}/online", path); + match OpenOptions::new().read(true).write(true).open(&path) { + Ok(file) =3D> { + let mut buf =3D [0u8; 1]; + file.read_exact_at(&mut buf, 0)?; + let online =3D buf[0] !=3D 0; + if vcpu.online !=3D online { + buf[0] =3D if vcpu.online { b'1' } else { b'0' }; + file.write_all_at(&buf, 0)?; + } + } + Err(e) =3D> { + if e.kind() !=3D ErrorKind::NotFound { + return Err(e.into()); + } else if !vcpu.online { + return err!(format!( + "logical processor #{} can't be offlined", + vcpu.logical_id + )); + } + } + } + + Ok(()) +} + +#[cfg(not(target_os =3D "linux"))] +fn set_vcpu(_vcpu: &qapi::GuestLogicalProcessor) -> Result<()> { + err!("unimplemented") +} + +pub(crate) fn set(vcpus: Vec) -> Result { + let mut processed =3D 0; + + for vcpu in &vcpus { + if let Err(e) =3D set_vcpu(vcpu) { + if processed !=3D 0 { + break; + } + return Err(e); + } + + processed +=3D 1; + } + + Ok(processed) +} + +#[cfg(target_os =3D "linux")] +pub(crate) fn get() -> Result> { + use nix::unistd::sysconf; + + let mut vcpus =3D vec![]; + let nproc_conf =3D match sysconf(unsafe { std::mem::transmute(libc::_S= C_NPROCESSORS_CONF) })? { + Some(nproc) =3D> nproc, + None =3D> { + return err!("Indefinite number of processors."); + } + }; + + for logical_id in 0..nproc_conf { + let path =3D get_sysfs_cpu_path(logical_id); + if std::fs::metadata(&path).is_err() { + continue; + } + + let path =3D format!("{}/online", path); + let (online, can_offline) =3D match OpenOptions::new().read(true).= open(&path) { + Ok(file) =3D> { + let mut buf =3D [0u8; 1]; + file.read_exact_at(&mut buf, 0)?; + (buf[0] !=3D 0, Some(true)) + } + Err(e) =3D> { + if e.kind() !=3D ErrorKind::NotFound { + return Err(e.into()); + } + (true, Some(false)) + } + }; + + vcpus.push(qapi::GuestLogicalProcessor { + logical_id, + online, + can_offline, + }); + } + + Ok(vcpus) +} + +#[cfg(target_os =3D "windows")] +fn get_logical_processor_info() -> Result> { + unsafe { + let mut needed_size =3D 0; + sysinfoapi::GetLogicalProcessorInformation(std::ptr::null_mut(), &= mut needed_size); + let struct_size =3D std::mem::size_of::() as u32; + if needed_size =3D=3D 0 || needed_size < struct_size || needed_siz= e % struct_size !=3D 0 { + return err!("Failed to get processor information"); + } + + let nstruct =3D needed_size / struct_size; + let mut buf =3D Vec::with_capacity(nstruct as usize); + let result =3D sysinfoapi::GetLogicalProcessorInformation(buf.as_m= ut_ptr(), &mut needed_size); + if result =3D=3D 0 { + return err!("Failed to get processor information"); + } + + let nstruct =3D needed_size / struct_size; + buf.set_len(nstruct as usize); + Ok(buf) + } +} + +#[cfg(target_os =3D "windows")] +pub(crate) fn get() -> Result> { + let mut vcpus =3D vec![]; + + get_logical_processor_info()?.iter().map(|info| { + for _ in 0..info.ProcessorMask.count_ones() { + vcpus.push(qapi::GuestLogicalProcessor { + logical_id: vcpus.len() as i64, + online: true, + can_offline: Some(false), + }); + } + }); + + if vcpus.is_empty() { + return err!("Guest reported zero VCPUs"); + } + + Ok(vcpus) +} + +#[cfg(not(any(target_os =3D "linux", target_os =3D "windows")))] +pub(crate) fn get() -> Result> { + err!("unimplemented") +} --=20 2.33.0.113.g6c40894d24 From nobody Tue May 7 11:02:16 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631019377114769.0344745329788; Tue, 7 Sep 2021 05:56:17 -0700 (PDT) Received: from localhost ([::1]:47894 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNae7-0006l0-T6 for importer@patchew.org; Tue, 07 Sep 2021 08:56:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43560) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNaBD-0000lE-SN for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:26:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:47331) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNaBC-0000Qp-9Q for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:26:23 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-594-YMmoFtxtPdqKpUYcJkg8lw-1; Tue, 07 Sep 2021 08:26:20 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C697A101371B for ; Tue, 7 Sep 2021 12:26:19 +0000 (UTC) Received: from localhost (unknown [10.39.208.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id 329221972D; Tue, 7 Sep 2021 12:26:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631017581; 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=h3dbzgGunefKAuftb3gTFrICA1H5uzJASY+5MaNdrt8=; b=KVhdGou2LDKha4/n0xD8Hn0W2iLp0/sYwB0gubLlbT9gEX38+4z2lZG9zcqXI98qjllqNL 4u7rGZlyrWZahgZEqSC+OacxKq1Vuy0Kxlj6BwqD9NLHn/bKY9eoWsy9D8O0n8/GgT0AXX z3EP0UDvwQGB7u5pYp5V4ZgDUAnaiUo= X-MC-Unique: YMmoFtxtPdqKpUYcJkg8lw-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [RFC v3 30/32] tests/vm: add Rust to FreeBSD VM Date: Tue, 7 Sep 2021 16:19:41 +0400 Message-Id: <20210907121943.3498701-31-marcandre.lureau@redhat.com> In-Reply-To: <20210907121943.3498701-1-marcandre.lureau@redhat.com> References: <20210907121943.3498701-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=marcandre.lureau@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, berrange@redhat.com, armbru@redhat.com, stefanha@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631019377784100001 From: Marc-Andr=C3=A9 Lureau Test Rust support on FreeBSD. Signed-off-by: Marc-Andr=C3=A9 Lureau --- tests/vm/freebsd | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/vm/freebsd b/tests/vm/freebsd index 6e20e84322..62c7adbe3c 100755 --- a/tests/vm/freebsd +++ b/tests/vm/freebsd @@ -38,6 +38,7 @@ class FreeBSDVM(basevm.BaseVM): "bzip2", "python37", "ninja", + "rust", =20 # gnu tools "bash", --=20 2.33.0.113.g6c40894d24 From nobody Tue May 7 11:02:16 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631020200374635.0543041415448; Tue, 7 Sep 2021 06:10:00 -0700 (PDT) Received: from localhost ([::1]:53228 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNarP-0004ji-Bz for importer@patchew.org; Tue, 07 Sep 2021 09:09:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43598) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNaBR-00018g-S7 for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:26:38 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:44916) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNaBQ-0000Vs-9o for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:26:37 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-511-JipiMNN5P1OLOX8nYeC1rQ-1; Tue, 07 Sep 2021 08:26:33 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8D7C4107ACCA for ; Tue, 7 Sep 2021 12:26:32 +0000 (UTC) Received: from localhost (unknown [10.39.208.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9F624781EE; Tue, 7 Sep 2021 12:26:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631017595; 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=Kbs1DsLIvJdmf816ZYXtbGyx19Q2exBJdVzzAqV6yiA=; b=NmQRqBR5mrz5eyxC/SVp/W7pUCUsUO1v20Jf5eICiuUZHdi+gp+ghJmkVedaqEgNWKUl5l JGLAJOeDR5TLxlkNx26q0VttSyzTXKJIc0PuIYjYrscCh3g0XY1vofH/bTDctTIIx2pfwg kD47OjX0L7+/T+lbvTX06DGpjIUhfbE= X-MC-Unique: JipiMNN5P1OLOX8nYeC1rQ-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [RFC v3 31/32] tests/vm: bump fedora VM to f32 Date: Tue, 7 Sep 2021 16:19:42 +0400 Message-Id: <20210907121943.3498701-32-marcandre.lureau@redhat.com> In-Reply-To: <20210907121943.3498701-1-marcandre.lureau@redhat.com> References: <20210907121943.3498701-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=marcandre.lureau@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, berrange@redhat.com, armbru@redhat.com, stefanha@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631020200809100001 From: Marc-Andr=C3=A9 Lureau The Rust version shipped in Fedora 30 is < 1.36, and would not let the build work with --offline. The one in Fedora 31 has some issues with --offline (https://github.com/rust-lang/cargo/issues/7582) Signed-off-by: Marc-Andr=C3=A9 Lureau --- tests/vm/fedora | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/vm/fedora b/tests/vm/fedora index b977efe4a2..03abc8ebe3 100755 --- a/tests/vm/fedora +++ b/tests/vm/fedora @@ -23,11 +23,11 @@ class FedoraVM(basevm.BaseVM): name =3D "fedora" arch =3D "x86_64" =20 - base =3D "https://archives.fedoraproject.org/pub/archive/fedora/linux/= releases/30/" - link =3D base + "Server/x86_64/iso/Fedora-Server-netinst-x86_64-30-1.2= .iso" + base =3D "https://archives.fedoraproject.org/pub/fedora/linux/releases= /32/" + link =3D base + "Server/x86_64/iso/Fedora-Server-netinst-x86_64-32-1.6= .iso" repo =3D base + "Server/x86_64/os/" full =3D base + "Everything/x86_64/os/" - csum =3D "5e4eac4566d8c572bfb3bcf54b7d6c82006ec3c6c882a2c9235c6d3494d7= b100" + csum =3D "7f4afd2a26c718f9f15e4bbfd9c2e8849f81036d2a82a4e81fa4a313a833= da9c" size =3D "20G" pkgs =3D [ # tools @@ -106,7 +106,7 @@ class FedoraVM(basevm.BaseVM): self.console_wait_send("1) [ ] Standard Part", "1\n") self.console_wait_send("1) [x] Standard Part", "c\n") =20 - self.console_wait_send("7) [!] Root password", "7\n") + self.console_wait_send("7) [x] Root password", "7\n") self.console_wait("Password:") self.console_send("%s\n" % self._config["root_pass"]) self.console_wait("Password (confirm):") @@ -116,7 +116,6 @@ class FedoraVM(basevm.BaseVM): self.console_wait_send("1) [ ] Create user", "1\n") self.console_wait_send("3) User name", "3\n") self.console_wait_send("ENTER:", "%s\n" % self._config["guest_user= "]) - self.console_wait_send("4) [ ] Use password", "4\n") self.console_wait_send("5) Password", "5\n") self.console_wait("Password:") self.console_send("%s\n" % self._config["guest_pass"]) --=20 2.33.0.113.g6c40894d24 From nobody Tue May 7 11:02:16 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631019111181597.4371875880529; Tue, 7 Sep 2021 05:51:51 -0700 (PDT) Received: from localhost ([::1]:36004 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNaZq-0006xF-5n for importer@patchew.org; Tue, 07 Sep 2021 08:51:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43836) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNaCS-0002MQ-Bm for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:27:40 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:52543) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNaCM-0000rZ-8e for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:27:39 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-12-THvgZZs4Om2yR8MM9QLiwg-1; Tue, 07 Sep 2021 08:27:32 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B11A4108F4D5 for ; Tue, 7 Sep 2021 12:27:18 +0000 (UTC) Received: from localhost (unknown [10.39.208.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id 919B376C20; Tue, 7 Sep 2021 12:26:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631017653; 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=hg+pnLxe929GTHm21ozIRZcvSOKWajNSi2+/j9akkAI=; b=Q9lxtV2IRAo6QbI7caDi/+oVGk3V6/rIYesbTf8nXJWe/uKfa9QWUnS201r8DdKN2eCXEB gGHgvsdDvCN0AqjhqjWNlnA/DSHg+0m/CElHtrOO38wc1ZuCG0kifCEZArl4j7VESoOGba d2sIQlmV6C2XMskCxB0fd2LvTQ24e+I= X-MC-Unique: THvgZZs4Om2yR8MM9QLiwg-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [RFC v3 32/32] tests/vm: add Rust to Fedora Date: Tue, 7 Sep 2021 16:19:43 +0400 Message-Id: <20210907121943.3498701-33-marcandre.lureau@redhat.com> In-Reply-To: <20210907121943.3498701-1-marcandre.lureau@redhat.com> References: <20210907121943.3498701-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=marcandre.lureau@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, berrange@redhat.com, armbru@redhat.com, stefanha@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631019112488100001 From: Marc-Andr=C3=A9 Lureau Test the Rust support on Fedora. Signed-off-by: Marc-Andr=C3=A9 Lureau --- tests/vm/fedora | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/vm/fedora b/tests/vm/fedora index 03abc8ebe3..70347e3fa2 100755 --- a/tests/vm/fedora +++ b/tests/vm/fedora @@ -34,6 +34,9 @@ class FedoraVM(basevm.BaseVM): 'git-core', 'gcc', 'binutils', 'make', 'ninja-build', =20 + # Rust + 'cargo', 'rust', + # perl 'perl-Test-Harness', =20 --=20 2.33.0.113.g6c40894d24