From nobody Mon May 13 11:48:03 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 ARC-Seal: i=1; a=rsa-sha256; t=1602448664; cv=none; d=zohomail.com; s=zohoarc; b=kKvuJj9vzJsfzisjLmrGrzX0JsaCXVTByyptL7EepleXmyo3UlMKhGoTtgL3hMMOc4I9Uzbs3Wwa+NXicQF2XuF9NttpQ/gv6UZYFxfpYZBQhU6HVsSScfK/W8BSXGfX5MJyLEDVoasdm9MDNOYvohamkaqnFF4rg1U795rh/q0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602448664; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=DRDoZioQbQ1N48Nel/LGXnmQnrp9I+d1CojiZL58o3E=; b=m4mDbytzslFo+/J6Z280+OIY94lzEZDzj/Zt+0kfqpUp2CwgcMFUmCJ7YRZEhLffTNckcy6alX5QJR8fCJQW1ThBiODUuDF7hr4ZtzEgcvjK7+K8S2nDHBGLiBBxr/t92RR4RF4MS2AAAWSutMqineNPPrUF7xDv0JNRDuYA86Q= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602448664260202.69191713902285; Sun, 11 Oct 2020 13:37:44 -0700 (PDT) Received: from localhost ([::1]:51496 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kRi6A-0001p5-NV for importer@patchew.org; Sun, 11 Oct 2020 16:37:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57322) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kRi4B-0008WK-50 for qemu-devel@nongnu.org; Sun, 11 Oct 2020 16:35:39 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:47529) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kRi49-0005Qy-K7 for qemu-devel@nongnu.org; Sun, 11 Oct 2020 16:35:38 -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-497-FuKsiZDeMPSY5uutpIVV4w-1; Sun, 11 Oct 2020 16:35:35 -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 1A6E6802B4A for ; Sun, 11 Oct 2020 20:35:34 +0000 (UTC) Received: from localhost (unknown [10.36.110.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id D0CBB100239A; Sun, 11 Oct 2020 20:35:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602448536; 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=DRDoZioQbQ1N48Nel/LGXnmQnrp9I+d1CojiZL58o3E=; b=FkQJBNEEMXGC47VajIGf+3AJkBYnEE5QAefxtgwatP3LEVogrFL9WjCWDv3R+DiXGOfWnM 7tnIoCBXa01ZiAQ0IZLL1ErPBIJHQeBps+xojrnpDdNnoJXT+RVGZsJNmbXJ3PC+ROEUZM b/QZy1qAl80IgulKnuAAYi5I0CHDuRs= X-MC-Unique: FuKsiZDeMPSY5uutpIVV4w-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [PoCv2 01/15] mingw: fix error __USE_MINGW_ANSI_STDIO redefined Date: Mon, 12 Oct 2020 00:34:59 +0400 Message-Id: <20201011203513.1621355-2-marcandre.lureau@redhat.com> In-Reply-To: <20201011203513.1621355-1-marcandre.lureau@redhat.com> References: <20201011203513.1621355-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-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/11 16:35:36 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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) From: Marc-Andr=C3=A9 Lureau Always put osdep.h first, and remove redundant stdlib.h include. Signed-off-by: Marc-Andr=C3=A9 Lureau --- migration/dirtyrate.c | 3 ++- tests/test-bitmap.c | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index 68577ef250..47f761e67a 100644 --- a/migration/dirtyrate.c +++ b/migration/dirtyrate.c @@ -10,8 +10,9 @@ * See the COPYING file in the top-level directory. */ =20 -#include #include "qemu/osdep.h" + +#include #include "qapi/error.h" #include "cpu.h" #include "qemu/config-file.h" diff --git a/tests/test-bitmap.c b/tests/test-bitmap.c index 2f5b71458a..8db4f67883 100644 --- a/tests/test-bitmap.c +++ b/tests/test-bitmap.c @@ -8,7 +8,6 @@ * Author: Peter Xu */ =20 -#include #include "qemu/osdep.h" #include "qemu/bitmap.h" =20 --=20 2.28.0 From nobody Mon May 13 11:48:03 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 ARC-Seal: i=1; a=rsa-sha256; t=1602448668; cv=none; d=zohomail.com; s=zohoarc; b=nEGI7x1166Z9Azj4iBD3LAsUPSC/tpBLF+zis5axiVEAiBhIBEsEsCxOeayQ8qfmMsvlJtOCxS0JvlBYGlAAaXhuMYLVn4jXbEQK0RJWe04mj986kVSatTh8owmg70iviyRJoJcsm+mKcZrTV4zQl1gih0uBAU9u/zNzxOa0yPE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602448668; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=YLHeBMskUZtqp132SdnBx+YQ+oQMCEZflKukbUd3w2w=; b=GSCK0PcK7lYGxrpSvpm1PgGCxVwRiizWm5IuT9j4GhTZXIVCg+EfM8sRFuQbkksdP7v946bdkpcR6QZw8OVZKhnRExE+eToi4xLj0JKSTEvdMoggD1bufNNcA1ryeX/t7umkuWK2R0YJ/xkSXEgUi9drC+o355hpBfEjHy9FKEg= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16024486681831000.1504178031777; Sun, 11 Oct 2020 13:37:48 -0700 (PDT) Received: from localhost ([::1]:51922 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kRi6F-00022E-1p for importer@patchew.org; Sun, 11 Oct 2020 16:37:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57338) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kRi4N-0000FD-JS for qemu-devel@nongnu.org; Sun, 11 Oct 2020 16:35:51 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:54911) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kRi4L-0005RK-JY for qemu-devel@nongnu.org; Sun, 11 Oct 2020 16:35:51 -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-111-VGHrBFH8ORGgjotoD5yijQ-1; Sun, 11 Oct 2020 16:35:46 -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 5AEB3107ACF5 for ; Sun, 11 Oct 2020 20:35:45 +0000 (UTC) Received: from localhost (unknown [10.36.110.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7AD2060C05; Sun, 11 Oct 2020 20:35:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602448548; 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=YLHeBMskUZtqp132SdnBx+YQ+oQMCEZflKukbUd3w2w=; b=NDGotNuN3dOAS9G9KcUr6veFjB1UtcbuLk6fwOvkupILsz6a6PJTUaSdiBLzYP/VGEU4uE CyDU/7NXgQDSRPv3lzC1cFahH5DqP6wMXAjYAN+ts7OQfr/dys9oaAou101V2ZwyVSPrw3 EusGPmOv8M+6Ba8lplSkMl8ICg1XT78= X-MC-Unique: VGHrBFH8ORGgjotoD5yijQ-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [PoCv2 02/15] scripts/qapi: teach c_param_type() to return const argument type Date: Mon, 12 Oct 2020 00:35:00 +0400 Message-Id: <20201011203513.1621355-3-marcandre.lureau@redhat.com> In-Reply-To: <20201011203513.1621355-1-marcandre.lureau@redhat.com> References: <20201011203513.1621355-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-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/11 16:35:36 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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) From: Marc-Andr=C3=A9 Lureau As it should be, since the argument isn't owned by the callee, but a lot of code in QEMU rely on non-const arguments to tweak it. Since Rust types / bindings are derived from the C version, we have to be more accurate there to do correct ownership conversions. Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi/schema.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index d1307ec661..ca85c7273a 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -167,8 +167,14 @@ class QAPISchemaType(QAPISchemaEntity): 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 for a stricte= r declaration. + def c_param_type(self, const=3DFalse): + 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): @@ -221,10 +227,10 @@ class QAPISchemaBuiltinType(QAPISchemaType): def c_type(self): return self._c_type_name =20 - def c_param_type(self): + def c_param_type(self, const=3DFalse): 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.28.0 From nobody Mon May 13 11:48:03 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 ARC-Seal: i=1; a=rsa-sha256; t=1602448733; cv=none; d=zohomail.com; s=zohoarc; b=GJrDwmQmGN2t621ehqve7syQWK0REP9ddeurABa1FlwoH9r9Mfxnr80NBsRP9e/FJEIDcrnSTZYZFkEgNBwW7hyQdIL8CHT7PkJkZTympB9LFenBVozzxDXlFXD1uRFPWhRBDW33vLvqVoY49hhbPVpnvPWNMCAB5npKcIux/Mo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602448733; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=g62JLdVzZ+lYru1vuaaHc3s3y6QR6Xc2NvMfJYPMMUA=; b=lhb6QjMDSiP3QFilc2FZnA/hrzmOUmIm14GL+8cT+GccOnckyeSsgOclW4zBvIMAt/+0aR9GLxwVxZeg8pxAQaypK0MtsQjYQat6siv6BcJoayQe/JGHyO0WWJXsUtIL31lgEAFLK+9oa4Vgrypwrbjmxh2TGh3xLU2Eul6IB4U= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602448733220854.1220381760803; Sun, 11 Oct 2020 13:38:53 -0700 (PDT) Received: from localhost ([::1]:58028 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kRi7I-0004b1-4T for importer@patchew.org; Sun, 11 Oct 2020 16:38:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57352) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kRi4a-0000bj-1o for qemu-devel@nongnu.org; Sun, 11 Oct 2020 16:36:04 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:32527) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kRi4V-0005Rh-T1 for qemu-devel@nongnu.org; Sun, 11 Oct 2020 16:36: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-305-ZysuvIkDNPivcUzTFJ8Owg-1; Sun, 11 Oct 2020 16:35:56 -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 9ACA52FD01 for ; Sun, 11 Oct 2020 20:35:55 +0000 (UTC) Received: from localhost (unknown [10.36.110.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2FC155DA30; Sun, 11 Oct 2020 20:35:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602448559; 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=g62JLdVzZ+lYru1vuaaHc3s3y6QR6Xc2NvMfJYPMMUA=; b=AwnaOIPfcLMBbnv2hUjlhT1PNBLhsuVHE6ttkqg8FIj+qAFF1zyS93uUrmRbSvW+ZWtYMO dS4i8T77ZocrEi1VNoCLotUAWvTPvMWap1KvXnSKWLQTm2aGqDMCVDivVTmox4LNWTK1PN ByBFcHIuje+u4auwK7fMVgBnFO+LIUo= X-MC-Unique: ZysuvIkDNPivcUzTFJ8Owg-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [PoCv2 03/15] build-sys: add --with-rust{-target} & basic build infrastructure Date: Mon, 12 Oct 2020 00:35:01 +0400 Message-Id: <20201011203513.1621355-4-marcandre.lureau@redhat.com> In-Reply-To: <20201011203513.1621355-1-marcandre.lureau@redhat.com> References: <20201011203513.1621355-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-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/11 16:35:36 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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) From: Marc-Andr=C3=A9 Lureau Add the build-sys infrastructure to 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, many of the platforms QEMU supports are considered 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 by developpers. 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 --- Cargo.toml | 2 ++ configure | 18 ++++++++++++++++++ meson.build | 23 +++++++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 Cargo.toml 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/configure b/configure index b553288c5e..7945ceac63 100755 --- a/configure +++ b/configure @@ -446,6 +446,8 @@ meson=3D"" ninja=3D"" skip_meson=3Dno gettext=3D"" +with_rust=3D"auto" +with_rust_target=3D"" =20 bogus_os=3D"no" malloc_trim=3D"auto" @@ -1519,6 +1521,12 @@ for opt do ;; --disable-libdaxctl) libdaxctl=3Dno ;; + --with-rust) with_rust=3Dyes + ;; + --without-rust) with_rust=3Dno + ;; + --with-rust-target=3D*) with_rust_target=3D"$optarg" + ;; *) echo "ERROR: unknown option $opt" echo "Try '$0 --help' for more information" @@ -1666,6 +1674,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] @@ -1918,6 +1928,10 @@ if test -z "$ninja"; then done fi =20 +if test "$with_rust" =3D auto && has cargo; then + with_rust=3Dyes +fi + # 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). @@ -7046,6 +7060,10 @@ fi if test "$safe_stack" =3D "yes"; then echo "CONFIG_SAFESTACK=3Dy" >> $config_host_mak fi +if test "$with_rust" =3D "yes" ; then + echo "CONFIG_WITH_RUST=3Dy" >> $config_host_mak + echo "CONFIG_WITH_RUST_TARGET=3D$with_rust_target" >> $config_host_mak +fi =20 # If we're using a separate build tree, set it up now. # DIRS are directories which we simply mkdir in the build tree; diff --git a/meson.build b/meson.build index 17c89c87c6..d8526dc999 100644 --- a/meson.build +++ b/meson.build @@ -73,6 +73,28 @@ if cpu in ['x86', 'x86_64'] } endif =20 +with_rust =3D 'CONFIG_WITH_RUST' in config_host +cargo =3D find_program('cargo', required: with_rust) + +if with_rust + rs_target_triple =3D config_host['CONFIG_WITH_RUST_TARGET'] + if meson.is_cross_build() + # more default target mappings may be added over time + if rs_target_triple =3D=3D '' and targetos =3D=3D 'windows' + rs_target_triple =3D host_machine.cpu() + '-pc-windows-gnu' + endif + if rs_target_triple =3D=3D '' + error('cross-compiling, but no Rust target-triple defined.') + endif + endif +endif + +if get_option('optimization') in ['0', '1', 'g'] + rs_build_type =3D 'debug' +else + rs_build_type =3D 'release' +endif + ################## # Compiler flags # ################## @@ -1770,6 +1792,7 @@ endif if targetos =3D=3D 'darwin' summary_info +=3D {'Objective-C compiler': meson.get_compiler('objc').cm= d_array()[0]} endif +summary_info +=3D {'Rust support': with_rust} summary_info +=3D {'ARFLAGS': config_host['ARFLAGS']} summary_info +=3D {'CFLAGS': ' '.join(get_option('c_args') + ['-O' + get_option('optim= ization')] --=20 2.28.0 From nobody Mon May 13 11:48:03 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 ARC-Seal: i=1; a=rsa-sha256; t=1602448759; cv=none; d=zohomail.com; s=zohoarc; b=G+kjn36dTKsVXCbTlHBUQlUVnaAFcqrM9wUirMM69z6gaNBMtotKBrQjkrGkZ/gfl4sjvTtzbdNpv+x+tsBdkLGN4DHWO+BPck2LdxNJd6VCuYwXnPjfaUT14C29lpBLhELOXspEniMc3vqABNFI4dRz1a9XpGGuAteQ2To7wi4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602448759; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=95axpi0IvDfLnJZoXZHGJcKk2SIGdhXysMCYnQ2+U+Y=; b=V6wACoZCihp/U1WR7GAvUqWK1B1Upqyqj6JtzrFYN+9e8tHU1p1X8vRVtCYHqTlK6gNgVBy8YcmmhEzFtgMpKcreYWsPCooslEWn/Mruuzjbe4u9IEVHJrHIWWFaKbNIrzM7Ze8yJf+XMLiXlsl24g8i5Uafh1SYTTcuSkQUcKA= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 160244875993023.292892855500327; Sun, 11 Oct 2020 13:39:19 -0700 (PDT) Received: from localhost ([::1]:60208 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kRi7i-0005U3-RN for importer@patchew.org; Sun, 11 Oct 2020 16:39:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57376) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kRi4g-0000rU-4C for qemu-devel@nongnu.org; Sun, 11 Oct 2020 16:36:10 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:48770) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kRi4e-0005SJ-1D for qemu-devel@nongnu.org; Sun, 11 Oct 2020 16:36:09 -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-394-fYwgFLRaMW6Hr-fLflQp-g-1; Sun, 11 Oct 2020 16:36:01 -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 E02F32FD02 for ; Sun, 11 Oct 2020 20:36:00 +0000 (UTC) Received: from localhost (unknown [10.36.110.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id 88D955DA30; Sun, 11 Oct 2020 20:35:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602448567; 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=95axpi0IvDfLnJZoXZHGJcKk2SIGdhXysMCYnQ2+U+Y=; b=J11BBcz6UKDT3DR/6gOyc9gu26LlelKHKaPTEMTyOx0a4sPTL/1/HEPzMHGaq3SZdvC9Vg F7DvV/7/AsmZpE1+61+CqWjEJFSk3It2hwn+TeJOJ1x9Rus8HD8qSovBGl8889lTBIEQyf kWr6yvBKl9F6DUDmPr1MJ5aWzP8NRGU= X-MC-Unique: fYwgFLRaMW6Hr-fLflQp-g-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [PoCv2 04/15] build-sys: add a cargo-wrapper script Date: Mon, 12 Oct 2020 00:35:02 +0400 Message-Id: <20201011203513.1621355-5-marcandre.lureau@redhat.com> In-Reply-To: <20201011203513.1621355-1-marcandre.lureau@redhat.com> References: <20201011203513.1621355-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=63.128.21.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/11 16:23:51 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=-1, RCVD_IN_MSPIKE_WL=-0.01, 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) From: Marc-Andr=C3=A9 Lureau Introduce a script to help calling cargo from Rust. Cargo is the most convenient way to build Rust code, with various crates, and has many features that meson lacks in general for Rust. Trying to convert projects to meson automatically is an option I considered (see for ex https://github.com/badboy/bygge for ninja conversion), but the complexity of the task and the need of build.rs mechanism in various crates makes this endeavour out of scope at this point. This script will help to invoke cargo in different ways. For now, it supports building static libraries. It sets up a common environment, run the compiler and grep its output for the linker flags. Finally it copies the built library to the expected meson output directory, and create a file with the linker arguments. Signed-off-by: Marc-Andr=C3=A9 Lureau --- meson.build | 1 + scripts/cargo_wrapper.py | 101 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 scripts/cargo_wrapper.py diff --git a/meson.build b/meson.build index d8526dc999..c30bb290c5 100644 --- a/meson.build +++ b/meson.build @@ -75,6 +75,7 @@ endif =20 with_rust =3D 'CONFIG_WITH_RUST' in config_host cargo =3D find_program('cargo', required: with_rust) +cargo_wrapper =3D find_program('scripts/cargo_wrapper.py') =20 if with_rust rs_target_triple =3D config_host['CONFIG_WITH_RUST_TARGET'] diff --git a/scripts/cargo_wrapper.py b/scripts/cargo_wrapper.py new file mode 100644 index 0000000000..164fad5123 --- /dev/null +++ b/scripts/cargo_wrapper.py @@ -0,0 +1,101 @@ +#!/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 glob +import os +import os.path +import re +import subprocess +import sys +from typing import List + + +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 build_lib(args: argparse.Namespace) -> None: + 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 dependency + config =3D configparser.ConfigParser() + config.read(manifest_path) + package_name =3D config["package"]["name"].strip('"') + 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 =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, + ] + 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 ["--", "--print", "native-static-libs"] + cargo_cmd +=3D args.EXTRA + try: + out =3D subprocess.check_output( + cargo_cmd, + env=3Ddict(os.environ, **env), + stderr=3Dsubprocess.STDOUT, + universal_newlines=3DTrue, + ) + native_static_libs =3D re.search(r"native-static-libs:(.*)", out) + link_args =3D native_static_libs.group(1) + with open(libargs, "w") as f: + print(link_args, file=3Df) + + distutils.file_util.copy_file(liba, args.build_dir, update=3DTrue) + except subprocess.CalledProcessError as e: + print( + "Environment: " + " ".join(["{}=3D{}".format(k, v) for k, v in= env.items()]) + ) + print("Command: " + " ".join(cargo_cmd)) + print(e.output) + sys.exit(1) + + +def main() -> None: + parser =3D argparse.ArgumentParser() + parser.add_argument("command") + 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") + parser.add_argument("EXTRA", nargs=3D"*") + args =3D parser.parse_args() + + if args.command =3D=3D "build-lib": + build_lib(args) + else: + raise argparse.ArgumentTypeError("Unknown command: %s" % args.comm= and) + + +if __name__ =3D=3D "__main__": + main() --=20 2.28.0 From nobody Mon May 13 11:48:03 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 ARC-Seal: i=1; a=rsa-sha256; t=1602448755; cv=none; d=zohomail.com; s=zohoarc; b=iSUh/2/rYstCiy3gz/+X1b6z+rxkXkskpFAm13vIWZMiUEzfmg1rJPLmMfh0zuPep8XjRsPIASzc00p3icJWzXp+j8zZhcbH6wjalam20jFVvxfPzIuj3ojiB1gRSHFUPZZ0T1yU0Qt0EO6N+WdNjfaMW4EClfs9FKShmfr47IY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602448755; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=OHft3RD80FkUI2fpCOWT/+7Xhsx9FIeU/vkqD1Xscrk=; b=T3zkRRJ3Kk7IczsBfIXTARaV1x1Ts4r8lODZRX8JW9sV8SebvVDUARs2NSnBvg01FViftfwMZjG31esvFMYfZ8OPZnmdmWpWdyN6uLqxAfyyCBe91B1PgNYzzI+alu2hVQQgM8MgHWfHw7GR4Ne5prBmrSjPM3RDU72QHnYRgdM= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602448755425815.0020206829998; Sun, 11 Oct 2020 13:39:15 -0700 (PDT) Received: from localhost ([::1]:59892 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kRi7e-0005MH-BF for importer@patchew.org; Sun, 11 Oct 2020 16:39:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57444) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kRi4q-00012b-TD for qemu-devel@nongnu.org; Sun, 11 Oct 2020 16:36:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:32174) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kRi4m-0005UA-Vx for qemu-devel@nongnu.org; Sun, 11 Oct 2020 16:36: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-284-d9gvnVZqNh6Ri1XzLgyBEA-1; Sun, 11 Oct 2020 16:36:12 -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 72071107ACF5 for ; Sun, 11 Oct 2020 20:36:11 +0000 (UTC) Received: from localhost (unknown [10.36.110.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id DF06B55790; Sun, 11 Oct 2020 20:36:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602448575; 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=OHft3RD80FkUI2fpCOWT/+7Xhsx9FIeU/vkqD1Xscrk=; b=VDWDE7X8u37yYQSuN5vg2swYu05L7ACnMyaf6AQcnIy59Iy5ZGcuqqhzaSpFdwz8U4p5SJ pu6Pu/jdY79oyHdXsX9nE8hi0TQYq36Gv7PbDcZpS7sm3mQJBNKBURZXOpo/nYh81lp5sJ irIe84l3OGTY2HnQvIOZAyjoW84MN3w= X-MC-Unique: d9gvnVZqNh6Ri1XzLgyBEA-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [PoCv2 05/15] qga/rust: build and link an empty static library Date: Mon, 12 Oct 2020 00:35:03 +0400 Message-Id: <20201011203513.1621355-6-marcandre.lureau@redhat.com> In-Reply-To: <20201011203513.1621355-1-marcandre.lureau@redhat.com> References: <20201011203513.1621355-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=63.128.21.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/11 16:23:51 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=-1, RCVD_IN_MSPIKE_WL=-0.01, 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) 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 --- Cargo.toml | 2 +- qga/Cargo.toml | 9 +++++++++ qga/lib.rs | 0 qga/meson.build | 18 +++++++++++++++++- 4 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 qga/Cargo.toml create mode 100644 qga/lib.rs diff --git a/Cargo.toml b/Cargo.toml index c4b464ff15..e69b04200f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,2 +1,2 @@ [workspace] -members =3D [] +members =3D ["qga"] diff --git a/qga/Cargo.toml b/qga/Cargo.toml new file mode 100644 index 0000000000..50c3415ab2 --- /dev/null +++ b/qga/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name =3D "qga" +version =3D "0.1.0" +edition =3D "2018" +license =3D "GPLv2" + +[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 cd08bd953a..62e13a11b3 100644 --- a/qga/meson.build +++ b/qga/meson.build @@ -45,9 +45,25 @@ 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, + 'build-lib', + meson.current_build_dir(), + meson.current_source_dir(), + meson.build_root(), + rs_build_type, + rs_target_triple]) + qga_rs =3D declare_dependency(link_args: '@' + cargo_qga.full_path(), so= urces: 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.28.0 From nobody Mon May 13 11:48:03 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 ARC-Seal: i=1; a=rsa-sha256; t=1602448913; cv=none; d=zohomail.com; s=zohoarc; b=A3/JrJJZFkuVATi5/NUsqAsb5X/q1ZGCo04JekzpvqezzQ237B35E4akiITLQ+ts0YT1S6He2E1QGxmSy6muSkYaYy0sEpqbxMEf8XyyyzJgvvXL9rnwJ3vCdlXoUK5ib2V/YpIpqnl4ADAZsedTYSIIflmBa/jYB2zrRwr6LXc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602448913; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=oMGcivtxqfyttrxW+n4YbT+qnoQcOtRjXxzV/2OSLnk=; b=e0w95PXAyqeQgObSvxV60ghr/vd2jU8O1/LoLALmit3aEvruqMFBysgt9gUzLvvIsysWokA4/mfjIAikwA62+o3W4JS01D0Y4EK3E5a4xtuwWYPH8TgCnSQqJcmYc1gso8qLbLDj2iXzEiEmlOt0QguQxnXkT4dulNyOMQrcPEs= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602448913830321.92571643802967; Sun, 11 Oct 2020 13:41:53 -0700 (PDT) Received: from localhost ([::1]:40314 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kRiAC-0000rn-Gp for importer@patchew.org; Sun, 11 Oct 2020 16:41:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57456) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kRi4w-00017H-La for qemu-devel@nongnu.org; Sun, 11 Oct 2020 16:36:28 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:50385) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kRi4s-0005UK-GC for qemu-devel@nongnu.org; Sun, 11 Oct 2020 16:36:26 -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-306-o_2hRVGHMz-OOlPLfEgsFA-1; Sun, 11 Oct 2020 16:36:18 -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 C77DF804001 for ; Sun, 11 Oct 2020 20:36:17 +0000 (UTC) Received: from localhost (unknown [10.36.110.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8C8D67512E; Sun, 11 Oct 2020 20:36:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602448580; 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=oMGcivtxqfyttrxW+n4YbT+qnoQcOtRjXxzV/2OSLnk=; b=Ri/CRzxZoyxrVcz8252OYAOLlwRIYsiVVw4PkoKIhp3+4YbLFO98Wpot6EZarBQlt/LKlh v6E2IjQgtMPQnjFiUz7+YPC9gmBnkVyOtjjzzKWSQq35QgLzhe22g/empOhAxNSjDywhnr 764iqt1hXkToc8Dzp8RvPkrLQDngbyU= X-MC-Unique: o_2hRVGHMz-OOlPLfEgsFA-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [PoCv2 06/15] rust: provide a common crate for QEMU Date: Mon, 12 Oct 2020 00:35:04 +0400 Message-Id: <20201011203513.1621355-7-marcandre.lureau@redhat.com> In-Reply-To: <20201011203513.1621355-1-marcandre.lureau@redhat.com> References: <20201011203513.1621355-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=63.128.21.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/11 16:23:51 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=-1, RCVD_IN_MSPIKE_WL=-0.01, 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) 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 prooven 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. Signed-off-by: Marc-Andr=C3=A9 Lureau --- Cargo.toml | 5 +- rust/common/Cargo.toml | 11 ++ rust/common/src/error.rs | 109 ++++++++++++ rust/common/src/lib.rs | 10 ++ rust/common/src/qemu.rs | 30 ++++ rust/common/src/sys.rs | 58 +++++++ rust/common/src/translate.rs | 309 +++++++++++++++++++++++++++++++++++ 7 files changed, 531 insertions(+), 1 deletion(-) create mode 100644 rust/common/Cargo.toml create mode 100644 rust/common/src/error.rs create mode 100644 rust/common/src/lib.rs create mode 100644 rust/common/src/qemu.rs create mode 100644 rust/common/src/sys.rs create mode 100644 rust/common/src/translate.rs diff --git a/Cargo.toml b/Cargo.toml index e69b04200f..26bd083f79 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,2 +1,5 @@ [workspace] -members =3D ["qga"] +members =3D [ + "qga", + "rust/common", +] diff --git a/rust/common/Cargo.toml b/rust/common/Cargo.toml new file mode 100644 index 0000000000..f0584dcc83 --- /dev/null +++ b/rust/common/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name =3D "common" +version =3D "0.1.0" +edition =3D "2018" +license =3D "GPLv2" + +[dependencies] +libc =3D "^0.2.76" + +[target."cfg(unix)".dependencies] +nix =3D "^0.18.0" diff --git a/rust/common/src/error.rs b/rust/common/src/error.rs new file mode 100644 index 0000000000..b89f788833 --- /dev/null +++ b/rust/common/src/error.rs @@ -0,0 +1,109 @@ +use std::{self, ffi, fmt, io, ptr}; + +use crate::translate::*; +use crate::{qemu, sys}; + +/// Common error type for QEMU and related projects. +#[derive(Debug)] +pub enum Error { + FailedAt(String, &'static str, u32), + Io(io::Error), + #[cfg(unix)] + 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 sys::Error; +} + +impl<'a> ToQemuPtr<'a, *mut sys::Error> for Error { + type Storage =3D qemu::CError; + + fn to_qemu_none(&'a self) -> Stash<'a, *mut sys::Error, Self> { + let err =3D self.to_qemu_full(); + + Stash(err, unsafe { from_qemu_full(err) }) + } + + fn to_qemu_full(&self) -> *mut sys::Error { + let cmsg =3D + ffi::CString::new(self.message()).expect("ToQemuPtr: un= expected '\0' character"); + let mut csrc =3D ffi::CString::new("").unwrap(); + let (src, line) =3D self.location().map_or((ptr::null(), 0 as i32)= , |loc| { + csrc =3D ffi::CString::new(loc.0).expect("ToQemuPtr:: u= nexpected '\0' character"); + (csrc.as_ptr() as *const libc::c_char, loc.1 as i32) + }); + let func =3D ptr::null(); + + let mut err: *mut sys::Error =3D ptr::null_mut(); + unsafe { + sys::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. +/// +/// (this error type can be nicely converted to a QEMU `sys::Error`) +#[allow(unused_macros)] +#[macro_export] +macro_rules! err { + ($err:expr) =3D> { + Err(Error::FailedAt($err.into(), file!(), line!())) + }; +} diff --git a/rust/common/src/lib.rs b/rust/common/src/lib.rs new file mode 100644 index 0000000000..2632a2b92b --- /dev/null +++ b/rust/common/src/lib.rs @@ -0,0 +1,10 @@ +mod error; +pub use error::*; + +mod qemu; +pub use qemu::*; + +mod translate; +pub use translate::*; + +pub mod sys; diff --git a/rust/common/src/qemu.rs b/rust/common/src/qemu.rs new file mode 100644 index 0000000000..e1e47d3623 --- /dev/null +++ b/rust/common/src/qemu.rs @@ -0,0 +1,30 @@ +use std::{ffi::CStr, ptr, str}; + +use crate::{sys, translate}; + +/// A type representing an owned C QEMU Error. +pub struct CError(ptr::NonNull); + +impl translate::FromQemuPtrFull<*mut sys::Error> for CError { + unsafe fn from_qemu_full(ptr: *mut sys::Error) -> Self { + assert!(!ptr.is_null()); + Self(ptr::NonNull::new_unchecked(ptr)) + } +} + +impl CError { + pub fn pretty(&self) -> &str { + unsafe { + let pretty =3D sys::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 { sys::error_free(self.0.as_ptr()) } + } +} diff --git a/rust/common/src/sys.rs b/rust/common/src/sys.rs new file mode 100644 index 0000000000..de37144860 --- /dev/null +++ b/rust/common/src/sys.rs @@ -0,0 +1,58 @@ +//! 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); +} diff --git a/rust/common/src/translate.rs b/rust/common/src/translate.rs new file mode 100644 index 0000000000..3be6e91987 --- /dev/null +++ b/rust/common/src/translate.rs @@ -0,0 +1,309 @@ +// 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 sy= s::*mut. +use libc::{c_char, size_t}; +use std::ffi::{CStr, CString}; +use std::ptr; + +use crate::sys; + +/// 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 for NewPtr. +/// +/// 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] +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 sys::GuestInfo` for `GuestInfo`= ... +pub trait QemuPtrDefault { + type QemuType: Ptr; +} + +impl QemuPtrDefault for String { + type QemuType =3D *mut c_char; +} + +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> 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 { sys::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 _); + sys::g_free(ptr as *mut _); + res + } +} + +/// A macro to help the implementation of `Vec -> P` translations. +#[allow(unused_macros)] +#[macro_export] +macro_rules! vec_to_qemu { + ($rs:ident, $sys:ident) =3D> { + #[allow(non_camel_case_types)] + pub struct $sys(*mut qapi_sys::$sys); + + impl Drop for $sys { + 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<'a> ToQemuPtr<'a, NewPtr<*mut qapi_sys::$sys>> for Vec<$rs> { + type Storage =3D ( + Option<$sys>, + 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_sys::$sys =3D std::ptr::null_mut(); + for stash in &stash_vec { + let b =3D Box::new(qapi_sys::$sys { + next: list, + value: Ptr::to(stash.0), + }); + list =3D Box::into_raw(b); + } + Stash(NewPtr(list), (Some($sys(list)), stash_vec)) + } + + #[inline] + fn to_qemu_full(&self) -> NewPtr<*mut qapi_sys::$sys> { + let v: Vec<_> =3D self.iter().rev().map(ToQemuPtr::to_qemu= _full).collect(); + let mut list: *mut qapi_sys::$sys =3D std::ptr::null_mut(); + unsafe { + for val in v { + let l =3D sys::g_malloc0(std::mem::size_of::()) + as *mut qapi_sys::$sys; + (*l).next =3D list; + (*l).value =3D val; + list =3D l; + } + } + NewPtr(list) + } + } + }; +} + +/// A macro to help the implementation of `P -> Vec` translations. +#[allow(unused_macros)] +#[macro_export] +macro_rules! vec_from_qemu { + ($rs:ident, $sys:ident, $free_sys:ident) =3D> { + impl FromQemuPtrFull> for Vec<$rs> { + #[inline] + unsafe fn from_qemu_full(sys: NewPtr<*mut qapi_sys::$sys>) -> = Self { + let ret =3D from_qemu_none(NewPtr(sys.0 as *const _)); + qapi_sys::$free_sys(sys.0); + ret + } + } + + impl FromQemuPtrNone> for Vec<$rs> { + #[inline] + unsafe fn from_qemu_none(sys: NewPtr<*const qapi_sys::$sys>) -= > Self { + let mut ret =3D vec![]; + let mut it =3D sys.0; + while !it.is_null() { + let e =3D &*it; + ret.push(from_qemu_none(e.value as *const _)); + it =3D e.next; + } + ret + } + } + + impl From> for *mut qapi_sys::$sys { + fn from(p: NewPtr<*mut qapi_sys::$sys>) -> Self { + p.0 + } + } + }; +} --=20 2.28.0 From nobody Mon May 13 11:48:03 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 ARC-Seal: i=1; a=rsa-sha256; t=1602449128; cv=none; d=zohomail.com; s=zohoarc; b=cwmBmHyHlDxquIXYYObDogf9zQRQ/X+oRrlw+QmH4bsuoxiuQhSYL/QRYPJzTm/Tg58jA35E0h313cVa0i0WAj8RRJ3VgGw/dHKn1QMdimWN5V7RhnVr63JN+4gR1QdWQNDrBZXsizphJmoiDKT3uMK/E7Mh3A8/8E1VmXvpfM8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602449128; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=//HZmmfSPMGK7ml0gSGQZp5T/TptKbriYwAwFbDujNk=; b=OB5d/GoZ9CBici3KblxhiKjvPxm2uBRwV+BSxm3mMLOWLMs12A2Nlz6pZlnwV20z5y+hXIRp4+36Y1y8/RupvbX8sFxnU66VjPHzdeMiFO7iNSVkDechlGXbkeJmw3GPGAN4exPo28MoiOgp9GsQH1bQFkyekJPP4WLSeQl6rMQ= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602449128675638.3540182553273; Sun, 11 Oct 2020 13:45:28 -0700 (PDT) Received: from localhost ([::1]:48834 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kRiDe-0004eu-Q5 for importer@patchew.org; Sun, 11 Oct 2020 16:45:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57498) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kRi57-0001Lz-0I for qemu-devel@nongnu.org; Sun, 11 Oct 2020 16:36:37 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:48402) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kRi54-0005Vg-5S for qemu-devel@nongnu.org; Sun, 11 Oct 2020 16:36: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-262-F5R_kDxNOm-V_xii7kjIeg-1; Sun, 11 Oct 2020 16:36:30 -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 44F1D10066FB for ; Sun, 11 Oct 2020 20:36:29 +0000 (UTC) Received: from localhost (unknown [10.36.110.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id C7F106EF7E; Sun, 11 Oct 2020 20:36:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602448593; 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=//HZmmfSPMGK7ml0gSGQZp5T/TptKbriYwAwFbDujNk=; b=G+MNG+0ZC3lP0EYoWpqrkASKhIwdcZPfYLd/qU87zavq2VvS4gCwQ35SsWLsyqVqbj4cV4 0gO8EOQGqwFen4XXmIJRU8cTf+dq8A5xsnUP2qkxiVEnFRng4x3IoIo0lonLEhiFYW2D0W RN0nXGBLbbt51gCY3x/9f3DhsLgInY4= X-MC-Unique: F5R_kDxNOm-V_xii7kjIeg-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [PoCv2 07/15] scripts/qapi: add Rust sys bindings generation Date: Mon, 12 Oct 2020 00:35:05 +0400 Message-Id: <20201011203513.1621355-8-marcandre.lureau@redhat.com> In-Reply-To: <20201011203513.1621355-1-marcandre.lureau@redhat.com> References: <20201011203513.1621355-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=63.128.21.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/11 16:23:51 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=-1, RCVD_IN_MSPIKE_WL=-0.01, 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) 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. An important question that remains unsolved to be usable with the QEMU schema in this version, is the handling of the 'if' compilation conditions. Since the 'if' value is a C pre-processor condition, it is hard to evaluate from Rust (we could implement a minimalistic CPP evaluator, or invoke CPP and somehow parse the output...). The normal Rust way of handling conditional compilation is via #[cfg] features, which rely on feature arguments being passed to rustc from Cargo. This would require a long Rust feature list, and new 'if-cfg' conditions in the schema (an idea would be for Cargo to read features from meson in the future?) Signed-off-by: Marc-Andr=C3=A9 Lureau --- meson.build | 4 +- scripts/qapi-gen.py | 16 ++- scripts/qapi/rs.py | 126 ++++++++++++++++++++ scripts/qapi/rs_sys.py | 254 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 394 insertions(+), 6 deletions(-) create mode 100644 scripts/qapi/rs.py create mode 100644 scripts/qapi/rs_sys.py diff --git a/meson.build b/meson.build index c30bb290c5..b6b8330b97 100644 --- a/meson.build +++ b/meson.build @@ -1147,7 +1147,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_sys.py', + meson.source_root() / 'scripts/qapi-gen.py', ] =20 tracetool =3D [ diff --git a/scripts/qapi-gen.py b/scripts/qapi-gen.py index 541e8c1f55..5bfe9c8cd1 100644 --- a/scripts/qapi-gen.py +++ b/scripts/qapi-gen.py @@ -16,10 +16,13 @@ from qapi.schema import QAPIError, QAPISchema from qapi.types import gen_types from qapi.visit import gen_visit =20 +from qapi.rs_sys import gen_rs_systypes =20 def main(argv): parser =3D argparse.ArgumentParser( description=3D'Generate code from a QAPI schema') + parser.add_argument('-r', '--rust', action=3D'store_true', + help=3D"generate Rust code") parser.add_argument('-b', '--builtins', action=3D'store_true', help=3D"generate code for built-in types") parser.add_argument('-o', '--output-dir', action=3D'store', default=3D= '', @@ -45,11 +48,14 @@ def main(argv): print(err, file=3Dsys.stderr) exit(1) =20 - gen_types(schema, args.output_dir, args.prefix, args.builtins) - gen_visit(schema, args.output_dir, args.prefix, args.builtins) - gen_commands(schema, args.output_dir, args.prefix) - gen_events(schema, args.output_dir, args.prefix) - gen_introspect(schema, args.output_dir, args.prefix, args.unmask) + if args.rust: + gen_rs_systypes(schema, args.output_dir, args.prefix, args.builtin= s) + else: + gen_types(schema, args.output_dir, args.prefix, args.builtins) + gen_visit(schema, args.output_dir, args.prefix, args.builtins) + gen_commands(schema, args.output_dir, args.prefix) + gen_events(schema, args.output_dir, args.prefix) + gen_introspect(schema, args.output_dir, args.prefix, args.unmask) =20 =20 if __name__ =3D=3D '__main__': diff --git a/scripts/qapi/rs.py b/scripts/qapi/rs.py new file mode 100644 index 0000000000..daa946580b --- /dev/null +++ b/scripts/qapi/rs.py @@ -0,0 +1,126 @@ +# 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 subprocess + +from qapi.common import * +from qapi.gen import QAPIGen, QAPISchemaVisitor + + +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, protect=3DTrue): + 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 + return name + + +def rs_ctype_parse(c_type): + is_pointer =3D False + if c_type.endswith(pointer_suffix): + is_pointer =3D True + c_type =3D c_type.rstrip(pointer_suffix).strip() + 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:] + + return (is_pointer, is_const, is_list, c_type) + + +def rs_systype(c_type, sys_ns=3D'qapi_sys::', list_as_newp=3DFalse): + (is_pointer, is_const, is_list, c_type) =3D rs_ctype_parse(c_type) + + to_rs =3D { + 'char': 'libc::c_char', + 'int8_t': 'i8', + 'uint8_t': 'u8', + 'int16_t': 'i16', + 'uint16_t': 'u16', + 'int32_t': 'i32', + 'uint32_t': 'u32', + 'int64_t': 'libc::c_longlong', + 'uint64_t': 'libc::c_ulonglong', + 'double': 'libc::c_double', + 'bool': 'bool', + } + + rs =3D '' + if is_const and is_pointer: + rs +=3D '*const ' + elif is_pointer: + rs +=3D '*mut ' + if c_type in to_rs: + rs +=3D to_rs[c_type] + else: + rs +=3D sys_ns + c_type + + if is_list and list_as_newp: + rs =3D 'NewPtr<{}>'.format(rs) + + return rs + + +def to_camel_case(value): + if value[0] =3D=3D '_': + return value + raw_id =3D False + if value.startswith('r#'): + raw_id =3D True + value =3D value[2:] + value =3D ''.join(word.title() for word in filter(None, re.split("[-_]= +", value))) + if raw_id: + return 'r#' + value + else: + return value + + +class QAPIGenRs(QAPIGen): + + def __init__(self, fname): + super().__init__(fname) + + +class QAPISchemaRsVisitor(QAPISchemaVisitor): + + def __init__(self, prefix, what): + self._prefix =3D prefix + self._what =3D what + self._gen =3D QAPIGenRs(self._prefix + self._what + '.rs') + + def write(self, output_dir): + 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_sys.py b/scripts/qapi/rs_sys.py new file mode 100644 index 0000000000..551a910c57 --- /dev/null +++ b/scripts/qapi/rs_sys.py @@ -0,0 +1,254 @@ +# 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 qapi.common import * +from qapi.rs import * +from qapi.schema import QAPISchemaEnumMember, QAPISchemaObjectType + + +objects_seen =3D set() + + +def gen_rs_sys_enum(name, ifcond, members, prefix=3DNone): + if ifcond: + raise NotImplementedError("ifcond are not implemented") + # append automatically generated _max value + enum_members =3D members + [QAPISchemaEnumMember('_MAX', None)] + + ret =3D mcgen(''' + +#[derive(Copy, Clone, Debug, PartialEq, Eq)] +#[repr(C)] +pub enum %(rs_name)s { +''', + rs_name=3Drs_name(name)) + + for m in enum_members: + if m.ifcond: + raise NotImplementedError("ifcond are not implemented") + ret +=3D mcgen(''' + %(c_enum)s, +''', + c_enum=3Dto_camel_case(rs_name(m.name, False))) + ret +=3D mcgen(''' +} +''') + return ret + + +def gen_rs_sys_struct_members(members): + ret =3D '' + for memb in members: + if memb.ifcond: + raise NotImplementedError("ifcond are not implemented") + if memb.optional: + ret +=3D mcgen(''' + pub has_%(rs_name)s: bool, +''', + rs_name=3Drs_name(memb.name, protect=3DFalse)) + ret +=3D mcgen(''' + pub %(rs_name)s: %(rs_systype)s, +''', + rs_systype=3Drs_systype(memb.type.c_type(), ''), rs_n= ame=3Drs_name(memb.name)) + return ret + + +def gen_rs_sys_free(ty): + return mcgen(''' + +extern "C" { + pub fn qapi_free_%(ty)s(obj: *mut %(ty)s); +} +''', ty=3Dty) + + +def gen_rs_sys_variants(name, variants): + ret =3D mcgen(''' + +#[repr(C)] +#[derive(Copy, Clone)] +pub union %(rs_name)s { /* union tag is @%(tag_name)s */ +''', + tag_name=3Drs_name(variants.tag_member.name), + rs_name=3Dname) + + for var in variants.variants: + if var.ifcond: + raise NotImplementedError("ifcond are not implemented") + if var.type.name =3D=3D 'q_empty': + continue + ret +=3D mcgen(''' + pub %(rs_name)s: %(rs_systype)s, +''', + rs_systype=3Drs_systype(var.type.c_unboxed_type(), ''= ), + rs_name=3Drs_name(var.name)) + + ret +=3D mcgen(''' +} + +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() + } +} +''', rs_name=3Dname) + + return ret + + +def gen_rs_sys_object(name, ifcond, base, members, variants): + if ifcond: + raise NotImplementedError("ifcond are not implemented") + if name in objects_seen: + return '' + + ret =3D '' + objects_seen.add(name) + unionty =3D name + 'Union' + if variants: + for v in variants.variants: + if v.ifcond: + raise NotImplementedError("ifcond are not implemented") + if isinstance(v.type, QAPISchemaObjectType): + ret +=3D gen_rs_sys_object(v.type.name, v.type.ifcond, v.t= ype.base, + v.type.local_members, v.type.vari= ants) + ret +=3D gen_rs_sys_variants(unionty, variants) + + ret +=3D gen_rs_sys_free(rs_name(name)) + ret +=3D mcgen(''' + +#[repr(C)] +#[derive(Copy, Clone, Debug)] +pub struct %(rs_name)s { +''', + rs_name=3Drs_name(name)) + + if base: + if not base.is_implicit(): + ret +=3D mcgen(''' + // Members inherited: +''') + ret +=3D gen_rs_sys_struct_members(base.members) + if not base.is_implicit(): + ret +=3D mcgen(''' + // Own members: +''') + + ret +=3D gen_rs_sys_struct_members(members) + if variants: + ret +=3D mcgen(''' + pub u: %(unionty)s +''', unionty=3Dunionty) + ret +=3D mcgen(''' +} +''') + return ret + + +def gen_rs_sys_variant(name, ifcond, variants): + if ifcond: + raise NotImplementedError("ifcond are not implemented") + if name in objects_seen: + return '' + + objects_seen.add(name) + + vs =3D '' + for var in variants.variants: + if var.type.name =3D=3D 'q_empty': + continue + vs +=3D mcgen(''' + pub %(mem_name)s: %(rs_systype)s, +''', + rs_systype=3Drs_systype(var.type.c_unboxed_type(), ''= ), + mem_name=3Drs_name(var.name)) + + return mcgen(''' + +#[repr(C)] +#[derive(Copy,Clone)] +pub union %(rs_name)sUnion { + %(variants)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() + } +} + +#[repr(C)] +#[derive(Copy,Clone,Debug)] +pub struct %(rs_name)s { + pub ty: QType, + pub u: %(rs_name)sUnion, +} +''', + rs_name=3Drs_name(name), variants=3Dvs) + + +def gen_rs_sys_array(name, ifcond, element_type): + if ifcond: + raise NotImplementedError("ifcond are not implemented") + ret =3D mcgen(''' + +#[repr(C)] +#[derive(Copy,Clone)] +pub struct %(rs_name)s { + pub next: *mut %(rs_name)s, + pub value: %(rs_systype)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() + } +} +''', + rs_name=3Drs_name(name), rs_systype=3Drs_systype(element_= type.c_type(), '')) + ret +=3D gen_rs_sys_free(rs_name(name)) + return ret + + +class QAPISchemaGenRsSysTypeVisitor(QAPISchemaRsVisitor): + + def __init__(self, prefix): + super().__init__(prefix, 'qapi-sys-types') + + def visit_begin(self, schema): + # 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 + +use common::sys::{QNull, QObject}; + +''')) + + def visit_enum_type(self, name, info, ifcond, features, members, prefi= x): + self._gen.add(gen_rs_sys_enum(name, ifcond, members, prefix)) + + def visit_array_type(self, name, info, ifcond, element_type): + self._gen.add(gen_rs_sys_array(name, ifcond, element_type)) + + def visit_object_type(self, name, info, ifcond, features, + base, members, variants): + if name.startswith('q_'): + return + self._gen.add(gen_rs_sys_object(name, ifcond, base, members, varia= nts)) + + def visit_alternate_type(self, name, info, ifcond, features, variants): + self._gen.add(gen_rs_sys_variant(name, ifcond, variants)) + + +def gen_rs_systypes(schema, output_dir, prefix, opt_builtins): + vis =3D QAPISchemaGenRsSysTypeVisitor(prefix) + schema.visit(vis) + vis.write(output_dir) --=20 2.28.0 From nobody Mon May 13 11:48:03 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 ARC-Seal: i=1; a=rsa-sha256; t=1602448755; cv=none; d=zohomail.com; s=zohoarc; b=PCw1hsVB6SrHixb6228rGzulXBogpQxoY5TYDzd4hD1WrcuPDcE1DK2S3o8uGnn6Jrss+FQ2UwSojvQ8/eXWpxbxOYrYKPcZMBg2/EF0dy8WSF4ryJCHA++kC/rH6y0p/5qsQUMqJhe9CQV7cDCl/LOZmaP8dv/0PRG7YT22/SI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602448755; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=egvCJt14G0LEvqg5zPm7LF3yH6IbcZwusrSLXxHeOH0=; b=EnIL/ASo0kRdg2gK4RcMeRzbrSoCQwU8vx9WB35d7Kh5/woqW6cs+dEhoOn9RRv29/5Cy9BhdwSzTm/tM7nSGOzqcZIO2GIbblY6L6EE1VInZ5gyYFeaid7uKJ+F5f78AKxfOVg241MtcozkXZ0YDO+3WYsGNLPj0Bg192NhN2E= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602448755359166.4359960221948; Sun, 11 Oct 2020 13:39:15 -0700 (PDT) Received: from localhost ([::1]:59876 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kRi7e-0005Lq-Aq for importer@patchew.org; Sun, 11 Oct 2020 16:39:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57530) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kRi5F-0001hC-80 for qemu-devel@nongnu.org; Sun, 11 Oct 2020 16:36:45 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:57777) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kRi5D-0005WS-JR for qemu-devel@nongnu.org; Sun, 11 Oct 2020 16:36:44 -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-333-N9K3a7k0OLuLHCVYud_OxQ-1; Sun, 11 Oct 2020 16:36:40 -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 75B58107ACF9 for ; Sun, 11 Oct 2020 20:36:39 +0000 (UTC) Received: from localhost (unknown [10.36.110.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id 418DA5DA30; Sun, 11 Oct 2020 20:36:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602448603; 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=egvCJt14G0LEvqg5zPm7LF3yH6IbcZwusrSLXxHeOH0=; b=fNKYe3W6qhBAXV3LJ/AAsbczFD3Xh7cNerTi6e2HUBlTQNueN2vc5UtXyi/+uhUt4bG214 ImC3H94UJU4lzB94khLg5Sbj3krpVljVvMBt1HTeWQj6UiyiaIB1TlVZMwQi9Kih56H90f p6r9LPPJnf6Ca80wtnKxL5uMcQh2TdA= X-MC-Unique: N9K3a7k0OLuLHCVYud_OxQ-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [PoCv2 08/15] qga/rust: generate QGA QAPI sys bindings Date: Mon, 12 Oct 2020 00:35:06 +0400 Message-Id: <20201011203513.1621355-9-marcandre.lureau@redhat.com> In-Reply-To: <20201011203513.1621355-1-marcandre.lureau@redhat.com> References: <20201011203513.1621355-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-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/11 16:35:36 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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) From: Marc-Andr=C3=A9 Lureau Use qapi-gen to generate low-level C sys bindings for QAPI types, include them to the build. Signed-off-by: Marc-Andr=C3=A9 Lureau --- qga/Cargo.toml | 4 ++++ qga/lib.rs | 1 + qga/meson.build | 11 +++++++++++ qga/qapi_sys.rs | 5 +++++ 4 files changed, 21 insertions(+) create mode 100644 qga/qapi_sys.rs diff --git a/qga/Cargo.toml b/qga/Cargo.toml index 50c3415ab2..9966057594 100644 --- a/qga/Cargo.toml +++ b/qga/Cargo.toml @@ -4,6 +4,10 @@ version =3D "0.1.0" edition =3D "2018" license =3D "GPLv2" =20 +[dependencies] +common =3D { path =3D "../rust/common" } +libc =3D "^0.2.76" + [lib] path =3D "lib.rs" crate-type =3D ["staticlib"] diff --git a/qga/lib.rs b/qga/lib.rs index e69de29bb2..050a47e2a3 100644 --- a/qga/lib.rs +++ b/qga/lib.rs @@ -0,0 +1 @@ +mod qapi_sys; diff --git a/qga/meson.build b/qga/meson.build index 62e13a11b3..dbc8f1623b 100644 --- a/qga/meson.build +++ b/qga/meson.build @@ -47,10 +47,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-sys-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, 'build-lib', meson.current_build_dir(), diff --git a/qga/qapi_sys.rs b/qga/qapi_sys.rs new file mode 100644 index 0000000000..06fc49b826 --- /dev/null +++ b/qga/qapi_sys.rs @@ -0,0 +1,5 @@ +#![allow(dead_code)] +include!(concat!( + env!("MESON_BUILD_ROOT"), + "/qga/qga-qapi-sys-types.rs" +)); --=20 2.28.0 From nobody Mon May 13 11:48:03 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 ARC-Seal: i=1; a=rsa-sha256; t=1602449052; cv=none; d=zohomail.com; s=zohoarc; b=JcLBmKBr3EaMtBmzgdppf6KTlmTwCA604uAXL+RHvBL19AfN5muJEdSncDrqJBcx5dVFMSAe0ewdSEQPiEq7LMdFdWytCj5fy7pkkntDYauyIhQIt4s8S+7RLwysM8npeGHS0h9tatcWpr4DTSI9TQbBTzLlY7f+BVoDjRJ1O2o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602449052; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=HYWZkMKWHLktsWqLRuW6+7g2bKU6rV7ednfYnjWHwEY=; b=C19OvO3iNArftYDydlmO0DicVSe6cnqqujQgkzLTD5CnknctK1/VIcl9hKp3OQTIN/9Q2ZW9SKvYMFs5lo9zbLHd2Sh98W7oa8meuJDJNDzCK1dX9hc2oK1JJ3d7invENM4gbzitHU+dTU2a6ynPWsfn4h1st0d0LNJ3HeMR++Y= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602449052228788.9766611040101; Sun, 11 Oct 2020 13:44:12 -0700 (PDT) Received: from localhost ([::1]:46064 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kRiCQ-0003U1-Ud for importer@patchew.org; Sun, 11 Oct 2020 16:44:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57576) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kRi5R-0001oZ-9E for qemu-devel@nongnu.org; Sun, 11 Oct 2020 16:36:57 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:32448) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kRi5O-0005XF-KA for qemu-devel@nongnu.org; Sun, 11 Oct 2020 16:36:56 -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-462-TQEGmjTcPP6s_u58-mq1Hg-1; Sun, 11 Oct 2020 16:36:51 -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 7CB1110066FE for ; Sun, 11 Oct 2020 20:36:50 +0000 (UTC) Received: from localhost (unknown [10.36.110.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4F2B660C05; Sun, 11 Oct 2020 20:36:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602448613; 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=HYWZkMKWHLktsWqLRuW6+7g2bKU6rV7ednfYnjWHwEY=; b=XCPIuZoIn15R/aYGSpqsiiF09wZzIcaLySGz19Gzu12bvjovCfwTF0CqXNPSWkaBSCTc5A +TnufGqGMGstW2HM9V/KbPYbhg5278/KtJB3mBR/ikaU2QOFH19xFdX0+C5xhSFLyC1SgO JeHeIeiFMjkBXjfiSUFAbqXL/7UatC8= X-MC-Unique: TQEGmjTcPP6s_u58-mq1Hg-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [PoCv2 09/15] scripts/qapi: add generation of Rust bindings for types Date: Mon, 12 Oct 2020 00:35:07 +0400 Message-Id: <20201011203513.1621355-10-marcandre.lureau@redhat.com> In-Reply-To: <20201011203513.1621355-1-marcandre.lureau@redhat.com> References: <20201011203513.1621355-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=63.128.21.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/11 16:23:51 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=-1, RCVD_IN_MSPIKE_WL=-0.01, 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) From: Marc-Andr=C3=A9 Lureau Generate high-level idiomatic Rust code for the QAPI types, with to/from translations for C FFI. - no conditional support yet - C FFI types are mapped to higher-level types (char*->String, Foo*->Foo, has_foo/foo->Option etc) - C enums are simply aliased - C structures have corresponding Rust structures - alternate are represented as Rust enum (TODO: to/from conversion) - variants A are represented as Rust AEnum enums. A AEnum::kind() method allows to easily get the variant C kind enum value. The translation code also uses a helper enum ACEnum to hold the C pointer variant. There might be better ways to achieve the translation, but that one works for now. - unions are represented in a similar way as C, as a struct S with a "u" member (since S may have extra 'base' fields). However, the discriminant isn't a member of S, as Rust enum variant don't need that. - lists are represented as Vec and translated thanks to vec_to/from translate macros Signed-off-by: Marc-Andr=C3=A9 Lureau --- meson.build | 1 + scripts/qapi-gen.py | 2 + scripts/qapi/rs.py | 78 +++++++ scripts/qapi/rs_types.py | 447 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 528 insertions(+) create mode 100644 scripts/qapi/rs_types.py diff --git a/meson.build b/meson.build index b6b8330b97..666e38033e 100644 --- a/meson.build +++ b/meson.build @@ -1149,6 +1149,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_sys.py', + meson.source_root() / 'scripts/qapi/rs_types.py', meson.source_root() / 'scripts/qapi-gen.py', ] =20 diff --git a/scripts/qapi-gen.py b/scripts/qapi-gen.py index 5bfe9c8cd1..556bfe9e7b 100644 --- a/scripts/qapi-gen.py +++ b/scripts/qapi-gen.py @@ -17,6 +17,7 @@ from qapi.types import gen_types from qapi.visit import gen_visit =20 from qapi.rs_sys import gen_rs_systypes +from qapi.rs_types import gen_rs_types =20 def main(argv): parser =3D argparse.ArgumentParser( @@ -50,6 +51,7 @@ def main(argv): =20 if args.rust: gen_rs_systypes(schema, args.output_dir, args.prefix, args.builtin= s) + gen_rs_types(schema, args.output_dir, args.prefix, args.builtins) else: gen_types(schema, args.output_dir, args.prefix, args.builtins) gen_visit(schema, args.output_dir, args.prefix, args.builtins) diff --git a/scripts/qapi/rs.py b/scripts/qapi/rs.py index daa946580b..cab5bb9b72 100644 --- a/scripts/qapi/rs.py +++ b/scripts/qapi/rs.py @@ -11,6 +11,8 @@ from qapi.common import * from qapi.gen import QAPIGen, QAPISchemaVisitor =20 =20 +rs_lists =3D set() + rs_name_trans =3D str.maketrans('.-', '__') =20 # Map @name to a valid Rust identifier. @@ -42,12 +44,55 @@ def rs_name(name, protect=3DTrue): return name =20 =20 +def rs_type(c_type, ns=3D'qapi::', optional=3DFalse): + vec =3D False + to_rs =3D { + 'char': 'i8', + 'int8_t': 'i8', + 'uint8_t': 'u8', + 'int16_t': 'i16', + 'uint16_t': 'u16', + 'int32_t': 'i32', + 'uint32_t': 'u32', + 'int64_t': 'i64', + 'uint64_t': 'u64', + 'double': 'f64', + 'bool': 'bool', + 'str': 'String', + } + if c_type.startswith('const '): + c_type =3D c_type[6:] + if c_type.endswith(pointer_suffix): + c_type =3D c_type.rstrip(pointer_suffix).strip() + if c_type.endswith('List'): + c_type =3D c_type[:-4] + vec =3D True + else: + to_rs =3D { + 'char': 'String', + } + + if c_type in to_rs: + ret =3D to_rs[c_type] + else: + ret =3D ns + c_type + + if vec: + ret =3D 'Vec<%s>' % ret + if optional: + return 'Option<%s>' % ret + else: + return ret + + def rs_ctype_parse(c_type): is_pointer =3D False if c_type.endswith(pointer_suffix): is_pointer =3D True c_type =3D c_type.rstrip(pointer_suffix).strip() is_list =3D c_type.endswith('List') + if is_list: + rs_lists.add(c_type) is_const =3D False if c_type.startswith('const '): is_const =3D True @@ -103,6 +148,39 @@ def to_camel_case(value): return value =20 =20 +def to_qemu_none(c_type, name): + (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) + elif is_list: + return mcgen(''' + let %(name)s_ =3D NewPtr(%(name)s).to_qemu_none(); + let %(name)s =3D %(name)s_.0.0; +''', name=3Dname) + else: + 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, c_type, full=3DFalse): + (is_pointer, _, is_list, _) =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: + return 'from_qemu_{}({})'.format('full' if full else 'none', ptr) + else: + return var_name + + class QAPIGenRs(QAPIGen): =20 def __init__(self, fname): diff --git a/scripts/qapi/rs_types.py b/scripts/qapi/rs_types.py new file mode 100644 index 0000000000..3a7d8914c8 --- /dev/null +++ b/scripts/qapi/rs_types.py @@ -0,0 +1,447 @@ +# 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 qapi.common import * +from qapi.rs import * + + +objects_seen =3D set() + + +def gen_rs_variants_enum_kind(name, kind_arms): + return mcgen(''' + +impl %(rs_name)sEnum { + pub fn kind(&self) -> %(rs_name)sKind { + match self { + %(kind_arms)s + } + } +} +''', rs_name=3Drs_name(name), kind_arms=3Dkind_arms) + + +def gen_rs_variants_to_qemu(name, variants): + ret =3D mcgen(''' + +pub enum %(rs_name)sCEnum<'a> { +''', rs_name=3Drs_name(name)) + + none_arms =3D '' + full_arms =3D '' + for var in variants.variants: + var_name =3D to_camel_case(rs_name(var.name, False)) + type_name =3D var.type.name + if type_name =3D=3D 'q_empty': + continue + if type_name.endswith('-wrapper'): + type_name =3D type_name[6:-8] + ret +=3D mcgen(''' + %(var_name)s(<%(rs_type)s as ToQemuPtr<'a, *mut %(rs_systype)s>>::Stor= age), +''', var_name=3Dvar_name, rs_type=3Drs_type(type_name, ''), rs_systype=3Dr= s_systype(type_name)) + none_arms +=3D mcgen(''' + %(rs_name)sEnum::%(var_name)s(v) =3D> { + let stash_ =3D v.to_qemu_none(); + (stash_.0 as *mut std::ffi::c_void, %(rs_name)sCEnum::%(v= ar_name)s(stash_.1)) + }, +''', rs_name=3Drs_name(name), var_name=3Dvar_name) + full_arms +=3D mcgen(''' + %(rs_name)sEnum::%(var_name)s(v) =3D> { + let ptr =3D v.to_qemu_full(); + ptr as *mut std::ffi::c_void + }, +''', rs_name=3Drs_name(name), var_name=3Dvar_name) + + ret +=3D mcgen(''' +} + +impl QemuPtrDefault for %(rs_name)sEnum { + type QemuType =3D *mut std::ffi::c_void; +} + +impl<'a> ToQemuPtr<'a, *mut std::ffi::c_void> for %(rs_name)sEnum { + type Storage =3D %(rs_name)sCEnum<'a>; + + #[inline] + fn to_qemu_none(&'a self) -> Stash<'a, *mut std::ffi::c_void, %(rs_nam= e)sEnum> { + 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 + } + } +} +''', rs_name=3Drs_name(name), none_arms=3Dnone_arms, full_arms=3Dfull_arms) + return ret + + +def gen_rs_variants(name, variants): + ret =3D mcgen(''' + +#[derive(Clone,Debug)] +pub enum %(rs_name)sEnum { +''', rs_name=3Drs_name(name)) + + kind_arms =3D '' + for var in variants.variants: + if var.ifcond: + raise NotImplementedError("ifcond are not implemented") + type_name =3D var.type.name + var_name =3D to_camel_case(rs_name(var.name, False)) + if type_name =3D=3D 'q_empty': + continue + if type_name.endswith('-wrapper'): + type_name =3D type_name[6:-8] # remove q_obj*-wrapper + kind_arms +=3D mcgen(''' + Self::%(var_name)s(_) =3D> { %(rs_name)sKind::%(var_name)s }, +''', var_name=3Dvar_name, rs_name=3Drs_name(name)) + ret +=3D mcgen(''' + %(var_name)s(%(rs_type)s), +''', var_name=3Dvar_name, rs_type=3Drs_type(type_name, '')) + + ret +=3D mcgen(''' +} +''') + + ret +=3D gen_rs_variants_enum_kind(name, kind_arms) + ret +=3D gen_rs_variants_to_qemu(name, variants) + # TODO FromQemu + return ret + + +def gen_rs_object_to_qemu(name, base, members, variants): + storage =3D [] + stash =3D [] + sys_memb =3D [] + memb_none =3D '' + memb_full =3D '' + for memb in members: + memb_name =3D rs_name(memb.name) + c_type =3D memb.type.c_type() + (is_pointer, _, is_list, _) =3D rs_ctype_parse(c_type) + if is_pointer: + t =3D rs_type(memb.type.c_type(), optional=3Dmemb.optional, ns= =3D'') + p =3D rs_systype(memb.type.c_type(), list_as_newp=3DTrue) + s =3D "Stash<'a, %s, %s>" % (p, t) + storage.append(s) + if memb.optional: + has_memb_name =3D 'has_%s' % rs_name(memb.name, protect=3DFals= e) + sys_memb.append(has_memb_name) + has_memb =3D mcgen(''' + let %(has_memb_name)s =3D self.%(memb_name)s.is_some(); +''', 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({})'.format(memb_name) if is_list else memb_na= me + 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()' + memb =3D mcgen(''' + let %(memb_name)s =3D self.%(memb_name)s%(unwrap)s; +''', memb_name=3Dmemb_name, unwrap=3Dunwrap) + memb_none +=3D memb + memb_full +=3D memb + + sys_memb.append(memb_name) + + if variants: + tag_name =3D rs_name(variants.tag_member.name) + sys_memb.append(tag_name) + sys_memb.append('u') + p =3D '*mut std::ffi::c_void' + s =3D "Stash<'a, %s, %sEnum>" % (p, name) + storage.append(s) + tag =3D mcgen(''' + let %(tag_name)s =3D self.u.kind(); +''', sys=3Drs_systype(name), tag_name=3Dtag_name) + memb_none +=3D tag + memb_full +=3D tag + arms =3D '' + for var in variants.variants: + if var.type.name =3D=3D 'q_empty': + continue + arms +=3D mcgen('%(rs_name)sEnum::%(kind_name)s(_) =3D> qapi_s= ys::%(rs_name)sUnion { %(var_name)s: %(var_type)s { data: u_ptr_ as *mut _ = } },', + rs_name=3Drs_name(name), kind_name=3Dto_camel_ca= se(var.name), var_name=3Drs_name(var.name), var_type=3Drs_systype(var.type.= c_name())) + memb_none +=3D mcgen(''' + let u_stash_ =3D self.u.to_qemu_none(); + let u_ptr_ =3D u_stash_.0; + let u =3D match self.u { + %(arms)s + }; +''', arms=3Darms) + 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 + }; +''', arms=3Darms) + + return mcgen(''' + +impl QemuPtrDefault for %(rs_name)s { + type QemuType =3D *mut qapi_sys::%(rs_name)s; +} + +impl<'a> ToQemuPtr<'a, *mut qapi_sys::%(rs_name)s> for %(rs_name)s { + type Storage =3D (Box, %(storage)s); + + #[inline] + fn to_qemu_none(&'a self) -> Stash<'a, *mut qapi_sys::%(rs_name)s, %(r= s_name)s> { + %(memb_none)s + let mut box_ =3D Box::new(qapi_sys::%(rs_name)s { %(sys_memb)s }); + + Stash(&mut *box_, (box_, %(stash)s)) + } + + #[inline] + fn to_qemu_full(&self) -> *mut qapi_sys::%(rs_name)s { + unsafe { + %(memb_full)s + let ptr =3D sys::g_malloc0(std::mem::size_of::<*const %(rs_nam= e)s>()) as *mut _; + *ptr =3D qapi_sys::%(rs_name)s { %(sys_memb)s }; + ptr + } + } +} +''', + rs_name=3Drs_name(name), storage=3D', '.join(storage), + sys_memb=3D', '.join(sys_memb), memb_none=3Dmemb_none, me= mb_full=3Dmemb_full, stash=3D', '.join(stash)) + + +def gen_rs_object_from_qemu(name, base, members, variants): + memb_names =3D [] + if base: + memb_names.extend([rs_name(memb.name) for memb in base.members]) + memb_names.extend([rs_name(memb.name) for memb in members]) + + ret =3D mcgen(''' +} + +impl FromQemuPtrFull<*mut qapi_sys::%(rs_name)s> for %(rs_name)s { + unsafe fn from_qemu_full(sys: *mut qapi_sys::%(rs_name)s) -> Self { + let ret =3D from_qemu_none(sys as *const _); + qapi_sys::qapi_free_%(rs_name)s(sys); + ret + } +} + +impl FromQemuPtrNone<*const qapi_sys::%(rs_name)s> for %(rs_name)s { + unsafe fn from_qemu_none(sys: *const qapi_sys::%(rs_name)s) -> Self { + let sys =3D & *sys; +''', rs_name=3Drs_name(name)) + + for memb in members: + memb_name =3D rs_name(memb.name) + val =3D from_qemu('sys.' + memb_name, memb.type.c_type()) + if memb.optional: + val =3D mcgen('''{ + if sys.has_%(memb_name)s { + Some(%(val)s) + } else { + None + } +}''', memb_name=3Drs_name(memb.name, protect=3DFalse), val=3Dval) + + ret +=3D mcgen(''' + let %(memb_name)s =3D %(val)s; +''', memb_name=3Dmemb_name, val=3Dval) + + if variants: + arms =3D '' + for variant in variants.tag_member.type.member_names(): + arms +=3D mcgen(''' + %(enum)s::%(variant)s =3D> { %(rs_name)sEnum::%(variant)s(from= _qemu_none(sys.u.%(memb)s.data as *const _)) }, +''', enum=3Dvariants.tag_member.type.name, memb=3Drs_name(variant), + variant=3Dto_camel_case(variant), rs_name=3Drs_n= ame(name)) + ret +=3D mcgen(''' + let u =3D match sys.%(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 } + } +} +''', rs_name=3Drs_name(name), memb_names=3D', '.join(memb_names)) + return ret + + +def gen_struct_members(members): + ret =3D '' + for memb in members: + if memb.ifcond: + raise NotImplementedError("ifcond are not implemented") + rsname =3D rs_name(memb.name) + ret +=3D mcgen(''' + pub %(rs_name)s: %(rs_type)s, +''', + rs_type=3Drs_type(memb.type.c_type(), '', optional=3D= memb.optional), rs_name=3Drsname) + return ret + + +def gen_rs_object(name, base, members, variants): + 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, variants) + + ret +=3D mcgen(''' + +#[derive(Clone, Debug)] +pub struct %(rs_name)s { +''', + rs_name=3Drs_name(name)) + + if base: + if not base.is_implicit(): + ret +=3D mcgen(''' + // Members inherited: +''', + c_name=3Dbase.c_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)sEnum, +''', rs_type=3Dname) + + ret +=3D gen_rs_object_from_qemu(name, base, members, variants) + ret +=3D gen_rs_object_to_qemu(name, base, members, variants) + return ret + + +def gen_rs_alternate(name, variants): + if name in objects_seen: + return '' + + ret =3D '' + objects_seen.add(name) + + ret +=3D mcgen(''' + +#[derive(Clone,Debug)] +pub enum %(rs_name)s { +''', + rs_name=3Drs_name(name)) + + for var in variants.variants: + if var.ifcond: + raise NotImplementedError("ifcond are not implemented") + if var.type.name =3D=3D 'q_empty': + continue + ret +=3D mcgen(''' + %(mem_name)s(%(rs_type)s), +''', + rs_type=3Drs_type(var.type.c_unboxed_type(), ''), + mem_name=3Dto_camel_case(rs_name(var.name))) + ret +=3D mcgen(''' +} +''') + # TODO: add to/from conversion + return ret + + +def gen_rs_enum(name): + return mcgen(''' + +pub type %(rs_name)s =3D qapi_sys::%(rs_name)s; +''', rs_name=3Drs_name(name)) + + +class QAPISchemaGenRsTypeVisitor(QAPISchemaRsVisitor): + + def __init__(self, prefix): + super().__init__(prefix, 'qapi-types') + + def visit_begin(self, schema): + # 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 + +use crate::qapi_sys; + +''')) + + def visit_end(self): + for name in rs_lists: + self._gen.add(mcgen(''' + +vec_from_qemu!(%(rs)s, %(sys)s, qapi_free_%(sys)s); +vec_to_qemu!(%(rs)s, %(sys)s); +''', sys=3Dname, rs=3Dname[:-4])) + + def visit_command(self, name, info, ifcond, features, + arg_type, ret_type, gen, success_response, boxed, + allow_oob, allow_preconfig, coroutine): + if ifcond: + raise NotImplementedError("ifcond are not implemented") + if not gen: + return + # call from_qemu() to eventually register a list + if ret_type: + from_qemu('', ret_type.c_type()) + + def visit_object_type(self, name, info, ifcond, features, + base, members, variants): + if ifcond: + raise NotImplementedError("ifcond are not implemented") + if name.startswith('q_'): + return + self._gen.add(gen_rs_object(name, base, members, variants)) + + def visit_enum_type(self, name, info, ifcond, features, members, prefi= x): + if ifcond: + raise NotImplementedError("ifcond are not implemented") + self._gen.add(gen_rs_enum(name)) + + def visit_alternate_type(self, name, info, ifcond, features, variants): + if ifcond: + raise NotImplementedError("ifcond are not implemented") + self._gen.add(gen_rs_alternate(name, variants)) + + +def gen_rs_types(schema, output_dir, prefix, opt_builtins): + vis =3D QAPISchemaGenRsTypeVisitor(prefix) + schema.visit(vis) + vis.write(output_dir) --=20 2.28.0 From nobody Mon May 13 11:48:03 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 ARC-Seal: i=1; a=rsa-sha256; t=1602448890; cv=none; d=zohomail.com; s=zohoarc; b=mKm6l+aWLuOFaOLbPGpjhafe8y0+jC0Xd6UiEUJ6dIcV812bUebS7Pm3YOyYtZEmleFJyLrxAPiNaDUpNYoTh6w0PmxOZDT+5Wid0+r2gcwF/dVe3izKF1IJ+tWcrDoBVMwIOT6R66gHlzxggusufEmcJH5B6OrzKMjv23vagfk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602448890; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=69CoiKyBWo9QUtUgrmlNSSXEFQ/HwyM1UPy3Ni4+k5o=; b=kfUgTvhi73iIYv1I3GLfU3hrtOO2mt5LHGUVKWIKrYZTRqB182xTnzy6uyVdYB+eMEyltqhUL1c9GTYYiAxkyuBLruRXQvDGZ5T4CgnfARK6Q/5f2F7TP4V1peohPg3kt0Vrjsbj3TWEtIe5HS+Q07u3LqAvMh8Ixh8hJidS92E= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602448890810368.53714514121987; Sun, 11 Oct 2020 13:41:30 -0700 (PDT) Received: from localhost ([::1]:40070 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kRi9p-0000hZ-HR for importer@patchew.org; Sun, 11 Oct 2020 16:41:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57660) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kRi5b-0001sq-L6 for qemu-devel@nongnu.org; Sun, 11 Oct 2020 16:37:08 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:54990) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kRi5Z-0005Xk-Vl for qemu-devel@nongnu.org; Sun, 11 Oct 2020 16:37:07 -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-6spTaWbmOBi5GRZj5l5xsw-1; Sun, 11 Oct 2020 16:37:01 -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 E3F4B107ACF5 for ; Sun, 11 Oct 2020 20:37:00 +0000 (UTC) Received: from localhost (unknown [10.36.110.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4C5097512E; Sun, 11 Oct 2020 20:36:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602448624; 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=69CoiKyBWo9QUtUgrmlNSSXEFQ/HwyM1UPy3Ni4+k5o=; b=NfInWK1bam9QojfNajg3sJMDbKwHKUwr6lo6I/EvbaK2X8e8zWIa9ouurNPSad0ZHaDZ8s ZxT+R35i+PMeqkM79AQK9ZBM4bBjEXbgPJyH9NMiSsRIjEgffFWWgPdJ5Vqpkno4A5XT0S LGwGWh40P4rM2smraTo9Q0J4cAkT3uA= X-MC-Unique: 6spTaWbmOBi5GRZj5l5xsw-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [PoCv2 10/15] qga/rust: build Rust types Date: Mon, 12 Oct 2020 00:35:08 +0400 Message-Id: <20201011203513.1621355-11-marcandre.lureau@redhat.com> In-Reply-To: <20201011203513.1621355-1-marcandre.lureau@redhat.com> References: <20201011203513.1621355-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=63.128.21.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/11 16:23:51 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=-1, RCVD_IN_MSPIKE_WL=-0.01, 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) 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 050a47e2a3..bff4107569 100644 --- a/qga/lib.rs +++ b/qga/lib.rs @@ -1 +1,2 @@ +mod qapi; mod qapi_sys; diff --git a/qga/meson.build b/qga/meson.build index dbc8f1623b..aedbd07a04 100644 --- a/qga/meson.build +++ b/qga/meson.build @@ -49,6 +49,7 @@ qga_rs =3D declare_dependency() if with_rust qga_qapi_rs_outputs =3D [ 'qga-qapi-sys-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.28.0 From nobody Mon May 13 11:48:03 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 ARC-Seal: i=1; a=rsa-sha256; t=1602449098; cv=none; d=zohomail.com; s=zohoarc; b=h4t0TuMDQFt5xzyfMDqchF5aXJOZGtO02/Ai9BSYAmskkJ8O4Mqk45Tta2XwJlj/3PgmSui9Kl7bNhT5HUqwGnb+lVWtTUvwpXCVcfv5tGc9H9AsujAjfWbPuAvbBTZ/DhRwFRpFmyrnQ5BqQbNzdS3cLqCTKwOi14KJtA3Yqu0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602449098; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=XlKLzn5XQx+MgQAM4EHXhVcJekM1LfEac+tlMU7Ov/E=; b=Uvt44UsATCblvcmhrZR+9Cs0Ep5Dv8mEB9i7wkM1cbDbePVkpHWdNFEYFA1JhgzR9qpp/K0l1ONMz95gxvERXtZOSpoVOLJwFrgNfa2mPMA+DrxepVFXJIEW6+7eqg5b53ZB2FpNXTpYDVeJkoY3HMrsiP2rD/mgBgN+IqE/8IY= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16024490981531016.273823019464; Sun, 11 Oct 2020 13:44:58 -0700 (PDT) Received: from localhost ([::1]:48304 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kRiD9-0004RE-1t for importer@patchew.org; Sun, 11 Oct 2020 16:44:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57750) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kRi5k-00027Z-BI for qemu-devel@nongnu.org; Sun, 11 Oct 2020 16:37:16 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:46907) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kRi5i-0005ZP-M0 for qemu-devel@nongnu.org; Sun, 11 Oct 2020 16:37: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-100-tbs0h5hQO9S8vGCEgpbzTg-1; Sun, 11 Oct 2020 16:37:12 -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 42468802B4A for ; Sun, 11 Oct 2020 20:37:11 +0000 (UTC) Received: from localhost (unknown [10.36.110.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id EC5B660C05; Sun, 11 Oct 2020 20:37:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602448633; 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=XlKLzn5XQx+MgQAM4EHXhVcJekM1LfEac+tlMU7Ov/E=; b=I7X17C6smd4vtpBWPnXTsTPr40hZyxZAltHebzhRwc0/t7GQy+HMuvHFNyJrHX+y9e/b+X ood9S8O8HbFDEEs0L0nmznNB08yU+ajQZewFc87KoAIwyoCVKtmnh6M1gl7oc4ON7z1xkD b2fr9diMJt4sUoCpBIXZ+sOZWqbRTOk= X-MC-Unique: tbs0h5hQO9S8vGCEgpbzTg-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [PoCv2 11/15] qga: add qmp! macro helper Date: Mon, 12 Oct 2020 00:35:09 +0400 Message-Id: <20201011203513.1621355-12-marcandre.lureau@redhat.com> In-Reply-To: <20201011203513.1621355-1-marcandre.lureau@redhat.com> References: <20201011203513.1621355-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=63.128.21.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/11 16:23:51 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=-1, RCVD_IN_MSPIKE_WL=-0.01, 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) From: Marc-Andr=C3=A9 Lureau Add a macro to help wrapping higher-level qmp handlers, by taking care of errors and return value pointer translation. Signed-off-by: Marc-Andr=C3=A9 Lureau --- qga/lib.rs | 1 + qga/qmp/mod.rs | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 qga/qmp/mod.rs diff --git a/qga/lib.rs b/qga/lib.rs index bff4107569..5fe08c25a3 100644 --- a/qga/lib.rs +++ b/qga/lib.rs @@ -1,2 +1,3 @@ mod qapi; mod qapi_sys; +mod qmp; diff --git a/qga/qmp/mod.rs b/qga/qmp/mod.rs new file mode 100644 index 0000000000..38060100af --- /dev/null +++ b/qga/qmp/mod.rs @@ -0,0 +1,36 @@ +use common::*; + +use crate::*; + +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() + }, + } + }}; +} --=20 2.28.0 From nobody Mon May 13 11:48:03 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 ARC-Seal: i=1; a=rsa-sha256; t=1602449318; cv=none; d=zohomail.com; s=zohoarc; b=aIa9WAImrqfaVWACq0YH2DG07A2hYCkjN/2L8qfoS6V/h7nm4aH+ewrExqF0/qvjHR9SZEnBmfTt85NH0m7FcU13qvN3zWEssS/AOezwJW2jjmN12T4Qdr/YJT3bONowq+Hne6XQ+h6k4L2yHcgMdHirwQhsBB4GazrlQwQuShQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602449318; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=tMbEFUjxPSyAU3nqy9BsI64+jEiY61NYPw2mnJQxISc=; b=a1r0WIAoYLN60MTpNuskrgI0KgQ2AXStNfx1CeW9fe7vtnp7Og3okI4OUVJ9Tl6IxnMrf74mCLcblVqqy1chTgu50L4r/Qp2rT2CIZBTNz0oGhlbzsYVbkvPt2uV2/YlZGR0xcv5RK96Ll/EJG6PXeCrAw5igdez7tMcuTc3XUw= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602449318141184.98861108830454; Sun, 11 Oct 2020 13:48:38 -0700 (PDT) Received: from localhost ([::1]:56676 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kRiGj-00083J-0s for importer@patchew.org; Sun, 11 Oct 2020 16:48:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57802) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kRi5y-0002G6-Tt for qemu-devel@nongnu.org; Sun, 11 Oct 2020 16:37:32 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:31717) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kRi5u-0005Zv-Jg for qemu-devel@nongnu.org; Sun, 11 Oct 2020 16:37:30 -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-355-zhsTWrE0OyuzUIeZtOWrHg-1; Sun, 11 Oct 2020 16:37:22 -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 D5617802B4A for ; Sun, 11 Oct 2020 20:37:21 +0000 (UTC) Received: from localhost (unknown [10.36.110.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id CD9771A8EC; Sun, 11 Oct 2020 20:37:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602448646; 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=tMbEFUjxPSyAU3nqy9BsI64+jEiY61NYPw2mnJQxISc=; b=KWw6Uay2My7yAixoM1SOKpKd2V70FvVQ+xL8JbUnY9dof3y1JSIqvj+oM/Krptcv41XWgL 4wQg4DFHs26k+phDPj8lFa9ClDbkOAOLDHvo5/WMWN2hEKnpKc2fJEm7djlLTmKxIBoZgY B19EGckYxFvR6ye4S8GliNv9uuVllrM= X-MC-Unique: zhsTWrE0OyuzUIeZtOWrHg-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [PoCv2 12/15] qga: implement get-host-name in Rust Date: Mon, 12 Oct 2020 00:35:10 +0400 Message-Id: <20201011203513.1621355-13-marcandre.lureau@redhat.com> In-Reply-To: <20201011203513.1621355-1-marcandre.lureau@redhat.com> References: <20201011203513.1621355-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=216.205.24.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/11 16:35:36 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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) 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/Cargo.toml | 1 + qga/commands.c | 20 ++++---------------- qga/lib.rs | 2 ++ qga/qmp/hostname.rs | 9 +++++++++ qga/qmp/mod.rs | 7 +++++++ tests/test-qga.c | 2 ++ util/oslib-posix.c | 35 ----------------------------------- util/oslib-win32.c | 13 ------------- 9 files changed, 25 insertions(+), 74 deletions(-) create mode 100644 qga/qmp/hostname.rs diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index f9ec8c84e9..1ea244fc06 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -664,16 +664,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/Cargo.toml b/qga/Cargo.toml index 9966057594..63a419255d 100644 --- a/qga/Cargo.toml +++ b/qga/Cargo.toml @@ -7,6 +7,7 @@ license =3D "GPLv2" [dependencies] common =3D { path =3D "../rust/common" } libc =3D "^0.2.76" +hostname =3D "^0.3.1" =20 [lib] path =3D "lib.rs" diff --git a/qga/commands.c b/qga/commands.c index 3dcd5fbe5c..15478a16e7 100644 --- a/qga/commands.c +++ b/qga/commands.c @@ -512,25 +512,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/qga/lib.rs b/qga/lib.rs index 5fe08c25a3..f4967f59e5 100644 --- a/qga/lib.rs +++ b/qga/lib.rs @@ -1,3 +1,5 @@ +pub use common::{err, Error, Result}; + mod qapi; mod qapi_sys; 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 index 38060100af..e855aa4bd7 100644 --- a/qga/qmp/mod.rs +++ b/qga/qmp/mod.rs @@ -34,3 +34,10 @@ macro_rules! qmp { } }}; } + +mod hostname; + +#[no_mangle] +extern "C" fn qmp_guest_get_host_name(errp: *mut *mut sys::Error) -> *mut = qapi_sys::GuestHostName { + qmp!(hostname::get(), errp) +} diff --git a/tests/test-qga.c b/tests/test-qga.c index c1b173b3cb..6190e93e0e 100644 --- a/tests/test-qga.c +++ b/tests/test-qga.c @@ -863,6 +863,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 @@ -874,6 +875,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 f15234b5c0..1722c269b8 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -804,41 +804,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 051afb217b..804e303c4f 100644 --- a/util/oslib-win32.c +++ b/util/oslib-win32.c @@ -822,19 +822,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; --=20 2.28.0 From nobody Mon May 13 11:48:03 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 ARC-Seal: i=1; a=rsa-sha256; t=1602449248; cv=none; d=zohomail.com; s=zohoarc; b=V87r1Kz/9FJiLWnavoG6G53vBzTcSaSnE3LTINr8SNsZAoJtIMknJDvAlX3p+xvYmlyl5U920yHseadS+pc1/RBvJyP/IHTvKZQkpJqSsBXNg9J32ZmDsR6fw8q07C90TT/Q48xMCiiMZsi6PSyUwyQY0jdFgmXruQRSUMI49BM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602449248; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=tBSHczW2Lzk3cLtx36KBC74qLkYR3CoBuZtx44+ZG+w=; b=BLTyg2QK641MyTZtpItXapbkMYl04JfQjw4javbBOl0PgDcfX2AKuiKdlG+GGyFUeaxhXe/pMcpTMC+JwAM9XqMvmwvK7VFGuIi38yeYl0NkzToH6xOnT+zVKY0/YsZYK6REgFO6UMRpwzchSWylhVfaDiBtZLI/9SLH8E4I2oc= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 160244924842293.96399455643962; Sun, 11 Oct 2020 13:47:28 -0700 (PDT) Received: from localhost ([::1]:54738 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kRiFa-0007E5-1U for importer@patchew.org; Sun, 11 Oct 2020 16:47:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57866) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kRi67-0002TA-9S for qemu-devel@nongnu.org; Sun, 11 Oct 2020 16:37:39 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:36044) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kRi64-0005b7-W3 for qemu-devel@nongnu.org; Sun, 11 Oct 2020 16:37:38 -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-316-gFLx1wC3M2CNkhiBFWngew-1; Sun, 11 Oct 2020 16:37:33 -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 D847A185A0DD for ; Sun, 11 Oct 2020 20:37:32 +0000 (UTC) Received: from localhost (unknown [10.36.110.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id 98FCD100239A; Sun, 11 Oct 2020 20:37:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602448656; 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=tBSHczW2Lzk3cLtx36KBC74qLkYR3CoBuZtx44+ZG+w=; b=O5vB2qgoN/MEZLtnbrHFo0OT0/Qt/bwJ2JEtyy2Zuav4/kudXfs5kZWzAGGZfiHcE05NIR 08QianhJD3s7Qd12MopFyNswhiqsGDdhBLErTm+/nnHSmXMGVpz1EtReXb9Fkw3GNVTvpf kn54fuLJS6Kyel/0nD+GuUDVXaEYk7c= X-MC-Unique: gFLx1wC3M2CNkhiBFWngew-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [PoCv2 13/15] qga: implement {get,set}-vcpus in Rust Date: Mon, 12 Oct 2020 00:35:11 +0400 Message-Id: <20201011203513.1621355-14-marcandre.lureau@redhat.com> In-Reply-To: <20201011203513.1621355-1-marcandre.lureau@redhat.com> References: <20201011203513.1621355-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=63.128.21.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/11 16:23:51 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_NONE=-0.0001, RCVD_IN_MSPIKE_H5=-1, RCVD_IN_MSPIKE_WL=-0.01, 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) 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/Cargo.toml | 6 ++ qga/commands-posix.c | 159 ------------------------------------------ qga/commands-win32.c | 76 -------------------- qga/commands.c | 14 ++++ qga/qmp/mod.rs | 18 +++++ qga/qmp/vcpus.rs | 161 +++++++++++++++++++++++++++++++++++++++++++ tests/test-qga.c | 2 + 7 files changed, 201 insertions(+), 235 deletions(-) create mode 100644 qga/qmp/vcpus.rs diff --git a/qga/Cargo.toml b/qga/Cargo.toml index 63a419255d..bb86fc543d 100644 --- a/qga/Cargo.toml +++ b/qga/Cargo.toml @@ -9,6 +9,12 @@ common =3D { path =3D "../rust/common" } libc =3D "^0.2.76" hostname =3D "^0.3.1" =20 +[target."cfg(unix)".dependencies] +nix =3D "^0.18.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/commands-posix.c b/qga/commands-posix.c index 3bffee99d4..2c2c97fbca 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -2092,165 +2092,6 @@ error: return NULL; } =20 -#define SYSCONF_EXACT(name, errp) sysconf_exact((name), #name, (errp)) - -static long sysconf_exact(int name, const char *name_str, Error **errp) -{ - long ret; - - errno =3D 0; - ret =3D sysconf(name); - if (ret =3D=3D -1) { - if (errno =3D=3D 0) { - error_setg(errp, "sysconf(%s): value indefinite", name_str); - } else { - error_setg_errno(errp, errno, "sysconf(%s)", name_str); - } - } - return ret; -} - -/* 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) -{ - int64_t current; - GuestLogicalProcessorList *head, **link; - long sc_max; - Error *local_err =3D NULL; - - current =3D 0; - head =3D NULL; - link =3D &head; - sc_max =3D SYSCONF_EXACT(_SC_NPROCESSORS_CONF, &local_err); - - while (local_err =3D=3D NULL && current < sc_max) { - GuestLogicalProcessor *vcpu; - GuestLogicalProcessorList *entry; - int64_t id =3D current++; - char *path =3D g_strdup_printf("/sys/devices/system/cpu/cpu%" PRId= 64 "/", - id); - - if (g_file_test(path, G_FILE_TEST_EXISTS)) { - 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); - entry =3D g_malloc0(sizeof *entry); - entry->value =3D vcpu; - *link =3D entry; - link =3D &entry->next; - } - g_free(path); - } - - 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, diff --git a/qga/commands-win32.c b/qga/commands-win32.c index 0c3c05484f..1e140b68a6 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -1740,82 +1740,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, **link; - Error *local_err =3D NULL; - int64_t current; - - ptr =3D pslpi =3D NULL; - length =3D 0; - current =3D 0; - head =3D NULL; - link =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; - GuestLogicalProcessorList *entry; - - vcpu =3D g_malloc0(sizeof *vcpu); - vcpu->logical_id =3D current++; - vcpu->online =3D true; - vcpu->has_can_offline =3D true; - - entry =3D g_malloc0(sizeof *entry); - entry->value =3D vcpu; - - *link =3D entry; - link =3D &entry->next; - } - 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 15478a16e7..a5f8e32ece 100644 --- a/qga/commands.c +++ b/qga/commands.c @@ -577,3 +577,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/qga/qmp/mod.rs b/qga/qmp/mod.rs index e855aa4bd7..7c4d30c7de 100644 --- a/qga/qmp/mod.rs +++ b/qga/qmp/mod.rs @@ -41,3 +41,21 @@ mod hostname; extern "C" fn qmp_guest_get_host_name(errp: *mut *mut sys::Error) -> *mut = qapi_sys::GuestHostName { qmp!(hostname::get(), errp) } + +mod vcpus; + +#[no_mangle] +extern "C" fn qmp_guest_get_vcpus( + errp: *mut *mut sys::Error, +) -> *mut qapi_sys::GuestLogicalProcessorList { + qmp!(vcpus::get(), errp) +} + +#[no_mangle] +extern "C" fn qmp_guest_set_vcpus( + vcpus: *const qapi_sys::GuestLogicalProcessorList, + errp: *mut *mut sys::Error, +) -> libc::c_longlong { + let vcpus =3D unsafe { from_qemu_none(qapi::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") +} diff --git a/tests/test-qga.c b/tests/test-qga.c index 6190e93e0e..ff1807531c 100644 --- a/tests/test-qga.c +++ b/tests/test-qga.c @@ -307,6 +307,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; @@ -323,6 +324,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) --=20 2.28.0 From nobody Mon May 13 11:48:03 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 ARC-Seal: i=1; a=rsa-sha256; t=1602448854; cv=none; d=zohomail.com; s=zohoarc; b=X35fHp2gYPpDhZa4PPKcKb7+EMQ38UYFHxI8obwwVxbmNpYfTXu4076lS2r5bm8f/Xg9AzvyUThbnvdyZKnMurSKiICY7nvttD+VESESTTzdMYByqQOXFCtw16pQsWHXZjpo+lPnExYaF4jYE/5gSZORUrgQ5FxrhiMEvLrbLd8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602448854; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=TeY7imNTlzyA8qZI2q/5+3WkBmAybf/f5KVeNklE1XM=; b=lJcGk1H0evNxDIKhoN8CdTMA7qG4mSzQfM7CH+D+YHxfUskUz3rr9EdOA1HcnXHC//fI7PSOPuz90+XQmCfWqVtjIx9CeQ6ZT5FeMcI26LHKHllzAem5XrGHr72VBvDw+T+8HUNcUF8AZWKJqLNqGp/XJzRQder5e8AaZlmvkx8= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602448854190407.3794480036646; Sun, 11 Oct 2020 13:40:54 -0700 (PDT) Received: from localhost ([::1]:38114 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kRi9F-00086v-4K for importer@patchew.org; Sun, 11 Oct 2020 16:40:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57886) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kRi6F-0002ng-Mq for qemu-devel@nongnu.org; Sun, 11 Oct 2020 16:37:47 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:53464) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kRi6E-0005bl-0M for qemu-devel@nongnu.org; Sun, 11 Oct 2020 16:37:47 -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-197-ew21iFf0NUmw6x9cUr-yAw-1; Sun, 11 Oct 2020 16:37:43 -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 ABC31185A0C0 for ; Sun, 11 Oct 2020 20:37:42 +0000 (UTC) Received: from localhost (unknown [10.36.110.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id 718F26EF66; Sun, 11 Oct 2020 20:37:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602448665; 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=TeY7imNTlzyA8qZI2q/5+3WkBmAybf/f5KVeNklE1XM=; b=K9taYZpN5y0CX72mik41Q/SgZQEaMKNQoliwxln6q07EncVg5Ro1vxpVKJzq32WVQ7P2nT YSSbRnMj4Emr5J0QhyoB6U3y28ZdL/1KgRTxTQyoEDwp3qg5GnN7+nIXFIOI2aeL63DmQ3 7dvoE1A88W2rlgly4CgV79CozI93vXU= X-MC-Unique: ew21iFf0NUmw6x9cUr-yAw-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [PoCv2 14/15] travis: add Rust Date: Mon, 12 Oct 2020 00:35:12 +0400 Message-Id: <20201011203513.1621355-15-marcandre.lureau@redhat.com> In-Reply-To: <20201011203513.1621355-1-marcandre.lureau@redhat.com> References: <20201011203513.1621355-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-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/11 16:35:36 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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) From: Marc-Andr=C3=A9 Lureau Signed-off-by: Marc-Andr=C3=A9 Lureau --- .travis.yml | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 1054ec5d29..b2835316bc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,6 +23,8 @@ addons: apt: packages: # Build dependencies + - cargo + - rustc - libaio-dev - libattr1-dev - libbrlapi-dev @@ -71,7 +73,7 @@ env: global: - SRC_DIR=3D".." - BUILD_DIR=3D"build" - - BASE_CONFIG=3D"--disable-docs --disable-tools" + - BASE_CONFIG=3D"--disable-docs --disable-tools --with-rust" - TEST_BUILD_CMD=3D"" - TEST_CMD=3D"make check V=3D1" # This is broadly a list of "mainline" softmmu targets which have supp= ort across the major distros @@ -258,6 +260,8 @@ jobs: # Extra toolchains - gcc-9 - g++-9 + - cargo + - rustc # Build dependencies - libaio-dev - libattr1-dev @@ -325,6 +329,8 @@ jobs: dist: focal addons: apt_packages: + - cargo + - rustc - libaio-dev - libattr1-dev - libbrlapi-dev @@ -358,6 +364,8 @@ jobs: dist: focal addons: apt_packages: + - cargo + - rustc - libaio-dev - libattr1-dev - libbrlapi-dev @@ -390,6 +398,8 @@ jobs: dist: bionic addons: apt_packages: + - cargo + - rustc - libaio-dev - libattr1-dev - libbrlapi-dev @@ -432,6 +442,8 @@ jobs: dist: bionic addons: apt_packages: + - cargo + - rustc - libaio-dev - libattr1-dev - libcap-ng-dev @@ -461,6 +473,8 @@ jobs: dist: bionic addons: apt_packages: + - cargo + - rustc - libgcrypt20-dev - libgnutls28-dev env: @@ -472,6 +486,8 @@ jobs: compiler: clang addons: apt_packages: + - cargo + - rustc - libaio-dev - libattr1-dev - libbrlapi-dev --=20 2.28.0 From nobody Mon May 13 11:48:03 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 ARC-Seal: i=1; a=rsa-sha256; t=1602449432; cv=none; d=zohomail.com; s=zohoarc; b=B6b6FwaZpl1tYD/ysfLEj3MFNocyYw0INUEpZxr24uRXAF6WWUEZQLqBB41lG+Qnl08SIwPeYqM3v2vzMBVHNyHSAV6bBS8KmJmqIoP8+XiVdhpX2J2EEdUK/otxJVs4P2NqLTV6HtB7e+pQmErbVSKIGviy8X1T7N+rL/ErpSU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602449432; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=voPjCiZWVDBPQH65LrK+W3HZpGd+P96aarosFlVdCOo=; b=J11aZ4nYjrxFgjX6/esKVmVN2IFs+XZSQ6irXwcJftXZput39Xbcd0EYGXmr6T3TRw7pymvTAl5opkX1EnfakA8d5y5i0KYMA97MMY9SUxwZ7YK1IOgj6khtrwjmdtFXiPx3urZvYVIknRPuOIEGxD/9MRBKBnEjpQNxDtkBbz8= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602449432519869.4682785241068; Sun, 11 Oct 2020 13:50:32 -0700 (PDT) Received: from localhost ([::1]:33580 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kRiIZ-0001oE-Dg for importer@patchew.org; Sun, 11 Oct 2020 16:50:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57930) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kRi6R-0003FR-DE for qemu-devel@nongnu.org; Sun, 11 Oct 2020 16:37:59 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:50287) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kRi6P-0005cM-Eq for qemu-devel@nongnu.org; Sun, 11 Oct 2020 16:37:59 -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-534-ho2pcMK4P1-31mvpUrfFaA-1; Sun, 11 Oct 2020 16:37:53 -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 C1EBE185A0C0 for ; Sun, 11 Oct 2020 20:37:52 +0000 (UTC) Received: from localhost (unknown [10.36.110.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8733660C05; Sun, 11 Oct 2020 20:37:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602448676; 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=voPjCiZWVDBPQH65LrK+W3HZpGd+P96aarosFlVdCOo=; b=Z/YE4wHpkKlOUSG/gQ6vh+wYVjkNUd3f+PyFAJlsq6Kte4RePRV7iG3paMn+v/wtRsHRmP 43OecmKWaPFluMHlghgfYYjVIB6L+UBmCaENRsQxg98wjcDq+tXmIycbLuP1nWU2cMDf6T gTIwJeuxvvwoZcQ3wA0zpWFGXwUQB1g= X-MC-Unique: ho2pcMK4P1-31mvpUrfFaA-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [PoCv2 15/15] rust: use vendored-sources Date: Mon, 12 Oct 2020 00:35:13 +0400 Message-Id: <20201011203513.1621355-16-marcandre.lureau@redhat.com> In-Reply-To: <20201011203513.1621355-1-marcandre.lureau@redhat.com> References: <20201011203513.1621355-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=63.128.21.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/11 16:23:51 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=-1, RCVD_IN_MSPIKE_WL=-0.01, 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) 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. "cargo vendor" makes that simple. Signed-off-by: Marc-Andr=C3=A9 Lureau --- .cargo/config | 5 +++++ .gitmodules | 3 +++ configure | 8 ++++++++ rust/vendored | 1 + scripts/cargo_wrapper.py | 1 + 5 files changed, 18 insertions(+) create mode 100644 .cargo/config create mode 160000 rust/vendored diff --git a/.cargo/config b/.cargo/config new file mode 100644 index 0000000000..a8c55940d5 --- /dev/null +++ b/.cargo/config @@ -0,0 +1,5 @@ +[source.crates-io] +replace-with =3D "vendored-sources" + +[source.vendored-sources] +directory =3D "rust/vendored" diff --git a/.gitmodules b/.gitmodules index 2bdeeacef8..62a2be12b9 100644 --- a/.gitmodules +++ b/.gitmodules @@ -64,3 +64,6 @@ [submodule "roms/vbootrom"] path =3D roms/vbootrom url =3D https://git.qemu.org/git/vbootrom.git +[submodule "rust/vendored"] + path =3D rust/vendored + url =3D https://github.com/elmarco/qemu-rust-vendored.git diff --git a/configure b/configure index 7945ceac63..702546d87f 100755 --- a/configure +++ b/configure @@ -1932,6 +1932,14 @@ if test "$with_rust" =3D auto && has cargo; then with_rust=3Dyes fi =20 +case "$with_rust" in + yes) + if test -e "${source_path}/.git" && test $git_update =3D 'yes' ; 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/rust/vendored b/rust/vendored new file mode 160000 index 0000000000..71ee65d042 --- /dev/null +++ b/rust/vendored @@ -0,0 +1 @@ +Subproject commit 71ee65d042606d18de3175d67f9e4e4b78a1f865 diff --git a/scripts/cargo_wrapper.py b/scripts/cargo_wrapper.py index 164fad5123..4a0673407b 100644 --- a/scripts/cargo_wrapper.py +++ b/scripts/cargo_wrapper.py @@ -51,6 +51,7 @@ def build_lib(args: argparse.Namespace) -> None: target_dir, "--manifest-path", manifest_path, + "--offline", ] if args.target_triple: cargo_cmd +=3D ["--target", args.target_triple] --=20 2.28.0