qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Junjie Mao <junjie.mao@intel.com>
To: "Manos Pitsidianakis" <manos.pitsidianakis@linaro.org>,
	"Alex Benn é e" <alex.bennee@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>,
	"Zhao Liu" <zhao1.liu@intel.com>
Subject: Re: [PATCH RESEND v9 7/9] rust: add crate to expose bindings and interfaces
Date: Mon, 2 Sep 2024 13:58:45 +0800	[thread overview]
Message-ID: <5676887b-9e54-4ee3-a29a-4735c3c21350@intel.com> (raw)
In-Reply-To: <j2qtr.bznhnwg3r4rn@linaro.org>

On 8/31/2024 4:25 PM, Manos Pitsidianakis wrote:
> On Fri, 30 Aug 2024 14:03, Alex Bennée <alex.bennee@linaro.org> wrote:
> [.snip.]
>>
>> It is there:
>>
>>  /usr/lib/llvm-14/lib/clang/14.0.6/include/stdatomic.h
>>
>> in the search path:
>>
>>  clang -E -Wp,-v -
>>  clang -cc1 version 14.0.6 based upon LLVM 14.0.6 default target 
>> x86_64-pc-linux-gnu
>>  ignoring nonexistent directory 
>> "/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include"
>>  ignoring nonexistent directory "/include"
>>  #include "..." search starts here:
>>  #include <...> search starts here:
>>   /usr/lib/llvm-14/lib/clang/14.0.6/include
>>   /usr/local/include
>>   /usr/include/x86_64-linux-gnu
>>   /usr/include
>>  End of search list.
>>
>> but not in the list above. Have we told clang not to include system
>> search paths in the bindgen invocation?
> 
> stdatomic.h was first included in c11, and compilers already shipped the header 
> on their own (since they use builtin operations). The compiler header paths are 
> considered special system header paths by compilers, and what's happening here 
> is a bug in the manual searching logic in libclang like explained in the other 

Do you mean the manual searching logic in the *clang-sys* crate?

There is also a related issue [1] on GitHub.

[1] https://github.com/rust-lang/rust-bindgen/issues/2682

> replies. The bindgen invocation looks at system search paths otherwise, or it'd 
> fail to find headers used in QEMU.

Another approach to work around that issue is to define BOTH CLANG_PATH and 
LIBCLANG_PATH env vars, e.g., CLANG_PATH=/usr/bin/clang-13 
LIBCLANG_PATH=/lib/x86_64-linux-gnu/libclang-13.so. That works in my environment.

The following is a draft to do it in meson.build. It does NOT work yet as 
bindgen() does not allow customizing environment variables. I'm checking how to 
make it in meson.

diff --git a/meson.build b/meson.build
index 68d5b53684..1f6fc21f8d 100644
--- a/meson.build
+++ b/meson.build
@@ -3879,6 +3879,30 @@ if have_rust and have_system
      capture : true,
      check: true).stdout().strip().split()

+  host_clang = find_program(
+    'clang', version: '>=5.0.0',
+    required: true, native: true)
+  host_libclang = run_command(
+    host_clang,
+    '-print-file-name=libclang.so',
+    capture: true,
+    check: true).stdout().strip()
+  # Clang prints an absolute path when the library is found
+  if not host_libclang.startswith('/')
+    host_clang_major = host_clang.version().split('.')[0]
+    host_libclang = run_command(
+      host_clang,
+      '-print-file-name=libclang-' + host_clang_major + '.so',
+      capture: true,
+      check: true).stdout().strip()
+  endif
+  if not host_libclang.startswith('/')
+    error('Cannot find libclang.so for ' + host_clang.full_path())
+  endif
+  message('Found libclang: ' + host_libclang)
+
+  # TODO: set CLANG_PATH to host_clang.full_path() and LIBCLANG_PATH to
+  # host_libclang when invoking bindgen
    bindings_rs = import('rust').bindgen(
      input: 'rust/wrapper.h',
      dependencies: common_ss.all_dependencies(),



  reply	other threads:[~2024-09-02  6:00 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
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 [this message]
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=5676887b-9e54-4ee3-a29a-4735c3c21350@intel.com \
    --to=junjie.mao@intel.com \
    --cc=alex.bennee@linaro.org \
    --cc=berrange@redhat.com \
    --cc=gustavo.romero@linaro.org \
    --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 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).