On 6/27/24 16:47, Pierrick Bouvier wrote:
On 6/25/24 11:08, Manos Pitsidianakis wrote:
On Tue, 25 Jun 2024 19:00, Zhao Liu <zhao1....@intel.com> wrote:
[snip]
This is for future-proofing the Rust integration in general. I
haven't been
able to compile under macos yet because bindgen cannot find the system clang
header. I also don't have a windows pc to test it on. But it should work
theoretically under all three.
Yes, they should work. EMM, but there is no particular need for them at
the moment, so just to be safe, we can put these two platforms on hold
for now, and they can be easily added when the tests are covered.
A TODO can remind support for them.
I'm still trying to figure out why bindgen doesn't find the /Library/***
include paths.. it's frustrating! I will remove them if I don't succeed
and also no one volunteers to attempt a windows build. :)
I'm currently doing it, and managed to run until bindgen step. Same
problem that you found on MacOS, it can't locate some headers
(strings.h, included from osdep.h). I'll try to dig into this, but if
you found a solution already, you're welcome to share it.
'gcc | grep' command you used should work, but should be adapted because
windows paths start with C:/ instead of /.
I've been able to build rust device on windows, with a few tweaks needed.
- specificy the target for libclang (used by bindgen), which targets
MSVC by default (so different set of headers)
- additional headers (libclang searches its own header with a relative
path instead of absolute)
- additional windows libs that must be linked in final executable
However, even tough I can build the executable, I get this error:
$ ./build/qemu-system-aarch64 -M virt
C:\w\qemu\build\qemu-system-aarch64.exe: unknown type 'x-pl011-rust'
Any idea of what could be missing here?
By the way, I noticed configure --enable-with-rust does not trigger
error when not finding cargo, it just deactivates rust support, which is
probably not what is expected.
---
QEMU Build instructions for windows are here:
https://wiki.qemu.org/Hosts/W32#Native_builds_with_MSYS2
Additional steps needed:
$ cargo install bindgen-cli
$ export PATH=/c/Users/user/.cargo/bin/:$PATH
$ wget
https://github.com/llvm/llvm-project/releases/download/llvmorg-18.1.6/LLVM-18.1.6-win64.exe
# for libclang.dll
$ pacman -S p7zip
$ mkdir llvm && cd llvm && 7z x ../LLVM-18.1.6-win64.exe && cd ..
$ export LIBCLANG_PATH=$(cygpath -m $(pwd)/llvm/bin/libclang.dll)
Additional libs to link can be found with:
$ touch empty.rs
$ rustc empty.rs --print=native-static-libs --crate-type=staticlib
note: Link against the following native artifacts when linking against
this static library. The order and any duplication can be significant on so
me platforms.
note: native-static-libs: -lkernel32 -ladvapi32 -lkernel32 -lntdll
-luserenv -lws2_32 -lkernel32 -lws2_32 -lkernel32
---
diff --git a/meson.build b/meson.build
index ca40a39ad7e..98faa4777b7 100644
--- a/meson.build
+++ b/meson.build
@@ -3896,7 +3896,8 @@ foreach target : target_dirs
input: copy,
dependencies: arch_deps + lib_deps,
output: target + '-generated.rs',
- include_directories: include_directories('.', 'include'),
+ include_directories: include_directories('.', 'include',
+ 'llvm/lib/clang/18/include/'),
args: [
'--ctypes-prefix', 'core::ffi',
'--formatter', 'rustfmt',
@@ -3910,7 +3911,10 @@ foreach target : target_dirs
'--with-derive-default',
'--allowlist-file', meson.project_source_root() + '/include/.*',
'--allowlist-file', meson.project_source_root() + '/.*',
- '--allowlist-file', meson.project_build_root() + '/.*'
+ '--allowlist-file', meson.project_build_root() + '/.*',
+ ],
+ c_args: [
+ '--target=x86_64-pc-windows-gnu'
],
)
@@ -3925,7 +3929,12 @@ foreach target : target_dirs
rust_dep = declare_dependency(link_args: [
'-Wl,--whole-archive',
t['output-path'],
- '-Wl,--no-whole-archive'
+ '-Wl,--no-whole-archive',
+ '-lkernel32',
+ '-ladvapi32',
+ '-lntdll',
+ '-luserenv',
+ '-lws2_32',
],
sources: [rust_device_cargo])
rust_hw.add(rust_dep)