All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Alex Bennée" <alex.bennee@linaro.org>
To: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
Cc: qemu-devel@nongnu.org, "Paolo Bonzini" <pbonzini@redhat.com>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Daniel P. Berrangé" <berrange@redhat.com>,
	"Thomas Huth" <thuth@redhat.com>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>,
	"Pierrick Bouvier" <pierrick.bouvier@linaro.org>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"Gustavo Romero" <gustavo.romero@linaro.org>,
	"Peter Maydell" <peter.maydell@linaro.org>,
	"Junjie Mao" <junjie.mao@intel.com>,
	"Zhao Liu" <zhao1.liu@intel.com>
Subject: Re: [PATCH RESEND v9 7/9] rust: add crate to expose bindings and interfaces
Date: Wed, 28 Aug 2024 14:08:23 +0100	[thread overview]
Message-ID: <871q284wxk.fsf@draig.linaro.org> (raw)
In-Reply-To: <20240828-rust-pl011-v9-7-35579191f17c@linaro.org> (Manos Pitsidianakis's message of "Wed, 28 Aug 2024 07:11:48 +0300")

Manos Pitsidianakis <manos.pitsidianakis@linaro.org> writes:

> Add rust/qemu-api, which exposes rust-bindgen generated FFI bindings and
> provides some declaration macros for symbols visible to the rest of
> QEMU.

As mentioned on IRC I'm hitting a compilation error that bisects to this
commit:

  [148/1010] Generating bindings for Rust rustmod-bindgen-rust_wrapper.h
  FAILED: bindings.rs
  /home/alex/.cargo/bin/bindgen ../../rust/wrapper.h --output /home/alex/lsrc/qemu.git/builds/rust/bindings.rs --disable-header-comment --raw-line '// @generated' --ctypes-prefix core::ffi --formatter rustfmt --generate-block --generate-cstr --impl-debug --merge-extern-blocks --no-doc-comments --use-core --with-derive-default --allowlist-file '/home/alex/lsrc/qemu.git/include/.*' --allowlist-file '/home/alex/lsrc/qemu.git/.*' --allowlist-file '/home/alex/lsrc/qemu.git/builds/rust/.*' -- -I/home/alex/lsrc/qemu.git/. -I/home/alex/lsrc/qemu.git/builds/rust/. -I/home/alex/lsrc/qemu.git/include -I/home/alex/lsrc/qemu.git/builds/rust/include -I/usr/include/capstone -I/usr/include/p11-kit-1 -I/usr/include/pixman-1 -I/usr/include/libpng16 -I/usr/include/spice-server -I/usr/include/spice-1 -I/usr/include/spice-1 -DSTRUCT_IOVEC_DEFINED -I/usr/include/libusb-1.0 -I/usr/include/SDL2 -D_REENTRANT -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -pthread -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/gio-unix-2.0 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -pthread -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/slirp -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -DNCURSES_WIDECHAR=1 -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=600 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/gtk-3.0 -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/harfbuzz -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/fribidi -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/x86_64-linux-gnu -I/usr/include/gio-unix-2.0 -I/usr/include/atk-1.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/at-spi-2.0 -I/usr/include/dbus-1.0 -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include -pthread -I/usr/include/gtk-3.0 -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/harfbuzz -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/fribidi -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/x86_64-linux-gnu -I/usr/include/gio-unix-2.0 -I/usr/include/atk-1.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/at-spi-2.0 -I/usr/include/dbus-1.0 -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include -pthread -I/usr/include/vte-2.91 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/fribidi -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/gtk-3.0 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/x86_64-linux-gnu -I/usr/include/gio-unix-2.0 -I/usr/include/atk-1.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/at-spi-2.0 -I/usr/include/dbus-1.0 -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include -pthread -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/spice-server -I/usr/include/spice-1 -I/usr/include/cacard -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/nss -I/usr/include/nspr -I/usr/include/PCSC -pthread -D_REENTRANT -I/usr/include/pipewire-0.3 -I/usr/include/spa-0.2 -D_REENTRANT -I/usr/include/p11-kit-1 -I/usr/include/fuse3 -I/usr/include/x86_64-linux-gnu -D_FILE_OFFSET_BITS=64 -D__USE_FILE_OFFSET64 -D__USE_LARGEFILE64 -DUSE_POSIX_ACLS=1 -I/usr/include/uuid -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/p11-kit-1 -I/usr/include/p11-kit-1 -I/usr/include/p11-kit-1 -I/usr/include/p11-kit-1 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -std=gnu11 -MD -MQ ../../rust/wrapper.h -MF wrapper.h.d
  /usr/include/liburing.h:296:3: error: use of undeclared identifier 'memory_order_release'
  /usr/include/liburing.h:1080:11: error: use of undeclared identifier 'memory_order_acquire'
  /usr/include/liburing.h:1116:9: error: use of undeclared identifier 'memory_order_acquire'
  /usr/include/liburing.h:1125:9: error: use of undeclared identifier 'memory_order_relaxed'
  /usr/include/liburing.h:1161:2: error: use of undeclared identifier 'memory_order_relaxed'
  /usr/include/liburing.h:1197:19: error: use of undeclared identifier 'memory_order_acquire'
  /usr/include/liburing.h:1267:10: error: use of undeclared identifier 'memory_order_relaxed'
  /usr/include/liburing.h:1269:10: error: use of undeclared identifier 'memory_order_acquire'
  /usr/include/liburing.h:1320:2: error: use of undeclared identifier 'memory_order_release'
  panicked at /home/alex/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bindgen-cli-0.69.4/main.rs:52:36:
  Unable to generate bindings: ClangDiagnostic("/usr/include/liburing.h:296:3: error: use of undeclared identifier 'memory_order_release'\n/usr/include/liburing.h:1080:11: error: use of undeclared identifier 'memory_order_acquire'\n/usr/include/liburing.h:1116:9: error: use of undeclared identifier 'memory_order_acquire'\n/usr/include/liburing.h:1125:9: error: use of undeclared identifier 'memory_order_relaxed'\n/usr/include/liburing.h:1161:2: error: use of undeclared identifier 'memory_order_relaxed'\n/usr/include/liburing.h:1197:19: error: use of undeclared identifier 'memory_order_acquire'\n/usr/include/liburing.h:1267:10: error: use of undeclared identifier 'memory_order_relaxed'\n/usr/include/liburing.h:1269:10: error: use of undeclared identifier 'memory_order_acquire'\n/usr/include/liburing.h:1320:2: error: use of undeclared identifier 'memory_order_release'\n")

And I wasn't able to force the newer clang with:

  env CLANG_PATH=/usr/bin/clang-15 ../../configure '--disable-docs' --target-list=aarch64-softmmu --enable-rust

So if clang is required for bindgen we at least need:

  - to probe for clang (separately from --cc)
  - allow the user to override the default
  - pass the clang we want to use somehow to bindgen

Briefly looking at the bindgen code I see:

  fn main() {
      let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());

      let mut dst =
          File::create(Path::new(&out_dir).join("host-target.txt")).unwrap();
      dst.write_all(env::var("TARGET").unwrap().as_bytes())
          .unwrap();

      // On behalf of clang_sys, rebuild ourselves if important configuration
      // variables change, to ensure that bindings get rebuilt if the
      // underlying libclang changes.
      println!("cargo:rerun-if-env-changed=LLVM_CONFIG_PATH");
      println!("cargo:rerun-if-env-changed=LIBCLANG_PATH");
      println!("cargo:rerun-if-env-changed=LIBCLANG_STATIC_PATH");
      println!("cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS");
      println!(
          "cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS_{}",
          std::env::var("TARGET").unwrap()
      );
      println!(
          "cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS_{}",
          std::env::var("TARGET").unwrap().replace('-', "_")
      );
  }

