qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Kevin Wolf <kwolf@redhat.com>
Cc: qemu-block@nongnu.org, hreitz@redhat.com,
	manos.pitsidianakis@linaro.org,  qemu-devel@nongnu.org,
	qemu-rust@nongnu.org
Subject: Re: [PATCH 03/11] rust: Add some block layer bindings
Date: Wed, 12 Feb 2025 18:16:09 +0100	[thread overview]
Message-ID: <a8e79f73-15d0-486c-99da-ad871a57e4ef@redhat.com> (raw)
In-Reply-To: <Z6y6nUo68dIkryOu@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 455 bytes --]

On 2/12/25 16:13, Kevin Wolf wrote:
> Or if you have to define the constants anyway - you currently do this
> only for Windows, but for into_negative_errno() you might need it on
> Linux, too - and it wouldn't be a problem for the constants to be
> signed (that they are unsigned is the main reason why it becomes so ugly
> with the bindgen constants), you could just make it -errno::EINVAL
> again.

Or just include the libc crate, see attachment.

Paolo

[-- Attachment #2: 0001-rust-subprojects-add-libc-crate.patch --]
[-- Type: text/x-patch, Size: 7529 bytes --]

From 526ad76001e788eb9adb2624eb4bbedae50301f9 Mon Sep 17 00:00:00 2001
From: Paolo Bonzini <pbonzini@redhat.com>
Date: Mon, 16 Dec 2024 09:42:35 +0100
Subject: [PATCH] rust: subprojects: add libc crate

This allows access to errno values.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 rust/Cargo.lock                               |  7 ++++
 rust/qemu-api/Cargo.toml                      |  1 +
 rust/qemu-api/src/errno.rs                    | 32 ++---------------
 scripts/archive-source.sh                     |  2 +-
 scripts/make-release                          |  4 +--
 subprojects/libc-0.2-rs.wrap                  |  7 ++++
 .../packagefiles/libc-0.2-rs/meson.build      | 36 +++++++++++++++++++
 7 files changed, 56 insertions(+), 33 deletions(-)
 create mode 100644 subprojects/libc-0.2-rs.wrap
 create mode 100644 subprojects/packagefiles/libc-0.2-rs/meson.build

diff --git a/rust/Cargo.lock b/rust/Cargo.lock
index bd22cc39c16..ac9806a1b4f 100644
--- a/rust/Cargo.lock
+++ b/rust/Cargo.lock
@@ -56,4 +56,10 @@ dependencies = [
  "either",
 ]
 
+[[package]]
+name = "libc"
+version = "0.2.162"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "18d287de67fe55fd7e1581fe933d965a5a9477b38e949cfa9f8574ef01506398"
+
 [[package]]
@@ -126,4 +132,5 @@ dependencies = [
 name = "qemu_api"
 version = "0.1.0"
 dependencies = [
+ "libc",
  "qemu_api_macros",
diff --git a/rust/qemu-api/meson.build b/rust/qemu-api/meson.build
index d273e5d903f..3708d97ae75 100644
--- a/rust/qemu-api/meson.build
+++ b/rust/qemu-api/meson.build
@@ -1,6 +1,8 @@
 _qemu_api_cfg = run_command(rustc_args,
   '--config-headers', config_host_h, '--features', files('Cargo.toml'),
   capture: true, check: true).stdout().strip().splitlines()
+
+libc_dep = dependency('libc-0.2-rs')
 
 if get_option('debug_mutex')
   _qemu_api_cfg += ['--cfg', 'feature="debug_cell"']
@@ -38,6 +38,7 @@ _qemu_api_rs = static_library(
   override_options: ['rust_std=2021', 'build.rust_std=2021'],
   rust_abi: 'rust',
   rust_args: _qemu_api_cfg,
+  link_with: libc_dep,
 )
 
 rust.test('rust-qemu-api-tests', _qemu_api_rs,
diff --git a/rust/qemu-api/Cargo.toml b/rust/qemu-api/Cargo.toml
index c96e87f592e..7255e9ee596 100644
--- a/rust/qemu-api/Cargo.toml
+++ b/rust/qemu-api/Cargo.toml
@@ -18,6 +18,7 @@ rust-version = "1.63.0"

 [dependencies]
 qemu_api_macros = { path = "../qemu-api-macros" }
+libc = "0.2.162"
 
 [build-dependencies]
 version_check = "~0.9"
diff --git a/rust/qemu-api/src/errno.rs b/rust/qemu-api/src/errno.rs
index c697f9bef05..58d46abc21c 100644
--- a/rust/qemu-api/src/errno.rs
+++ b/rust/qemu-api/src/errno.rs
@@ -16,32 +16,6 @@
 // into io::Error by hand.  For simplicity use ErrorKind and use
 // the standard library's simple-minded mapping of ErrorKind to Error
 // (`impl From<ErrorKind> for io::Error`).
-//
-// Since this is just for Windows, do not bother with using the libc
-// crate or generating the constants from C.  Just list here the
-// constants that map to stable error kinds.
-#[cfg(windows)]
-mod libc {
-    pub const EPERM: u16 = 1;
-    pub const ENOENT: u16 = 2;
-    pub const EINTR: u16 = 4;
-    pub const EAGAIN: u16 = 11;
-    pub const ENOMEM: u16 = 12;
-    pub const EACCES: u16 = 13;
-    pub const EEXIST: u16 = 17;
-    pub const EINVAL: u16 = 22;
-    pub const EPIPE: u16 = 32;
-    pub const EADDRINUSE: u16 = 100;
-    pub const EADDRNOTAVAIL: u16 = 101;
-    pub const ECONNABORTED: u16 = 106;
-    pub const ECONNREFUSED: u16 = 107;
-    pub const ECONNRESET: u16 = 108;
-    pub const ENOTCONN: u16 = 126;
-    pub const ENOTSUP: u16 = 129;
-    pub const ETIMEDOUT: u16 = 138;
-    pub const EWOULDBLOCK: u16 = 140;
-}
-
 impl From<Errno> for io::Error {
     #[cfg(unix)]
     fn from(value: Errno) -> io::Error {
@@ -52,13 +26,11 @@ fn from(value: Errno) -> io::Error {
     #[cfg(windows)]
     fn from(value: Errno) -> io::Error {
         let Errno(errno) = value;
-        let error_kind = match errno {
+        let error_kind = match errno as i32 {
             libc::EPERM | libc::EACCES => ErrorKind::PermissionDenied,
             libc::ENOENT => ErrorKind::NotFound,
             libc::EINTR => ErrorKind::Interrupted,
-            // Note that on Windows we know these two are distinct.  In general,
-            // it would not be possible to use "|".
-            libc::EAGAIN | libc::EWOULDBLOCK => ErrorKind::WouldBlock,
+            x if x == libc::EAGAIN || x == libc::EWOULDBLOCK => ErrorKind::WouldBlock,
             libc::ENOMEM => ErrorKind::OutOfMemory,
             libc::EEXIST => ErrorKind::AlreadyExists,
             libc::EINVAL => ErrorKind::InvalidInput,
diff --git a/scripts/archive-source.sh b/scripts/archive-source.sh
index e72bc7aa61e..00a1254ce8b 100755
--- a/scripts/archive-source.sh
+++ b/scripts/archive-source.sh
@@ -29,7 +29,7 @@ sub_file="${sub_tdir}/submodule.tar"
 # different to the host OS.
 subprojects="keycodemapdb libvfio-user berkeley-softfloat-3
   berkeley-testfloat-3 arbitrary-int-1-rs bilge-0.2-rs
-  bilge-impl-0.2-rs either-1-rs itertools-0.11-rs proc-macro2-1-rs
+  bilge-impl-0.2-rs either-1-rs itertools-0.11-rs libc-0.2-rs proc-macro2-1-rs
   proc-macro-error-1-rs proc-macro-error-attr-1-rs quote-1-rs
   syn-2-rs unicode-ident-1-rs"
 sub_deinit=""
diff --git a/scripts/make-release b/scripts/make-release
index 2acbfed8f2d..a53aebd1f1e 100755
--- a/scripts/make-release
+++ b/scripts/make-release
@@ -40,7 +40,7 @@ fi
 # Only include wraps that are invoked with subproject()
 SUBPROJECTS="libvfio-user keycodemapdb berkeley-softfloat-3
   berkeley-testfloat-3 arbitrary-int-1-rs bilge-0.2-rs
-  bilge-impl-0.2-rs either-1-rs itertools-0.11-rs
+  bilge-impl-0.2-rs either-1-rs itertools-0.11-rs libc-0.2-rs
   proc-macro-error-1-rs proc-macro-error-attr-1-rs quote-1-rs
   syn-2-rs unicode-ident-1-rs"
 
diff --git a/subprojects/libc-0.2-rs.wrap b/subprojects/libc-0.2-rs.wrap
new file mode 100644
index 00000000000..0ce0e75291a
--- /dev/null
+++ b/subprojects/libc-0.2-rs.wrap
@@ -0,0 +1,7 @@
+[wrap-file]
+directory = libc-0.2
+source_url = https://crates.io/api/v1/crates/libc/0.2.162/download
+source_filename = libc-0.2.162.tar.gz
+source_hash = 18d287de67fe55fd7e1581fe933d965a5a9477b38e949cfa9f8574ef01506398
+#method = cargo
+patch_directory = libc-0.2-rs
diff --git a/subprojects/packagefiles/libc-0.2-rs/meson.build b/subprojects/packagefiles/libc-0.2-rs/meson.build
new file mode 100644
index 00000000000..11c4ada33a5
--- /dev/null
+++ b/subprojects/packagefiles/libc-0.2-rs/meson.build
@@ -0,0 +1,36 @@
+project('libc-0.2-rs', 'rust',
+  meson_version: '>=1.5.0',
+  version: '0.2.162',
+  license: 'MIT OR Apache-2.0',
+  default_options: [])
+
+_libc_rs = static_library(
+  'libc',
+  files('src/lib.rs'),
+  gnu_symbol_visibility: 'hidden',
+  override_options: ['rust_std=2015', 'build.rust_std=2015'],
+  rust_abi: 'rust',
+  rust_args: [
+    '--cfg', 'freebsd11',
+    '--cfg', 'libc_priv_mod_use',
+    '--cfg', 'libc_union',
+    '--cfg', 'libc_const_size_of',
+    '--cfg', 'libc_align',
+    '--cfg', 'libc_int128',
+    '--cfg', 'libc_core_cvoid',
+    '--cfg', 'libc_packedN',
+    '--cfg', 'libc_cfg_target_vendor',
+    '--cfg', 'libc_non_exhaustive',
+    '--cfg', 'libc_long_array',
+    '--cfg', 'libc_ptr_addr_of',
+    '--cfg', 'libc_underscore_const_names',
+    '--cfg', 'libc_const_extern_fn',
+  ],
+  dependencies: [],
+)
+
+libc_dep = declare_dependency(
+  link_with: _libc_rs,
+)
+
+meson.override_dependency('libc-0.2-rs', libc_dep)
-- 
2.48.1


  reply	other threads:[~2025-02-12 17:17 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-11 21:43 [PATCH 00/11] rust/block: Add minimal block driver bindings Kevin Wolf
2025-02-11 21:43 ` [PATCH 01/11] rust: Build separate qemu_api_tools and qemu_api_system Kevin Wolf
2025-02-12 10:01   ` Paolo Bonzini
2025-02-12 15:29     ` Kevin Wolf
2025-02-12 16:59       ` Paolo Bonzini
2025-02-11 21:43 ` [PATCH 02/11] meson: Add rust_block_ss and link tools with it Kevin Wolf
2025-02-12  7:38   ` Philippe Mathieu-Daudé
2025-02-11 21:43 ` [PATCH 03/11] rust: Add some block layer bindings Kevin Wolf
2025-02-12  9:29   ` Paolo Bonzini
2025-02-12 13:13     ` Kevin Wolf
2025-02-12 13:47       ` Paolo Bonzini
2025-02-12 15:13         ` Kevin Wolf
2025-02-12 17:16           ` Paolo Bonzini [this message]
2025-02-12 19:52             ` Kevin Wolf
2025-02-13 11:06               ` Paolo Bonzini
2025-02-11 21:43 ` [PATCH 04/11] rust/qemu-api: Add wrappers to run futures in QEMU Kevin Wolf
2025-02-12  9:28   ` Paolo Bonzini
2025-02-12 12:47     ` Kevin Wolf
2025-02-12 13:22       ` Paolo Bonzini
2025-02-18 17:25         ` Kevin Wolf
2025-02-11 21:43 ` [PATCH 05/11] rust/block: Add empty crate Kevin Wolf
2025-02-11 21:43 ` [PATCH 06/11] rust/block: Add I/O buffer traits Kevin Wolf
2025-02-12 16:48   ` Paolo Bonzini
2025-02-12 17:22     ` Kevin Wolf
2025-02-12 17:41       ` Paolo Bonzini
2025-02-11 21:43 ` [PATCH 07/11] block: Add bdrv_open_blockdev_ref_file() Kevin Wolf
2025-02-12  7:43   ` Philippe Mathieu-Daudé
2025-02-11 21:43 ` [PATCH 08/11] rust/block: Add driver module Kevin Wolf
2025-02-12 16:43   ` Paolo Bonzini
2025-02-12 17:32     ` Kevin Wolf
2025-02-12 18:17       ` Paolo Bonzini
2025-02-11 21:43 ` [PATCH 09/11] rust/block: Add read support for block drivers Kevin Wolf
2025-02-12 15:05   ` Paolo Bonzini
2025-02-12 20:52     ` Kevin Wolf
2025-02-11 21:43 ` [PATCH 10/11] bochs-rs: Add bochs block driver reimplementation in Rust Kevin Wolf
2025-02-12  7:45   ` Philippe Mathieu-Daudé
2025-02-12 12:59     ` Kevin Wolf
2025-02-12 13:52       ` Philippe Mathieu-Daudé
2025-02-12  9:14   ` Daniel P. Berrangé
2025-02-12  9:41     ` Daniel P. Berrangé
2025-02-12 12:58       ` Kevin Wolf
2025-02-12 13:07         ` Daniel P. Berrangé
2025-02-11 21:43 ` [PATCH 11/11] rust/block: Add format probing Kevin Wolf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a8e79f73-15d0-486c-99da-ad871a57e4ef@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=hreitz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=manos.pitsidianakis@linaro.org \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-rust@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).