So I wonder if this depends on what libclang versions can be found when
cargo builds it? Although if it does it must do so dynamically:

  $ ldd /home/alex/.cargo/bin/bindgen
          linux-vdso.so.1 (0x00007f7cb43d8000)
          libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f7cb438c000)
          libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f7cb42ad000)
          libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f7cb3a1f000)
          /lib64/ld-linux-x86-64.so.2 (0x00007f7cb43da000)

-- 
Alex Bennée
Virtualisation Tech Lead @ Linaro


  reply	other threads:[~2024-08-28 13:09 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-28  4:11 [PATCH RESEND v9 0/9] Add Rust build support, ARM PL011 device impl Manos Pitsidianakis
2024-08-28  4:11 ` [PATCH RESEND v9 1/9] Require meson version 1.5.0 Manos Pitsidianakis
2024-08-28 10:43   ` Alex Bennée
2024-08-28  4:11 ` [PATCH RESEND v9 2/9] build-sys: Add rust feature option Manos Pitsidianakis
2024-08-28 11:26   ` Alex Bennée
2024-08-28  4:11 ` [PATCH RESEND v9 3/9] configure, meson: detect Rust toolchain Manos Pitsidianakis
2024-08-28 12:11   ` Alex Bennée
2024-08-28 12:28   ` Daniel P. Berrangé
2024-09-04 11:03     ` Paolo Bonzini
2024-09-04 11:32       ` Paolo Bonzini
2024-08-28  4:11 ` [PATCH RESEND v9 4/9] rust: add bindgen step as a meson dependency Manos Pitsidianakis
2024-08-28  4:11 ` [PATCH RESEND v9 5/9] .gitattributes: add Rust diff and merge attributes Manos Pitsidianakis
2024-08-28  4:11 ` [PATCH RESEND v9 6/9] meson.build: add HAVE_GLIB_WITH_ALIGNED_ALLOC flag Manos Pitsidianakis
2024-08-28 13:15   ` Alex Bennée
2024-08-28  4:11 ` [PATCH RESEND v9 7/9] rust: add crate to expose bindings and interfaces Manos Pitsidianakis
2024-08-28 13:08   ` Alex Bennée [this message]
2024-08-30  1:19     ` Junjie Mao
2024-08-30  6:43       ` Manos Pitsidianakis
2024-08-30  8:50         ` Junjie Mao
2024-08-30 11:03       ` Alex Bennée
2024-08-31  8:25         ` Manos Pitsidianakis
2024-09-02  5:58           ` Junjie Mao
2024-09-06  7:56             ` Paolo Bonzini
2024-09-04 11:01   ` Paolo Bonzini
2024-09-05  3:05     ` Junjie Mao
2024-09-05  7:50     ` Manos Pitsidianakis
2024-08-28  4:11 ` [PATCH RESEND v9 8/9] rust: add utility procedural macro crate Manos Pitsidianakis
2024-08-28  4:11 ` [PATCH RESEND v9 9/9] rust: add PL011 device model Manos Pitsidianakis
2024-09-04 11:04   ` Paolo Bonzini
2024-09-06 10:41   ` Paolo Bonzini
2024-08-28 13:18 ` [PATCH RESEND v9 0/9] Add Rust build support, ARM PL011 device impl Alex Bennée
2024-09-04 11:31 ` Paolo Bonzini

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=871q284wxk.fsf@draig.linaro.org \
    --to=alex.bennee@linaro.org \
    --cc=berrange@redhat.com \
    --cc=gustavo.romero@linaro.org \
    --cc=junjie.mao@intel.com \
    --cc=manos.pitsidianakis@linaro.org \
    --cc=marcandre.lureau@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=philmd@linaro.org \
    --cc=pierrick.bouvier@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=thuth@redhat.com \
    --cc=zhao1.liu@intel.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.