Skip to contentSkip to conversation

rust-pl011-rfc-v6

RFC PATCH In review Manos Pitsidianakis 3 participants 14 messages Aug 4, 2024 – Aug 12, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v6 cover rust-pl011-rfc-v6

Changes
=======

- Setting MSRV to 1.77.0:
* cstr crate MSRV is 1.64, which is more recent than Debian bookworm

    (1.63.0) <https://github.com/upsuper/cstr/blob/master/Cargo.toml>

* pl011's dependencies (mostly proc-macro2) don't support 1.63.0

- Dropped CI/lcitool patches.

- Dropped vendored dependencies in favor of meson subprojects.

- Added a qom ObjectImpl trait and declaration macros

- Added # SAFETY comments.

- Changed configure flag to --{enable,disable}-rust

Manos Pitsidianakis (5):
build-sys: Add rust feature option
rust: add bindgen step as a meson dependency .gitattributes: add Rust diff and merge attributes
rust: add crate to expose bindings and interfaces
rust: add PL011 device model

 MAINTAINERS                                   |  20 +
 configure                                     |   2 +
 meson.build                                   |  77 ++-
 rust/wrapper.h                                |  39 ++
 .gitattributes                                |   3 +
 Kconfig                                       |   1 +
 Kconfig.host                                  |   3 +
 hw/arm/Kconfig                                |  33 +-
 meson_options.txt                             |   3 +
 rust/.gitignore                               |   3 +
 rust/Kconfig                                  |   1 +
 rust/hw/Kconfig                               |   2 +
 rust/hw/char/Kconfig                          |   3 +
 rust/hw/char/meson.build                      |   1 +
 rust/hw/char/pl011/.gitignore                 |   2 +
 rust/hw/char/pl011/Cargo.lock                 | 125 ++++
 rust/hw/char/pl011/Cargo.toml                 |  26 +
 rust/hw/char/pl011/README.md                  |  31 +
 rust/hw/char/pl011/meson.build                |  28 +
 rust/hw/char/pl011/rustfmt.toml               |   1 +
 rust/hw/char/pl011/src/definitions.rs         |  26 +
 rust/hw/char/pl011/src/device.rs              | 586 ++++++++++++++++++
 rust/hw/char/pl011/src/device_class.rs        |  58 ++
 rust/hw/char/pl011/src/lib.rs                 | 584 +++++++++++++++++
 rust/hw/char/pl011/src/memory_ops.rs          |  56 ++
 rust/hw/meson.build                           |   1 +
 rust/meson.build                              |  15 +
 rust/qemu-api/.gitignore                      |   2 +
 rust/qemu-api/Cargo.lock                      |   7 +
 rust/qemu-api/Cargo.toml                      |  23 +
 rust/qemu-api/README.md                       |  17 +
 rust/qemu-api/build.rs                        |  13 +
 rust/qemu-api/meson.build                     |  19 +
 rust/qemu-api/rustfmt.toml                    |   1 +
 rust/qemu-api/src/bindings.rs                 |   7 +
 rust/qemu-api/src/definitions.rs              | 108 ++++
 rust/qemu-api/src/device_class.rs             | 128 ++++
 rust/qemu-api/src/lib.rs                      | 100 +++
 rust/qemu-api/src/tests.rs                    |  48 ++
 rust/rustfmt.toml                             |   7 +
 scripts/meson-buildoptions.sh                 |   3 +
 scripts/rustc_args.py                         |  84 +++
 subprojects/.gitignore                        |  11 +
 subprojects/arbitrary-int.wrap                |   9 +
 subprojects/bilge-impl.wrap                   |  10 +
 subprojects/bilge.wrap                        |  10 +
 subprojects/either.wrap                       |  10 +
 subprojects/itertools.wrap                    |  10 +
 .../packagefiles/arbitrary-int/meson.build    |  19 +
 .../packagefiles/bilge-impl/meson.build       |  36 ++
 subprojects/packagefiles/bilge/meson.build    |  25 +
 subprojects/packagefiles/either/meson.build   |  21 +
 .../packagefiles/itertools/meson.build        |  25 +
 .../proc-macro-error-attr/meson.build         |  27 +
 .../packagefiles/proc-macro-error/meson.build |  32 +
 .../packagefiles/proc-macro2/meson.build      |  26 +
 subprojects/packagefiles/quote/meson.build    |  25 +
 subprojects/packagefiles/syn/meson.build      |  33 +
 .../packagefiles/unicode-ident/meson.build    |  19 +
 subprojects/proc-macro-error-attr.wrap        |  10 +
 subprojects/proc-macro-error.wrap             |  11 +
 subprojects/proc-macro2.wrap                  |  10 +
 subprojects/quote.wrap                        |  10 +
 subprojects/syn.wrap                          |  11 +
 subprojects/unicode-ident.wrap                |  10 +
 65 files changed, 2695 insertions(+), 12 deletions(-)
 create mode 100644 rust/wrapper.h
 create mode 100644 rust/.gitignore
 create mode 100644 rust/Kconfig
 create mode 100644 rust/hw/Kconfig
 create mode 100644 rust/hw/char/Kconfig
 create mode 100644 rust/hw/char/meson.build
 create mode 100644 rust/hw/char/pl011/.gitignore
 create mode 100644 rust/hw/char/pl011/Cargo.lock
 create mode 100644 rust/hw/char/pl011/Cargo.toml
 create mode 100644 rust/hw/char/pl011/README.md
 create mode 100644 rust/hw/char/pl011/meson.build
 create mode 120000 rust/hw/char/pl011/rustfmt.toml
 create mode 100644 rust/hw/char/pl011/src/definitions.rs
 create mode 100644 rust/hw/char/pl011/src/device.rs
 create mode 100644 rust/hw/char/pl011/src/device_class.rs
 create mode 100644 rust/hw/char/pl011/src/lib.rs
 create mode 100644 rust/hw/char/pl011/src/memory_ops.rs
 create mode 100644 rust/hw/meson.build
 create mode 100644 rust/meson.build
 create mode 100644 rust/qemu-api/.gitignore
 create mode 100644 rust/qemu-api/Cargo.lock
 create mode 100644 rust/qemu-api/Cargo.toml
 create mode 100644 rust/qemu-api/README.md
 create mode 100644 rust/qemu-api/build.rs
 create mode 100644 rust/qemu-api/meson.build
 create mode 120000 rust/qemu-api/rustfmt.toml
 create mode 100644 rust/qemu-api/src/bindings.rs
 create mode 100644 rust/qemu-api/src/definitions.rs
 create mode 100644 rust/qemu-api/src/device_class.rs
 create mode 100644 rust/qemu-api/src/lib.rs
 create mode 100644 rust/qemu-api/src/tests.rs
 create mode 100644 rust/rustfmt.toml
 create mode 100644 scripts/rustc_args.py
 create mode 100644 subprojects/arbitrary-int.wrap
 create mode 100644 subprojects/bilge-impl.wrap
 create mode 100644 subprojects/bilge.wrap
 create mode 100644 subprojects/either.wrap
 create mode 100644 subprojects/itertools.wrap
 create mode 100644 subprojects/packagefiles/arbitrary-int/meson.build
 create mode 100644 subprojects/packagefiles/bilge-impl/meson.build
 create mode 100644 subprojects/packagefiles/bilge/meson.build
 create mode 100644 subprojects/packagefiles/either/meson.build
 create mode 100644 subprojects/packagefiles/itertools/meson.build
 create mode 100644 subprojects/packagefiles/proc-macro-error-attr/meson.build
 create mode 100644 subprojects/packagefiles/proc-macro-error/meson.build
 create mode 100644 subprojects/packagefiles/proc-macro2/meson.build
 create mode 100644 subprojects/packagefiles/quote/meson.build
 create mode 100644 subprojects/packagefiles/syn/meson.build
 create mode 100644 subprojects/packagefiles/unicode-ident/meson.build
 create mode 100644 subprojects/proc-macro-error-attr.wrap
 create mode 100644 subprojects/proc-macro-error.wrap
 create mode 100644 subprojects/proc-macro2.wrap
 create mode 100644 subprojects/quote.wrap
 create mode 100644 subprojects/syn.wrap
 create mode 100644 subprojects/unicode-ident.wrap

base-commit: f9851d2ffef59b3a7f39513469263ab3b019480f

Signature · 1 line
γαῖα πυρί μιχθήτω
#1 lore raw

RFC PATCH v6 1/5 build-sys: Add rust feature option

Add rust feature in meson.build, configure, to prepare for adding Rust code in the followup commits.

---
 MAINTAINERS                   |  5 +++++
 configure                     |  2 ++
 meson.build                   | 25 ++++++++++++++++++++++++-
 Kconfig                       |  1 +
 Kconfig.host                  |  3 +++
 meson_options.txt             |  3 +++
 rust/Kconfig                  |  0
 scripts/meson-buildoptions.sh |  3 +++
 8 files changed, 41 insertions(+), 1 deletion(-)
 create mode 100644 rust/Kconfig
MAINTAINERS +5 -0
index e34c2bd4cd..4ba57c9c67 100644
@@ -4239,6 +4239,11 @@ F: docs/sphinx/
 F: docs/_templates/
 F: docs/devel/docs.rst
 
+Rust build system integration
+M: Manos Pitsidianakis <[email protected]>
+S: Maintained
+F: rust/Kconfig
+
 Miscellaneous
 -------------
 Performance Tools and Tests
configure +2 -0
index 019fcbd0ef..aac7f29f25 100755
@@ -874,6 +874,8 @@ Advanced options (experts only):
                            start the emulator (only use if you are including
                            desired devices in configs/devices/)
   --with-devices-ARCH=NAME override default configs/devices
+  --enable-rust            enable compilation of Rust code
+  --disable-rust           disable compilation of Rust code
   --enable-debug           enable common debug build options
   --cpu=CPU                Build for host CPU [$cpu]
   --disable-containers     don't use containers for cross-building
meson.build +24 -1
index 97f63aa86c..9593fce47f 100644
@@ -70,6 +70,22 @@ if host_os == 'darwin' and \
   all_languages += ['objc']
   objc = meson.get_compiler('objc')
 endif
+if get_option('rust').enabled() and meson.version().version_compare('<1.0.0')
+  error('Rust support requires Meson version >=1.0.0')
+endif
+have_rust = false
+if not get_option('rust').disabled() and add_languages('rust', required: get_option('rust'), native: false)
+  rustc = meson.get_compiler('rust')
+  have_rust = true
+  if rustc.version().version_compare('<1.80.0')
+    if get_option('rust').enabled()
+      error('rustc version ' + rustc.version() + ' is unsupported: Please upgrade to at least 1.80.0')
+    else
+      warning('rustc version ' + rustc.version() + ' is unsupported: Disabling Rust compilation. Please upgrade to at least 1.80.0 to use Rust.')
+      have_rust = false
+    endif
+  endif
+endif
 
 dtrace = not_found
 stap = not_found
@@ -2119,6 +2135,7 @@ endif
 
 config_host_data = configuration_data()
 
+config_host_data.set('CONFIG_HAVE_RUST', have_rust)
 audio_drivers_selected = []
 if have_system
   audio_drivers_available = {
@@ -3062,7 +3079,8 @@ host_kconfig = \
   (host_os == 'linux' ? ['CONFIG_LINUX=y'] : []) + \
   (multiprocess_allowed ? ['CONFIG_MULTIPROCESS_ALLOWED=y'] : []) + \
   (vfio_user_server_allowed ? ['CONFIG_VFIO_USER_SERVER_ALLOWED=y'] : []) + \
-  (hv_balloon ? ['CONFIG_HV_BALLOON_POSSIBLE=y'] : [])
+  (hv_balloon ? ['CONFIG_HV_BALLOON_POSSIBLE=y'] : []) + \
+  (have_rust ? ['CONFIG_HAVE_RUST=y'] : [])
 
 ignored = [ 'TARGET_XML_FILES', 'TARGET_ABI_DIR', 'TARGET_ARCH' ]
 
@@ -4273,6 +4291,11 @@ if 'objc' in all_languages
 else
   summary_info += {'Objective-C compiler': false}
 endif
+summary_info += {'Rust support':      have_rust}
+if have_rust
+  summary_info += {'rustc version':      rustc.version()}
+  summary_info += {'rustc':      ' '.join(rustc.cmd_array())}
+endif
 option_cflags = (get_option('debug') ? ['-g'] : [])
 if get_option('optimization') != 'plain'
   option_cflags += ['-O' + get_option('optimization')]
Kconfig +1 -0
index fb6a24a2de..63ca7f46df 100644
@@ -4,3 +4,4 @@ source accel/Kconfig
 source target/Kconfig
 source hw/Kconfig
 source semihosting/Kconfig
+source rust/Kconfig
Kconfig.host +3 -0
index 17f405004b..4ade7899d6 100644
@@ -52,3 +52,6 @@ config VFIO_USER_SERVER_ALLOWED
 
 config HV_BALLOON_POSSIBLE
     bool
+
+config HAVE_RUST
+    bool
meson_options.txt +3 -0
index 0269fa0f16..fa94a5ce97 100644
@@ -371,3 +371,6 @@ option('hexagon_idef_parser', type : 'boolean', value : true,
 
 option('x86_version', type : 'combo', choices : ['0', '1', '2', '3', '4'], value: '1',
        description: 'tweak required x86_64 architecture version beyond compiler default')
+
+option('rust', type: 'feature', value: 'auto',
+       description: 'Rust support')
rust/Kconfig new file +0 -0
new file mode 100644
index 0000000000..e69de29bb2
scripts/meson-buildoptions.sh +3 -0
index c97079a38c..5e8a225a6b 100644
@@ -170,6 +170,7 @@ meson_options_help() {
   printf "%s\n" '  rbd             Ceph block device driver'
   printf "%s\n" '  rdma            Enable RDMA-based migration'
   printf "%s\n" '  replication     replication support'
+  printf "%s\n" '  rust            Rust support'
   printf "%s\n" '  rutabaga-gfx    rutabaga_gfx support'
   printf "%s\n" '  sdl             SDL user interface'
   printf "%s\n" '  sdl-image       SDL Image support for icons'
@@ -452,6 +453,8 @@ _meson_option_parse() {
     --disable-replication) printf "%s" -Dreplication=disabled ;;
     --enable-rng-none) printf "%s" -Drng_none=true ;;
     --disable-rng-none) printf "%s" -Drng_none=false ;;
+    --enable-rust) printf "%s" -Drust=enabled ;;
+    --disable-rust) printf "%s" -Drust=disabled ;;
     --enable-rutabaga-gfx) printf "%s" -Drutabaga_gfx=enabled ;;
     --disable-rutabaga-gfx) printf "%s" -Drutabaga_gfx=disabled ;;
     --enable-safe-stack) printf "%s" -Dsafe_stack=true ;;
Signature · 1 line
γαῖα πυρί μιχθήτω
#2 lore raw

Re: [RFC PATCH v6 1/5] build-sys: Add rust feature option

configure Advanced options (experts only): · line 878

Quoted 10 lines · Manos Pitsidianakis
configure +2 -0
index 019fcbd0ef..aac7f29f25 100755
@@ -874,6 +874,8 @@ Advanced options (experts only):
                             start the emulator (only use if you are including
                             desired devices in configs/devices/)
    --with-devices-ARCH=NAME override default configs/devices
+  --enable-rust            enable compilation of Rust code
+  --disable-rust           disable compilation of Rust code

Not needed ("rust" is included in the features list emitted by meson-build-options.sh)

Quoted 8 lines
configure +0 -0
    --enable-debug           enable common debug build options
    --cpu=CPU                Build for host CPU [$cpu]
    --disable-containers     don't use containers for cross-building
meson.build +0 -0
index 97f63aa86c..9593fce47f 100644

meson.build if host_os == 'darwin' and \ · line 75

Quoted 6 lines
meson.build +3 -0
@@ -70,6 +70,22 @@ if host_os == 'darwin' and \
    all_languages += ['objc']
    objc = meson.get_compiler('objc')
  endif
+if get_option('rust').enabled() and meson.version().version_compare('<1.0.0')
+  error('Rust support requires Meson version >=1.0.0')
+endif

Also not needed (1.1.0 is the minimum supported meson version).

meson.build if host_os == 'darwin' and \ · line 78

Quoted 3 lines
meson.build +3 -0
+have_rust = false
+if not get_option('rust').disabled() and add_languages('rust', required: get_option('rust'), native: false)
+  rustc = meson.get_compiler('rust')

The main missing part here is setting rustc in the native and cross files. This is a small change to the patch I had for cargo:

configure +48 -4
index aac7f29f25c..f2d5a9a8d40 100755
@@ -207,6 +207,8 @@ for opt do
   ;;
   --objcc=*) objcc="$optarg"
   ;;
+  --rustc=*) RUSTC="$optarg"
+  ;;
   --cpu=*) cpu="$optarg"
   ;;
   --extra-cflags=*)
@@ -252,6 +254,9 @@ python=
 download="enabled"
 skip_meson=no
 use_containers="yes"
+# do not enable by default because cross compilation requires --rust-target-triple
+rust="disabled"
+rust_target_triple=""
 gdb_bin=$(command -v "gdb-multiarch" || command -v "gdb")
 gdb_arches=""
 
@@ -317,6 +322,8 @@ windmc="${WINDMC-${cross_prefix}windmc}"
 pkg_config="${PKG_CONFIG-${cross_prefix}pkg-config}"
 sdl2_config="${SDL2_CONFIG-${cross_prefix}sdl2-config}"
 
+rustc="${RUSTC-rustc}"
+
 check_define() {
 cat > $TMPC <<EOF
 #if !defined($1)
@@ -636,6 +643,8 @@ for opt do
   ;;
   --objcc=*)
   ;;
+  --rustc=*)
+  ;;
   --make=*)
   ;;
   --install=*)
@@ -755,8 +764,14 @@ for opt do
   ;;
   --container-engine=*) container_engine="$optarg"
   ;;
+  --rust-target-triple=*) rust_target_triple="$optarg"
+  ;;
   --gdb=*) gdb_bin="$optarg"
   ;;
+  --enable-rust) rust=enabled
+  ;;
+  --disable-rust) rust=disabled
+  ;;
   # everything else has the same name in configure and meson
   --*) meson_option_parse "$opt" "$optarg"
   ;;
@@ -859,6 +874,7 @@ Advanced options (experts only):
                            at build time [$host_cc]
   --cxx=CXX                use C++ compiler CXX [$cxx]
   --objcc=OBJCC            use Objective-C compiler OBJCC [$objcc]
+  --rustc=RUSTC            use Rust compiler RUSTC [$rustc]
   --extra-cflags=CFLAGS    append extra C compiler flags CFLAGS
   --extra-cxxflags=CXXFLAGS append extra C++ compiler flags CXXFLAGS
   --extra-objcflags=OBJCFLAGS append extra Objective C compiler flags OBJCFLAGS
@@ -869,13 +885,12 @@ Advanced options (experts only):
   --python=PYTHON          use specified python [$python]
   --ninja=NINJA            use specified ninja [$ninja]
   --static                 enable static build [$static]
-  --without-default-features default all --enable-* options to "disabled"
-  --without-default-devices  do not include any device that is not needed to
+  --rust-target-triple=TRIPLE  target for Rust cross compilation
+  --without-default-features   default all --enable-* options to "disabled"
+  --without-default-devices    do not include any device that is not needed to
                            start the emulator (only use if you are including
                            desired devices in configs/devices/)
   --with-devices-ARCH=NAME override default configs/devices
-  --enable-rust            enable compilation of Rust code
-  --disable-rust           disable compilation of Rust code
   --enable-debug           enable common debug build options
   --cpu=CPU                Build for host CPU [$cpu]
   --disable-containers     don't use containers for cross-building
@@ -1140,6 +1155,21 @@ EOF
   fi
 fi
 
+##########################################
+# detect rust triple
+
+if test "$rust" != disabled && has "$rustc" && $rustc -vV > "${TMPDIR1}/${TMPB}.out"; then
+  rust_host_triple=$(sed -n 's/^host: //p' "${TMPDIR1}/${TMPB}.out")
+else
+  if test "$rust" = enabled; then
+    error_exit "could not execute rustc binary \"$rustc\""
+  fi
+  rust=disabled
+fi
+if test "$rust" != disabled && test -z "$rust_target_triple"; then
+  rust_target_triple=$rust_host_triple
+fi
+
 ##########################################
 # functions to probe cross compilers
 
@@ -1606,6 +1636,9 @@ if test "$container" != no; then
     echo "RUNC=$runc" >> $config_host_mak
 fi
 echo "SUBDIRS=$subdirs" >> $config_host_mak
+if test "$rust" != disabled; then
+  echo "RUST_TARGET_TRIPLE=$rust_target_triple" >> $config_host_mak
+fi
 echo "PYTHON=$python" >> $config_host_mak
 echo "MKVENV_ENSUREGROUP=$mkvenv ensuregroup $mkvenv_online_flag" >> $config_host_mak
 echo "GENISOIMAGE=$genisoimage" >> $config_host_mak
@@ -1737,6 +1770,13 @@ if test "$skip_meson" = no; then
   echo "c = [$(meson_quote $cc $CPU_CFLAGS)]" >> $cross
   test -n "$cxx" && echo "cpp = [$(meson_quote $cxx $CPU_CFLAGS)]" >> $cross
   test -n "$objcc" && echo "objc = [$(meson_quote $objcc $CPU_CFLAGS)]" >> $cross
+  if test "$rust" != disabled; then
+    if test "$rust_host_triple" != "$rust_target_triple"; then
+      echo "rustc = [$(meson_quote $rustc --target "$rust_target_triple")]" >> $cross
+    else
+      echo "rustc = [$(meson_quote $rustc)]" >> $cross
+    fi
+  fi
   echo "ar = [$(meson_quote $ar)]" >> $cross
   echo "dlltool = [$(meson_quote $dlltool)]" >> $cross
   echo "nm = [$(meson_quote $nm)]" >> $cross
@@ -1772,6 +1812,9 @@ if test "$skip_meson" = no; then
     echo "# Automatically generated by configure - do not modify" > $native
     echo "[binaries]" >> $native
     echo "c = [$(meson_quote $host_cc)]" >> $native
+    if test "$rust" != disabled; then
+      echo "rustc = [$(meson_quote $rustc)]" >> $cross
+    fi
     mv $native config-meson.native
     meson_option_add --native-file
     meson_option_add config-meson.native
@@ -1790,6 +1833,7 @@ if test "$skip_meson" = no; then
   test "$pie" = no && meson_option_add -Db_pie=false
 
   # QEMU options
+  test "$rust" != "auto" && meson_option_add "-Drust=$rust"
   test "$cfi" != false && meson_option_add "-Dcfi=$cfi" "-Db_lto=$cfi"
   test "$docs" != auto && meson_option_add "-Ddocs=$docs"
   test -n "${LIB_FUZZING_ENGINE+xxx}" && meson_option_add "-Dfuzzing_engine=$LIB_FUZZING_ENGINE"
meson.build +3 -5
index b89ce025c1a..e656ef34aab 100644
@@ -70,9 +70,6 @@ if host_os == 'darwin' and \
   all_languages += ['objc']
   objc = meson.get_compiler('objc')
 endif
-if get_option('rust').enabled() and meson.version().version_compare('<1.0.0')
-  error('Rust support requires Meson version >=1.0.0')
-endif
 have_rust = false
 if not get_option('rust').disabled() and add_languages('rust', required: get_option('rust'), native: false)
   rustc = meson.get_compiler('rust')
@@ -4305,8 +4302,9 @@ else
 endif
 summary_info += {'Rust support':      have_rust}
 if have_rust
-  summary_info += {'rustc version':      rustc.version()}
-  summary_info += {'rustc':      ' '.join(rustc.cmd_array())}
+  summary_info += {'rustc version':   rustc.version()}
+  summary_info += {'rustc':           ' '.join(rustc.cmd_array())}
+  summary_info += {'Rust target':     config_host['RUST_TARGET_TRIPLE']}
 endif
 option_cflags = (get_option('debug') ? ['-g'] : [])
 if get_option('optimization') != 'plain'
#3 lore raw

RFC PATCH v6 2/5 rust: add bindgen step as a meson dependency

In reply to Manos Pitsidianakis

Add bindings_rs target for generating rust bindings to target-independent qemu C APIs.

The bindings need be created before any rust crate that uses them is compiled.

The bindings.rs file will end up in BUILDDIR/bindings.rs and have the same name as a target:

ninja bindings.rs

---
 MAINTAINERS           |  4 +++
 meson.build           | 52 +++++++++++++++++++++++++++
 rust/wrapper.h        | 39 ++++++++++++++++++++
 rust/.gitignore       |  3 ++
 rust/meson.build      |  0
 scripts/rustc_args.py | 84 +++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 182 insertions(+)
 create mode 100644 rust/wrapper.h
 create mode 100644 rust/.gitignore
 create mode 100644 rust/meson.build
 create mode 100644 scripts/rustc_args.py
MAINTAINERS +4 -0
index 4ba57c9c67..e1d77816bb 100644
@@ -4242,7 +4242,11 @@ F: docs/devel/docs.rst
 Rust build system integration
 M: Manos Pitsidianakis <[email protected]>
 S: Maintained
+F: scripts/rustc_args.py
+F: rust/.gitignore
 F: rust/Kconfig
+F: rust/meson.build
+F: rust/wrapper.h
 
 Miscellaneous
 -------------
meson.build +52 -0

64 lines not on this page · raw message

rust/wrapper.h new file +39 -0
new file mode 100644
index 0000000000..51985f0ef1
@@ -0,0 +1,39 @@
+/*
+ * QEMU System Emulator
+ *
+ * Copyright 2024 Manos Pitsidianakis <[email protected]>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/module.h"
+#include "qemu-io.h"
+#include "sysemu/sysemu.h"
+#include "hw/sysbus.h"
+#include "exec/memory.h"
+#include "chardev/char-fe.h"
+#include "hw/clock.h"
+#include "hw/qdev-clock.h"
+#include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
+#include "hw/irq.h"
+#include "qapi/error.h"
+#include "migration/vmstate.h"
+#include "chardev/char-serial.h"
rust/.gitignore new file +3 -0
new file mode 100644
index 0000000000..1bf71b1f68
@@ -0,0 +1,3 @@
+# Ignore any cargo development build artifacts; for qemu-wide builds, all build
+# artifacts will go to the meson build directory.
+target
rust/meson.build new file +0 -0
new file mode 100644
index 0000000000..e69de29bb2
scripts/rustc_args.py new file +84 -0

84 lines not on this page · raw message

Signature · 1 line
γαῖα πυρί μιχθήτω
#4 lore raw

RFC PATCH v6 3/5 .gitattributes: add Rust diff and merge attributes

In reply to Manos Pitsidianakis

Set rust source code to diff=rust (built-in with new git versions) and merge=binary for Cargo.lock files (they should not be merged but auto-generated by cargo)

---
 .gitattributes | 3 +++
 1 file changed, 3 insertions(+)
.gitattributes +3 -0
index a217cb7bfe..6dc6383d3d 100644
@@ -2,3 +2,6 @@
 *.h.inc         diff=c
 *.m             diff=objc
 *.py            diff=python
+*.rs            diff=rust
+*.rs.inc        diff=rust
+Cargo.lock      diff=toml merge=binary
Signature · 1 line
γαῖα πυρί μιχθήτω
#5 lore raw

RFC PATCH v6 4/5 rust: add crate to expose bindings and interfaces

In reply to Manos Pitsidianakis

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

---
 MAINTAINERS                       |   6 ++
 rust/meson.build                  |  13 +++
 rust/qemu-api/.gitignore          |   2 +
 rust/qemu-api/Cargo.lock          |   7 ++
 rust/qemu-api/Cargo.toml          |  23 ++++++
 rust/qemu-api/README.md           |  17 ++++
 rust/qemu-api/build.rs            |  13 +++
 rust/qemu-api/meson.build         |  19 +++++
 rust/qemu-api/rustfmt.toml        |   1 +
 rust/qemu-api/src/bindings.rs     |   7 ++
 rust/qemu-api/src/definitions.rs  | 108 +++++++++++++++++++++++++
 rust/qemu-api/src/device_class.rs | 128 ++++++++++++++++++++++++++++++
 rust/qemu-api/src/lib.rs          | 100 +++++++++++++++++++++++
 rust/qemu-api/src/tests.rs        |  48 +++++++++++
 rust/rustfmt.toml                 |   7 ++
 15 files changed, 499 insertions(+)
 create mode 100644 rust/qemu-api/.gitignore
 create mode 100644 rust/qemu-api/Cargo.lock
 create mode 100644 rust/qemu-api/Cargo.toml
 create mode 100644 rust/qemu-api/README.md
 create mode 100644 rust/qemu-api/build.rs
 create mode 100644 rust/qemu-api/meson.build
 create mode 120000 rust/qemu-api/rustfmt.toml
 create mode 100644 rust/qemu-api/src/bindings.rs
 create mode 100644 rust/qemu-api/src/definitions.rs
 create mode 100644 rust/qemu-api/src/device_class.rs
 create mode 100644 rust/qemu-api/src/lib.rs
 create mode 100644 rust/qemu-api/src/tests.rs
 create mode 100644 rust/rustfmt.toml
MAINTAINERS +6 -0
index e1d77816bb..018f3a9420 100644
@@ -3345,6 +3345,12 @@ F: hw/core/register.c
 F: include/hw/register.h
 F: include/hw/registerfields.h
 
+Rust
+M: Manos Pitsidianakis <[email protected]>
+S: Maintained
+F: rust/qemu-api
+F: rust/rustfmt.toml
+
 SLIRP
 M: Samuel Thibault <[email protected]>
 S: Maintained
rust/meson.build +13 -0
index e69de29bb2..a903c7c602 100644
@@ -0,0 +1,13 @@
+add_languages('rust', required: true)
+
+_lib_bindings_rs = static_library(
+  '_bindings_rs',
+  bindings_rs,
+  gnu_symbol_visibility: 'hidden',
+  rust_abi: 'rust',
+  rust_args: rust_args + [
+    '--edition', '2021',
+  ],
+)
+
+subdir('qemu-api')
rust/qemu-api/.gitignore new file +2 -0
new file mode 100644
index 0000000000..71eaff2035
@@ -0,0 +1,2 @@
+# Ignore generated bindings file overrides.
+src/bindings.rs.inc
rust/qemu-api/Cargo.lock new file +7 -0
new file mode 100644
index 0000000000..e9c51a243a
@@ -0,0 +1,7 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 3
+
+[[package]]
+name = "qemu_api"
+version = "0.1.0"
rust/qemu-api/Cargo.toml new file +23 -0
new file mode 100644
index 0000000000..51260cbe42
@@ -0,0 +1,23 @@
+[package]
+name = "qemu_api"
+version = "0.1.0"
+edition = "2021"
+authors = ["Manos Pitsidianakis <[email protected]>"]
+license = "GPL-2.0 OR GPL-3.0-or-later"
+readme = "README.md"
+homepage = "https://www.qemu.org"
+description = "Rust bindings for QEMU"
+repository = "https://gitlab.com/qemu-project/qemu/"
+resolver = "2"
+publish = false
+keywords = []
+categories = []
+
+[dependencies]
+
+[features]
+default = ["allocator"]
+allocator = []
+
+# Do not include in any global workspace
+[workspace]
rust/qemu-api/README.md new file +17 -0
new file mode 100644
index 0000000000..7588fa29ef
@@ -0,0 +1,17 @@
+# QEMU bindings and API wrappers
+
+This library exports helper Rust types, Rust macros and C FFI bindings for internal QEMU APIs.
+
+The C bindings can be generated with `bindgen`, using this build target:
+
+```console
+$ ninja bindings.rs
+```
+
+## Generate Rust documentation
+
+To generate docs for this crate, including private items:
+
+```sh
+cargo doc --no-deps --document-private-items
+```
rust/qemu-api/build.rs new file +13 -0
new file mode 100644
index 0000000000..2f57c2b3d4
@@ -0,0 +1,13 @@
+// Copyright 2024 Manos Pitsidianakis <[email protected]>
+// SPDX-License-Identifier: GPL-2.0 OR GPL-3.0-or-later
+
+use std::path::Path;
+
+fn main() {
+    if !Path::new("src/bindings.rs.inc").exists() {
+        panic!(
+            "No generated C bindings found! Either build them manually with bindgen or with meson \
+             (`ninja bindings.rs`) and copy them to src/bindings.rs.inc, or build through meson."
+        );
+    }
+}
rust/qemu-api/meson.build new file +19 -0
new file mode 100644
index 0000000000..7992dc64ce
@@ -0,0 +1,19 @@
+add_languages('rust', required: true)
+
+_qemu_api_rs = static_library(
+  'qemu_api',
+  [files('src/lib.rs')],
+  gnu_symbol_visibility: 'hidden',
+  rust_abi: 'rust',
+  rust_args: rust_args + [
+    '--edition', '2021',
+    '--cfg', 'MESON_BINDINGS_RS',
+  ],
+  link_with: [
+    _lib_bindings_rs,
+  ],
+)
+
+qemu_api = declare_dependency(
+  link_with: _qemu_api_rs,
+)
rust/qemu-api/rustfmt.toml new file +1 -0
new file mode 120000
index 0000000000..39f97b043b
@@ -0,0 +1 @@
+../rustfmt.toml
\ No newline at end of file
rust/qemu-api/src/bindings.rs new file +7 -0
new file mode 100644
index 0000000000..fb595f1469
@@ -0,0 +1,7 @@
+// Copyright 2024 Manos Pitsidianakis <[email protected]>
+// SPDX-License-Identifier: GPL-2.0 OR GPL-3.0-or-later
+#[cfg(not(MESON_BINDINGS_RS))]
+include!("bindings.rs.inc");
+
+#[cfg(MESON_BINDINGS_RS)]
+pub use ::_bindings_rs::*;
rust/qemu-api/src/definitions.rs new file +108 -0

108 lines not on this page · raw message

rust/qemu-api/src/device_class.rs new file +128 -0

128 lines not on this page · raw message

rust/qemu-api/src/lib.rs new file +100 -0

100 lines not on this page · raw message

rust/qemu-api/src/tests.rs new file +48 -0

48 lines not on this page · raw message

rust/rustfmt.toml new file +7 -0
new file mode 100644
index 0000000000..ebecb99fe0
@@ -0,0 +1,7 @@
+edition = "2021"
+format_generated_files = false
+format_code_in_doc_comments = true
+format_strings = true
+imports_granularity = "Crate"
+group_imports = "StdExternalCrate"
+wrap_comments = true
Signature · 1 line
γαῖα πυρί μιχθήτω
#6 lore raw

Re: [RFC PATCH v6 4/5] rust: add crate to expose bindings and interfaces

rust/qemu-api/meson.build line 1

Quoted 7 lines · Manos Pitsidianakis
rust/qemu-api/meson.build new file +1 -0
new file mode 100644
index 0000000000..7992dc64ce
@@ -0,0 +1,19 @@
+add_languages('rust', required: true)

Not needed.

Paolo

#7 lore raw

RFC PATCH v6 5/5 rust: add PL011 device model

In reply to Manos Pitsidianakis

This commit adds a re-implementation of hw/char/pl011.c in Rust.

How to build:

1. Configure a QEMU build with:
--enable-system --target-list=aarch64-softmmu --enable-rust
2. Launching a VM with qemu-system-aarch64 should use the Rust version of the pl011 device

---
Note: subproject dependencies licenses are not correct.

---
 MAINTAINERS                                   |   5 +
 hw/arm/Kconfig                                |  33 +-
 rust/Kconfig                                  |   1 +
 rust/hw/Kconfig                               |   2 +
 rust/hw/char/Kconfig                          |   3 +
 rust/hw/char/meson.build                      |   1 +
 rust/hw/char/pl011/.gitignore                 |   2 +
 rust/hw/char/pl011/Cargo.lock                 | 125 ++++
 rust/hw/char/pl011/Cargo.toml                 |  26 +
 rust/hw/char/pl011/README.md                  |  31 +
 rust/hw/char/pl011/meson.build                |  28 +
 rust/hw/char/pl011/rustfmt.toml               |   1 +
 rust/hw/char/pl011/src/definitions.rs         |  26 +
 rust/hw/char/pl011/src/device.rs              | 586 ++++++++++++++++++
 rust/hw/char/pl011/src/device_class.rs        |  58 ++
 rust/hw/char/pl011/src/lib.rs                 | 584 +++++++++++++++++
 rust/hw/char/pl011/src/memory_ops.rs          |  56 ++
 rust/hw/meson.build                           |   1 +
 rust/meson.build                              |   2 +
 subprojects/.gitignore                        |  11 +
 subprojects/arbitrary-int.wrap                |   9 +
 subprojects/bilge-impl.wrap                   |  10 +
 subprojects/bilge.wrap                        |  10 +
 subprojects/either.wrap                       |  10 +
 subprojects/itertools.wrap                    |  10 +
 .../packagefiles/arbitrary-int/meson.build    |  19 +
 .../packagefiles/bilge-impl/meson.build       |  36 ++
 subprojects/packagefiles/bilge/meson.build    |  25 +
 subprojects/packagefiles/either/meson.build   |  21 +
 .../packagefiles/itertools/meson.build        |  25 +
 .../proc-macro-error-attr/meson.build         |  27 +
 .../packagefiles/proc-macro-error/meson.build |  32 +
 .../packagefiles/proc-macro2/meson.build      |  26 +
 subprojects/packagefiles/quote/meson.build    |  25 +
 subprojects/packagefiles/syn/meson.build      |  33 +
 .../packagefiles/unicode-ident/meson.build    |  19 +
 subprojects/proc-macro-error-attr.wrap        |  10 +
 subprojects/proc-macro-error.wrap             |  11 +
 subprojects/proc-macro2.wrap                  |  10 +
 subprojects/quote.wrap                        |  10 +
 subprojects/syn.wrap                          |  11 +
 subprojects/unicode-ident.wrap                |  10 +
 42 files changed, 1970 insertions(+), 11 deletions(-)
 create mode 100644 rust/hw/Kconfig
 create mode 100644 rust/hw/char/Kconfig
 create mode 100644 rust/hw/char/meson.build
 create mode 100644 rust/hw/char/pl011/.gitignore
 create mode 100644 rust/hw/char/pl011/Cargo.lock
 create mode 100644 rust/hw/char/pl011/Cargo.toml
 create mode 100644 rust/hw/char/pl011/README.md
 create mode 100644 rust/hw/char/pl011/meson.build
 create mode 120000 rust/hw/char/pl011/rustfmt.toml
 create mode 100644 rust/hw/char/pl011/src/definitions.rs
 create mode 100644 rust/hw/char/pl011/src/device.rs
 create mode 100644 rust/hw/char/pl011/src/device_class.rs
 create mode 100644 rust/hw/char/pl011/src/lib.rs
 create mode 100644 rust/hw/char/pl011/src/memory_ops.rs
 create mode 100644 rust/hw/meson.build
 create mode 100644 subprojects/arbitrary-int.wrap
 create mode 100644 subprojects/bilge-impl.wrap
 create mode 100644 subprojects/bilge.wrap
 create mode 100644 subprojects/either.wrap
 create mode 100644 subprojects/itertools.wrap
 create mode 100644 subprojects/packagefiles/arbitrary-int/meson.build
 create mode 100644 subprojects/packagefiles/bilge-impl/meson.build
 create mode 100644 subprojects/packagefiles/bilge/meson.build
 create mode 100644 subprojects/packagefiles/either/meson.build
 create mode 100644 subprojects/packagefiles/itertools/meson.build
 create mode 100644 subprojects/packagefiles/proc-macro-error-attr/meson.build
 create mode 100644 subprojects/packagefiles/proc-macro-error/meson.build
 create mode 100644 subprojects/packagefiles/proc-macro2/meson.build
 create mode 100644 subprojects/packagefiles/quote/meson.build
 create mode 100644 subprojects/packagefiles/syn/meson.build
 create mode 100644 subprojects/packagefiles/unicode-ident/meson.build
 create mode 100644 subprojects/proc-macro-error-attr.wrap
 create mode 100644 subprojects/proc-macro-error.wrap
 create mode 100644 subprojects/proc-macro2.wrap
 create mode 100644 subprojects/quote.wrap
 create mode 100644 subprojects/syn.wrap
 create mode 100644 subprojects/unicode-ident.wrap
MAINTAINERS +5 -0
index 018f3a9420..2b3d96fa2f 100644
@@ -1188,6 +1188,11 @@ F: include/hw/*/microbit*.h
 F: tests/qtest/microbit-test.c
 F: docs/system/arm/nrf.rst
 
+ARM PL011 Rust device
+M: Manos Pitsidianakis <[email protected]>
+S: Maintained
+F: rust/hw/char/pl011/
+
 AVR Machines
 -------------
 
hw/arm/Kconfig +22 -11
index 1ad60da7aa..45438c1bc4 100644
@@ -20,7 +20,8 @@ config ARM_VIRT
     select PCI_EXPRESS
     select PCI_EXPRESS_GENERIC_BRIDGE
     select PFLASH_CFI01
-    select PL011 # UART
+    select PL011 if !HAVE_RUST # UART
+    select X_PL011_RUST if HAVE_RUST # UART
     select PL031 # RTC
     select PL061 # GPIO
     select GPIO_PWR
@@ -80,7 +81,8 @@ config HIGHBANK
     select AHCI
     select ARM_TIMER # sp804
     select ARM_V7M
-    select PL011 # UART
+    select PL011 if !HAVE_RUST # UART
+    select X_PL011_RUST if HAVE_RUST # UART
     select PL022 # SPI
     select PL031 # RTC
     select PL061 # GPIO
@@ -93,7 +95,8 @@ config INTEGRATOR
     depends on TCG && ARM
     select ARM_TIMER
     select INTEGRATOR_DEBUG
-    select PL011 # UART
+    select PL011 if !HAVE_RUST # UART
+    select X_PL011_RUST if HAVE_RUST # UART
     select PL031 # RTC
     select PL041 # audio
     select PL050 # keyboard/mouse
@@ -119,7 +122,8 @@ config MUSCA
     default y
     depends on TCG && ARM
     select ARMSSE
-    select PL011
+    select PL011 if !HAVE_RUST # UART
+    select X_PL011_RUST if HAVE_RUST # UART
     select PL031
     select SPLIT_IRQ
     select UNIMP
@@ -228,7 +232,8 @@ config Z2
     depends on TCG && ARM
     select PFLASH_CFI01
     select WM8750
-    select PL011 # UART
+    select PL011 if !HAVE_RUST # UART
+    select X_PL011_RUST if HAVE_RUST # UART
     select PXA2XX
 
 config REALVIEW
@@ -248,7 +253,8 @@ config REALVIEW
     select WM8750 # audio codec
     select LSI_SCSI_PCI
     select PCI
-    select PL011  # UART
+    select PL011 if !HAVE_RUST # UART
+    select X_PL011_RUST if HAVE_RUST # UART
     select PL031  # RTC
     select PL041  # audio codec
     select PL050  # keyboard/mouse
@@ -273,7 +279,8 @@ config SBSA_REF
     select PCI_EXPRESS
     select PCI_EXPRESS_GENERIC_BRIDGE
     select PFLASH_CFI01
-    select PL011 # UART
+    select PL011 if !HAVE_RUST # UART
+    select X_PL011_RUST if HAVE_RUST # UART
     select PL031 # RTC
     select PL061 # GPIO
     select USB_XHCI_SYSBUS
@@ -297,7 +304,8 @@ config STELLARIS
     select ARM_V7M
     select CMSDK_APB_WATCHDOG
     select I2C
-    select PL011 # UART
+    select PL011 if !HAVE_RUST # UART
+    select X_PL011_RUST if HAVE_RUST # UART
     select PL022 # SPI
     select PL061 # GPIO
     select SSD0303 # OLED display
@@ -356,7 +364,8 @@ config VEXPRESS
     select ARM_TIMER # sp804
     select LAN9118
     select PFLASH_CFI01
-    select PL011 # UART
+    select PL011 if !HAVE_RUST # UART
+    select X_PL011_RUST if HAVE_RUST # UART
     select PL041 # audio codec
     select PL181  # display
     select REALVIEW
@@ -440,7 +449,8 @@ config RASPI
     default y
     depends on TCG && ARM
     select FRAMEBUFFER
-    select PL011 # UART
+    select PL011 if !HAVE_RUST # UART
+    select X_PL011_RUST if HAVE_RUST # UART
     select SDHCI
     select USB_DWC2
     select BCM2835_SPI
@@ -515,7 +525,8 @@ config XLNX_VERSAL
     select ARM_GIC
     select CPU_CLUSTER
     select DEVICE_TREE
-    select PL011
+    select PL011 if !HAVE_RUST # UART
+    select X_PL011_RUST if HAVE_RUST # UART
     select CADENCE
     select VIRTIO_MMIO
     select UNIMP
rust/Kconfig +1 -0
index e69de29bb2..f9f5c39098 100644
@@ -0,0 +1 @@
+source hw/Kconfig
rust/hw/Kconfig new file +2 -0
new file mode 100644
index 0000000000..4d934f30af
@@ -0,0 +1,2 @@
+# devices Kconfig
+source char/Kconfig
rust/hw/char/Kconfig new file +3 -0
new file mode 100644
index 0000000000..a1732a9e97
@@ -0,0 +1,3 @@
+config X_PL011_RUST
+    bool
+    default y if HAVE_RUST
rust/hw/char/meson.build new file +1 -0
new file mode 100644
index 0000000000..5716dc43ef
@@ -0,0 +1 @@
+subdir('pl011')
rust/hw/char/pl011/.gitignore new file +2 -0
new file mode 100644
index 0000000000..71eaff2035
@@ -0,0 +1,2 @@
+# Ignore generated bindings file overrides.
+src/bindings.rs.inc
rust/hw/char/pl011/Cargo.lock new file +125 -0

125 lines not on this page · raw message

rust/hw/char/pl011/Cargo.toml new file +26 -0
new file mode 100644
index 0000000000..67a6973da6
@@ -0,0 +1,26 @@
+[package]
+name = "pl011"
+version = "0.1.0"
+edition = "2021"
+authors = ["Manos Pitsidianakis <[email protected]>"]
+license = "GPL-2.0 OR GPL-3.0-or-later"
+readme = "README.md"
+homepage = "https://www.qemu.org"
+description = "pl011 device model for QEMU"
+repository = "https://gitlab.com/epilys/rust-for-qemu"
+resolver = "2"
+publish = false
+keywords = []
+categories = []
+
+[lib]
+crate-type = ["staticlib"]
+
+[dependencies]
+arbitrary-int = { version = "1.2.7" }
+bilge = { version = "0.2.0" }
+bilge-impl = { version = "0.2.0" }
+qemu_api = { path = "../../../qemu-api" }
+
+# Do not include in any global workspace
+[workspace]
rust/hw/char/pl011/README.md new file +31 -0
new file mode 100644
index 0000000000..cd7dea3163
@@ -0,0 +1,31 @@
+# PL011 QEMU Device Model
+
+This library implements a device model for the PrimeCell® UART (PL011)
+device in QEMU.
+
+## Build static lib
+
+Host build target must be explicitly specified:
+
+```sh
+cargo build --target x86_64-unknown-linux-gnu
+```
+
+Replace host target triplet if necessary.
+
+## Generate Rust documentation
+
+To generate docs for this crate, including private items:
+
+```sh
+cargo doc --no-deps --document-private-items --target x86_64-unknown-linux-gnu
+```
+
+To include direct dependencies like `bilge` (bitmaps for register types):
+
+```sh
+cargo tree --depth 1 -e normal --prefix none \
+ | cut -d' ' -f1 \
+ | xargs printf -- '-p %s\n' \
+ | xargs cargo doc --no-deps --document-private-items --target x86_64-unknown-linux-gnu
+```
rust/hw/char/pl011/meson.build new file +28 -0
new file mode 100644
index 0000000000..a17a823cf5
@@ -0,0 +1,28 @@
+if not config_host_data.get('CONFIG_HAVE_RUST')
+  subdir_done()
+endif
+
+add_languages('rust', required: true)
+
+
+arbitrary_int_dep = subproject('arbitrary-int').get_variable('arbitrary_int_dep')
+bilge_dep = subproject('bilge').get_variable('bilge_dep')
+bilge_impl_dep = subproject('bilge-impl').get_variable('bilge_impl_dep')
+
+_libpl011_rs = static_library(
+  'pl011',
+  files('src/lib.rs'),
+  rust_abi: 'c',
+  rust_args: rust_args + [
+    '--edition', '2021',
+  ],
+  dependencies: [
+    bilge_dep,
+    bilge_impl_dep,
+    qemu_api,
+  ],
+)
+
+specific_ss.add(when: 'CONFIG_X_PL011_RUST', if_true: [declare_dependency(
+  link_whole: [_libpl011_rs],
+)])
rust/hw/char/pl011/rustfmt.toml new file +1 -0
new file mode 120000
index 0000000000..39f97b043b
@@ -0,0 +1 @@
+../rustfmt.toml
\ No newline at end of file
rust/hw/char/pl011/src/definitions.rs new file +26 -0
new file mode 100644
index 0000000000..66070559d4
@@ -0,0 +1,26 @@
+// Copyright 2024 Manos Pitsidianakis <[email protected]>
+// SPDX-License-Identifier: GPL-2.0 OR GPL-3.0-or-later
+
+//! Definitions required by QEMU when registering the device.
+
+use core::mem::MaybeUninit;
+
+use qemu_api::bindings::*;
+
+use crate::device::PL011State;
+use qemu_api::definitions::ObjectImpl;
+
+pub const TYPE_PL011: &std::ffi::CStr = c"pl011";
+
+#[used]
+pub static VMSTATE_PL011: VMStateDescription = VMStateDescription {
+    name: PL011State::TYPE_INFO.name,
+    unmigratable: true,
+    ..unsafe { MaybeUninit::<VMStateDescription>::zeroed().assume_init() }
+};
+
+qemu_api::module_init! {
+    qom: register_type => {
+        type_register_static(&PL011State::TYPE_INFO);
+    }
+}
rust/hw/char/pl011/src/device.rs new file +586 -0

586 lines not on this page · raw message

rust/hw/char/pl011/src/device_class.rs new file +58 -0

58 lines not on this page · raw message

rust/hw/char/pl011/src/lib.rs new file +584 -0

584 lines not on this page · raw message

rust/hw/char/pl011/src/memory_ops.rs new file +56 -0

56 lines not on this page · raw message

rust/hw/meson.build new file +1 -0
new file mode 100644
index 0000000000..860196645e
@@ -0,0 +1 @@
+subdir('char')
rust/meson.build +2 -0
index a903c7c602..4c858e9d1f 100644
@@ -11,3 +11,5 @@ _lib_bindings_rs = static_library(
 )
 
 subdir('qemu-api')
+
+subdir('hw')
subprojects/.gitignore +11 -0
index adca0266be..50f173f90d 100644
@@ -6,3 +6,14 @@
 /keycodemapdb
 /libvfio-user
 /slirp
+/arbitrary-int-1.2.7
+/bilge-0.2.0
+/bilge-impl-0.2.0
+/either-1.12.0
+/itertools-0.11.0
+/proc-macro-error-1.0.4
+/proc-macro-error-attr-1.0.4
+/proc-macro2-1.0.84
+/quote-1.0.36
+/syn-2.0.66
+/unicode-ident-1.0.12
subprojects/arbitrary-int.wrap new file +9 -0
new file mode 100644
index 0000000000..d8535bdc1e
@@ -0,0 +1,9 @@
+[wrap-file]
+directory = arbitrary-int-1.2.7
+source_url = https://crates.io/api/v1/crates/arbitrary-int/1.2.7/download
+source_filename = arbitrary-int-1.2.7.tar.gz
+source_hash = c84fc003e338a6f69fbd4f7fe9f92b535ff13e9af8997f3b14b6ddff8b1df46d
+patch_directory = arbitrary-int
+
+[provide]
+dependency_names = arbitrary_int_dep
subprojects/bilge-impl.wrap new file +10 -0
new file mode 100644
index 0000000000..f0d0c22fc9
@@ -0,0 +1,10 @@
+[wrap-file]
+directory = bilge-impl-0.2.0
+source_url = https://crates.io/api/v1/crates/bilge-impl/0.2.0/download
+source_filename = bilge-impl-0.2.0.tar.gz
+source_hash = feb11e002038ad243af39c2068c8a72bcf147acf05025dcdb916fcc000adb2d8
+#method = cargo
+patch_directory = bilge-impl
+
+[provide]
+dependency_names = bilge_impl_dep
subprojects/bilge.wrap new file +10 -0
new file mode 100644
index 0000000000..a37638e356
@@ -0,0 +1,10 @@
+[wrap-file]
+directory = bilge-0.2.0
+source_url = https://crates.io/api/v1/crates/bilge/0.2.0/download
+source_filename = bilge-0.2.0.tar.gz
+source_hash = dc707ed8ebf81de5cd6c7f48f54b4c8621760926cdf35a57000747c512e67b57
+#method = cargo
+patch_directory = bilge
+
+[provide]
+dependency_names = bilge-0.2.0-rs
subprojects/either.wrap new file +10 -0
new file mode 100644
index 0000000000..df2f09a986
@@ -0,0 +1,10 @@
+[wrap-file]
+directory = either-1.12.0
+source_url = https://crates.io/api/v1/crates/either/1.12.0/download
+source_filename = either-1.12.0.tar.gz
+source_hash = 3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb23385b58b
+#method = cargo
+patch_directory = either
+
+[provide]
+dependency_names = either_dep
subprojects/itertools.wrap new file +10 -0
new file mode 100644
index 0000000000..93961e00ab
@@ -0,0 +1,10 @@
+[wrap-file]
+directory = itertools-0.11.0
+source_url = https://crates.io/api/v1/crates/itertools/0.11.0/download
+source_filename = itertools-0.11.0.tar.gz
+source_hash = b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57
+#method = cargo
+patch_directory = itertools
+
+[provide]
+dependency_names = itertools_dep
subprojects/packagefiles/arbitrary-int/meson.build new file +19 -0
new file mode 100644
index 0000000000..6ce8eac79a
@@ -0,0 +1,19 @@
+project('arbitrary-int', 'rust',
+  version: '1.2.7',
+  license: 'GPL-2.0-or-later',
+  default_options: [])
+
+_arbitrary_int_rs = static_library(
+  'arbitrary_int',
+  files('src/lib.rs'),
+  gnu_symbol_visibility: 'hidden',
+  rust_abi: 'rust',
+  rust_args: [
+    '--edition', '2021',
+  ],
+  dependencies: [],
+)
+
+arbitrary_int_dep = declare_dependency(
+  link_with: _arbitrary_int_rs,
+)
subprojects/packagefiles/bilge-impl/meson.build new file +36 -0
new file mode 100644
index 0000000000..6413afaa4d
@@ -0,0 +1,36 @@
+project('bilge-impl', 'rust',
+  version: '0.2.0',
+  license: 'GPL-2.0-or-later',
+  default_options: [])
+
+itertools_dep = subproject('itertools').get_variable('itertools_dep')
+proc_macro_error_attr_dep = subproject('proc-macro-error-attr').get_variable('proc_macro_error_attr_dep')
+proc_macro_error_dep = subproject('proc-macro-error').get_variable('proc_macro_error_dep')
+quote_dep = subproject('quote').get_variable('quote_dep')
+syn_dep = subproject('syn').get_variable('syn_dep')
+proc_macro2_dep = subproject('proc-macro2').get_variable('proc_macro2_dep')
+
+rust = import('rust')
+
+_bilge_impl_rs = rust.proc_macro(
+  'bilge_impl',
+  files('src/lib.rs'),
+  rust_args: [
+    '--edition', '2021',
+    '--cfg', 'use_fallback',
+    '--cfg', 'feature="syn-error"',
+    '--cfg', 'feature="proc-macro"',
+  ],
+  dependencies: [
+    itertools_dep,
+    proc_macro_error_attr_dep,
+    proc_macro_error_dep,
+    quote_dep,
+    syn_dep,
+    proc_macro2_dep,
+  ],
+)
+
+bilge_impl_dep = declare_dependency(
+  link_with: _bilge_impl_rs,
+)
subprojects/packagefiles/bilge/meson.build new file +25 -0
new file mode 100644
index 0000000000..05d257da61
@@ -0,0 +1,25 @@
+project(
+  'bilge',
+  'rust',
+  version : '0.2.0',
+  license : 'MIT or Apache-2.0',
+)
+
+arbitrary_int_dep = subproject('arbitrary-int').get_variable('arbitrary_int_dep')
+bilge_impl_dep = subproject('bilge-impl').get_variable('bilge_impl_dep')
+
+lib = static_library(
+  'bilge',
+  'src/lib.rs',
+  override_options : ['rust_std=2021', 'build.rust_std=2021'],
+  rust_abi : 'rust',
+  native : true,
+  dependencies: [
+    arbitrary_int_dep,
+    bilge_impl_dep,
+  ],
+)
+
+bilge_dep = declare_dependency(
+  link_with : [lib],
+)
subprojects/packagefiles/either/meson.build new file +21 -0
new file mode 100644
index 0000000000..e6ab0e849b
@@ -0,0 +1,21 @@
+project('either', 'rust',
+  version: '1.12.0',
+  license: 'GPL-2.0-or-later',
+  default_options: [])
+
+_either_rs = static_library(
+  'either',
+  files('src/lib.rs'),
+  gnu_symbol_visibility: 'hidden',
+  rust_abi: 'rust',
+  rust_args: [
+    '--edition', '2018',
+    '--cfg', 'feature="use_std"',
+    '--cfg', 'feature="use_alloc"',
+  ],
+  dependencies: [],
+)
+
+either_dep = declare_dependency(
+  link_with: _either_rs,
+)
subprojects/packagefiles/itertools/meson.build new file +25 -0
new file mode 100644
index 0000000000..d897a615f0
@@ -0,0 +1,25 @@
+project('itertools', 'rust',
+  version: '0.11.0',
+  license: 'GPL-2.0-or-later',
+  default_options: [])
+
+either_dep = subproject('either').get_variable('either_dep')
+
+_itertools_rs = static_library(
+  'itertools',
+  files('src/lib.rs'),
+  gnu_symbol_visibility: 'hidden',
+  rust_abi: 'rust',
+  rust_args: [
+    '--edition', '2018',
+    '--cfg', 'feature="use_std"',
+    '--cfg', 'feature="use_alloc"',
+  ],
+  dependencies: [
+    either_dep,
+  ],
+)
+
+itertools_dep = declare_dependency(
+  link_with: _itertools_rs,
+)
subprojects/packagefiles/proc-macro-error-attr/meson.build new file +27 -0
new file mode 100644
index 0000000000..ed0f05e9e6
@@ -0,0 +1,27 @@
+project('proc-macro-error-attr', 'rust',
+  version: '1.12.0',
+  license: 'GPL-2.0-or-later',
+  default_options: [])
+
+proc_macro2_dep = subproject('proc-macro2').get_variable('proc_macro2_dep')
+quote_dep = subproject('quote').get_variable('quote_dep')
+
+rust = import('rust')
+_proc_macro_error_attr_rs = rust.proc_macro(
+  'proc_macro_error_attr',
+  files('src/lib.rs'),
+  rust_args: [
+    '--edition', '2018',
+    '--cfg', 'use_fallback',
+    '--cfg', 'feature="syn-error"',
+    '--cfg', 'feature="proc-macro"'
+  ],
+  dependencies: [
+    proc_macro2_dep,
+    quote_dep,
+  ],
+)
+
+proc_macro_error_attr_dep = declare_dependency(
+  link_with: _proc_macro_error_attr_rs,
+)
subprojects/packagefiles/proc-macro-error/meson.build new file +32 -0
new file mode 100644
index 0000000000..4c9e4f70ef
@@ -0,0 +1,32 @@
+project('proc-macro-error', 'rust',
+  version: '1.0.4',
+  license: 'GPL-2.0-or-later',
+  default_options: [])
+
+proc_macro_error_attr_dep = subproject('proc-macro-error-attr').get_variable('proc_macro_error_attr_dep')
+proc_macro2_dep = subproject('proc-macro2').get_variable('proc_macro2_dep')
+quote_dep = subproject('quote').get_variable('quote_dep')
+syn_dep = subproject('syn').get_variable('syn_dep')
+
+_proc_macro_error_rs = static_library(
+  'proc_macro_error',
+  files('src/lib.rs'),
+  rust_abi: 'rust',
+  rust_args: [
+    '--edition', '2018',
+    '--cfg', 'use_fallback',
+    '--cfg', 'feature="syn-error"',
+    '--cfg', 'feature="proc-macro"',
+    '-A', 'non_fmt_panics'
+  ],
+  dependencies: [
+    proc_macro_error_attr_dep,
+    proc_macro2_dep,
+    quote_dep,
+    syn_dep,
+  ],
+)
+
+proc_macro_error_dep = declare_dependency(
+  link_with: _proc_macro_error_rs,
+)
subprojects/packagefiles/proc-macro2/meson.build new file +26 -0
new file mode 100644
index 0000000000..9efb441b7a
@@ -0,0 +1,26 @@
+project('proc-macro2', 'rust',
+  version: '1.0.84',
+  license: 'GPL-2.0-or-later',
+  default_options: [])
+
+unicode_ident_dep = subproject('unicode-ident').get_variable('unicode_ident_dep')
+
+_proc_macro2_rs = static_library(
+  'proc_macro2',
+  files('src/lib.rs'),
+  gnu_symbol_visibility: 'hidden',
+  rust_abi: 'rust',
+  rust_args: [
+    '--edition', '2021',
+    '--cfg', 'feature="proc-macro"',
+    '--cfg', 'span_locations',
+    '--cfg', 'wrap_proc_macro',
+  ],
+  dependencies: [
+    unicode_ident_dep,
+  ],
+)
+
+proc_macro2_dep = declare_dependency(
+  link_with: _proc_macro2_rs,
+)
subprojects/packagefiles/quote/meson.build new file +25 -0
new file mode 100644
index 0000000000..4570e93b19
@@ -0,0 +1,25 @@
+project('quote', 'rust',
+  version: '1.12.0',
+  license: 'GPL-2.0-or-later',
+  default_options: [])
+
+proc_macro2_dep = subproject('proc-macro2').get_variable('proc_macro2_dep')
+
+_quote_rs = static_library(
+  'quote',
+  files('src/lib.rs'),
+  gnu_symbol_visibility: 'hidden',
+  rust_abi: 'rust',
+  rust_args: [
+    '--edition', '2021',
+    '--cfg', 'feature="proc-macro"',
+  ],
+  dependencies: [
+    proc_macro2_dep,
+    ],
+)
+
+quote_dep = declare_dependency(
+  link_with: _quote_rs,
+)
+
subprojects/packagefiles/syn/meson.build new file +33 -0
new file mode 100644
index 0000000000..104791f5c7
@@ -0,0 +1,33 @@
+project('syn', 'rust',
+  version: '2.0.66',
+  license: 'GPL-2.0-or-later',
+  default_options: [])
+
+quote_dep = subproject('quote').get_variable('quote_dep')
+proc_macro2_dep = subproject('proc-macro2').get_variable('proc_macro2_dep')
+unicode_ident_dep = subproject('unicode-ident').get_variable('unicode_ident_dep')
+
+_syn_rs = static_library(
+  'syn',
+  files('src/lib.rs'),
+  gnu_symbol_visibility: 'hidden',
+  rust_abi: 'rust',
+  rust_args: [
+    '--edition', '2021',
+    '--cfg', 'feature="full"',
+    '--cfg', 'feature="derive"',
+    '--cfg', 'feature="parsing"',
+    '--cfg', 'feature="printing"',
+    '--cfg', 'feature="clone-impls"',
+    '--cfg', 'feature="proc-macro"',
+  ],
+  dependencies: [
+    quote_dep,
+    proc_macro2_dep,
+    unicode_ident_dep,
+  ],
+)
+
+syn_dep = declare_dependency(
+  link_with: _syn_rs,
+)
subprojects/packagefiles/unicode-ident/meson.build new file +19 -0
new file mode 100644
index 0000000000..c81217de09
@@ -0,0 +1,19 @@
+project('unicode-ident', 'rust',
+  version: '1.0.12',
+  license: 'GPL-2.0-or-later',
+  default_options: [])
+
+_unicode_ident_rs = static_library(
+  'unicode_ident',
+  files('src/lib.rs'),
+  gnu_symbol_visibility: 'hidden',
+  rust_abi: 'rust',
+  rust_args: [
+    '--edition', '2021',
+  ],
+  dependencies: [],
+)
+
+unicode_ident_dep = declare_dependency(
+  link_with: _unicode_ident_rs,
+)
subprojects/proc-macro-error-attr.wrap new file +10 -0
new file mode 100644
index 0000000000..f24dbaadf3
@@ -0,0 +1,10 @@
+[wrap-file]
+directory = proc-macro-error-attr-1.0.4
+source_url = https://crates.io/api/v1/crates/proc-macro-error-attr/1.0.4/download
+source_filename = proc-macro-erro-attrr-1.0.4.tar.gz
+source_hash = a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869
+#method = cargo
+patch_directory = proc-macro-error-attr
+
+[provide]
+dependency_names = proc_macro_error_attr_dep
subprojects/proc-macro-error.wrap new file +11 -0
new file mode 100644
index 0000000000..95110ef94f
@@ -0,0 +1,11 @@
+[wrap-file]
+directory = proc-macro-error-1.0.4
+source_url = https://crates.io/api/v1/crates/proc-macro-error/1.0.4/download
+source_filename = proc-macro-error-1.0.4.tar.gz
+source_hash = da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c
+#method = cargo
+patch_directory = proc-macro-error
+
+[provide]
+dependency_names = proc_macro_error_dep
+
subprojects/proc-macro2.wrap new file +10 -0
new file mode 100644
index 0000000000..70849b9944
@@ -0,0 +1,10 @@
+[wrap-file]
+directory = proc-macro2-1.0.84
+source_url = https://crates.io/api/v1/crates/proc-macro2/1.0.84/download
+source_filename = proc-macro2-1.0.84.0.tar.gz
+source_hash = ec96c6a92621310b51366f1e28d05ef11489516e93be030060e5fc12024a49d6
+#method = cargo
+patch_directory = proc-macro2
+
+[provide]
+dependency_names = proc_macro2_dep
subprojects/quote.wrap new file +10 -0
new file mode 100644
index 0000000000..82836107cb
@@ -0,0 +1,10 @@
+[wrap-file]
+directory = quote-1.0.36
+source_url = https://crates.io/api/v1/crates/quote/1.0.36/download
+source_filename = quote-1.0.36.0.tar.gz
+source_hash = 0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7
+#method = cargo
+patch_directory = quote
+
+[provide]
+dependency_names = quote_dep
subprojects/syn.wrap new file +11 -0
new file mode 100644
index 0000000000..f5ebe033de
@@ -0,0 +1,11 @@
+[wrap-file]
+directory = syn-2.0.66
+source_url = https://crates.io/api/v1/crates/syn/2.0.66/download
+source_filename = syn-2.0.66.0.tar.gz
+source_hash = c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5
+#method = cargo
+patch_directory = syn
+
+[provide]
+dependency_names = syn_dep
+
subprojects/unicode-ident.wrap new file +10 -0
new file mode 100644
index 0000000000..7b5304ccac
@@ -0,0 +1,10 @@
+[wrap-file]
+directory = unicode-ident-1.0.12
+source_url = https://crates.io/api/v1/crates/unicode-ident/1.0.12/download
+source_filename = unicode-ident-1.0.12.tar.gz
+source_hash = 3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b
+#method = cargo
+patch_directory = unicode-ident
+
+[provide]
+dependency_names = unicode_ident_dep
Signature · 1 line
γαῖα πυρί μιχθήτω
#8 lore raw

Re: [RFC PATCH v6 5/5] rust: add PL011 device model

rust/hw/char/pl011/meson.build line 5

Quoted 11 lines · Manos Pitsidianakis
rust/hw/char/pl011/meson.build new file +5 -0
new file mode 100644
index 0000000000..a17a823cf5
@@ -0,0 +1,28 @@
+if not config_host_data.get('CONFIG_HAVE_RUST')
+  subdir_done()
+endif
+
+add_languages('rust', required: true)

These five lines are not necessary.

rust/hw/char/pl011/meson.build line 10

Quoted 3 lines
rust/hw/char/pl011/meson.build new file +3 -0
+arbitrary_int_dep = subproject('arbitrary-int').get_variable('arbitrary_int_dep')
+bilge_dep = subproject('bilge').get_variable('bilge_dep')
+bilge_impl_dep = subproject('bilge-impl').get_variable('bilge_impl_dep')

The subprojects also need to be added to scripts/archive-source.sh and scripts/make-release.

In order to simplify a future switch to Cargo projects, this should be something like:

subproject('bilge-0.2-rs', required: true)
subproject('bilge-impl-0.2-rs', required: true)

bilge_dep = dependency('bilge-0.2-rs')
bilge_impl_dep = dependency('bilge-impl-0.2-rs')

with a corresponding

meson.override_dependency('bilge-0.2-rs', bilge_dep)

in subprojects/packagefiles/bilge-0.2-rs/meson.build.

Also in bilge's meson.build:

rust/hw/char/pl011/meson.build line 18

Quoted 10 lines
rust/hw/char/pl011/meson.build new file +10 -0
+arbitrary_int_dep = subproject('arbitrary-int').get_variable('arbitrary_int_dep')
+bilge_impl_dep = subproject('bilge-impl').get_variable('bilge_impl_dep')
+
+lib = static_library(
+  'bilge',
+  'src/lib.rs',
+  override_options : ['rust_std=2021', 'build.rust_std=2021'],
+  rust_abi : 'rust',
+  native : true,
+  dependencies: [

native should not be true here (but it should be true for the dependencies of bilge-impl: either, itertools, proc-macro-error, proc-macro-error-attr, proc-macro2, quote, syn, unicode-ident).

I've placed my updates at a branch "rust-for-manos" of https://gitlab.com/bonzini/qemu/. I left the fixes unsquashed for your review, but feel free to merge them and post the result as part of v7.

Paolo

#9 lore raw

Re: [RFC PATCH v6 5/5] rust: add PL011 device model

Quoted 1 line · Paolo Bonzini

On 8/4/24 23:04, Manos Pitsidianakis wrote:

[snip]

Quoted 16 lines

Also in bilge's meson.build:

Review

Quoted 11 lines

+arbitrary_int_dep = subproject('arbitrary-int').get_variable('arbitrary_int_dep')

(quoted diff) +9 -0
+bilge_impl_dep = subproject('bilge-impl').get_variable('bilge_impl_dep')
+
+lib = static_library(
+  'bilge',
+  'src/lib.rs',
+  override_options : ['rust_std=2021', 'build.rust_std=2021'],
+  rust_abi : 'rust',
+  native : true,
+  dependencies: [

native should not be true here (but it should be true for the dependencies of bilge-impl: either, itertools, proc-macro-error, proc-macro-error-attr, proc-macro2, quote, syn, unicode-ident).

Quoted 1 line

I've placed my updates at a branch "rust-for-manos" of https://gitlab.com/bonzini/qemu/.  I left the fixes unsquashed for your review, but feel free to merge them and post the result as part of v7.

I tested that branch by a cross-build to aarch64 on an x86_64 machine (with "./configure --cross-prefix=aarch64-linux-gnu- --rust-target-triple=aarch64-unknown-linux-gnu"). To configure successfully, I need to add "native: true" to every "dependency()" that refers to those dependencies. Also their "override_dependency" needs a "native: true" as well. Here are my detailed changes:

========

subprojects/packagefiles/bilge-impl-0.2-rs/meson.build +1 -1
index ef1af5683a..a5f04bfeca 100644
@@ -11,7 +11,7 @@ subproject('syn-2-rs', required: true)
 subproject('proc-macro2-1-rs', required: true)
 
 itertools_dep = dependency('itertools-0.11-rs-native', native: true)
-proc_macro_error_attr_dep = dependency('proc-macro-error-attr-1-rs')
+proc_macro_error_attr_dep = dependency('proc-macro-error-attr-1-rs-native', native: true)
 proc_macro_error_dep = dependency('proc-macro-error-1-rs-native', native: true)
 quote_dep = dependency('quote-1-rs-native', native: true)
 syn_dep = dependency('syn-2-rs-native', native: true)
subprojects/packagefiles/either-1-rs/meson.build +1 -1
index 0101ffe446..8a92596cd0 100644
@@ -21,4 +21,4 @@ either_dep = declare_dependency(
   link_with: _either_rs,
 )
 
-meson.override_dependency('either-1-rs-native', either_dep)
+meson.override_dependency('either-1-rs-native', either_dep, native: true)
subprojects/packagefiles/itertools-0.11-rs/meson.build +2 -2
index 903913eb1d..6c2d1387e0 100644
@@ -5,7 +5,7 @@ project('itertools-0.11-rs', 'rust',
 
 subproject('either-1-rs', required: true)
 
-either_dep = dependency('either-1-rs-native')
+either_dep = dependency('either-1-rs-native', native: true)
 
 _itertools_rs = static_library(
   'itertools',
@@ -27,4 +27,4 @@ itertools_dep = declare_dependency(
   link_with: _itertools_rs,
 )
 
-meson.override_dependency('itertools-0.11-rs-native', itertools_dep)
+meson.override_dependency('itertools-0.11-rs-native', itertools_dep, native: true)
subprojects/packagefiles/proc-macro-error-1-rs/meson.build +5 -5
index f65e319ec7..673675930f 100644
@@ -8,10 +8,10 @@ subproject('quote-1-rs', required: true)
 subproject('syn-2-rs', required: true)
 subproject('proc-macro2-1-rs', required: true)
 
-proc_macro_error_attr_dep = dependency('proc-macro-error-attr-1-rs')
-proc_macro2_dep = dependency('proc-macro2-1-rs-native')
-quote_dep = dependency('quote-1-rs-native')
-syn_dep = dependency('syn-2-rs-native')
+proc_macro_error_attr_dep = dependency('proc-macro-error-attr-1-rs-native', native: true)
+proc_macro2_dep = dependency('proc-macro2-1-rs-native', native: true)
+quote_dep = dependency('quote-1-rs-native', native: true)
+syn_dep = dependency('syn-2-rs-native', native: true)
 
 _proc_macro_error_rs = static_library(
   'proc_macro_error',
@@ -37,4 +37,4 @@ proc_macro_error_dep = declare_dependency(
   link_with: _proc_macro_error_rs,
 )
 
-meson.override_dependency('proc-macro-error-1-rs-native', proc_macro_error_dep)
+meson.override_dependency('proc-macro-error-1-rs-native', proc_macro_error_dep, native: true)
subprojects/packagefiles/proc-macro-error-attr-1-rs/meson.build +3 -3
index 5c4e99f248..b6f25811eb 100644
@@ -6,8 +6,8 @@ project('proc-macro-error-attr-1-rs', 'rust',
 subproject('proc-macro2-1-rs', required: true)
 subproject('quote-1-rs', required: true)
 
-proc_macro2_dep = dependency('proc-macro2-1-rs-native')
-quote_dep = dependency('quote-1-rs-native')
+proc_macro2_dep = dependency('proc-macro2-1-rs-native', native: true)
+quote_dep = dependency('quote-1-rs-native', native: true)
 
 rust = import('rust')
 _proc_macro_error_attr_rs = rust.proc_macro(
@@ -29,4 +29,4 @@ proc_macro_error_attr_dep = declare_dependency(
   link_with: _proc_macro_error_attr_rs,
 )
 
-meson.override_dependency('proc-macro-error-attr-1-rs', proc_macro_error_attr_dep)
+meson.override_dependency('proc-macro-error-attr-1-rs-native', proc_macro_error_attr_dep, native: true)
subprojects/packagefiles/proc-macro2-1-rs/meson.build +1 -1
index 06279a8a6c..a5f4c11f82 100644
@@ -30,4 +30,4 @@ proc_macro2_dep = declare_dependency(
   link_with: _proc_macro2_rs,
 )
 
-meson.override_dependency('proc-macro2-1-rs-native', proc_macro2_dep)
+meson.override_dependency('proc-macro2-1-rs-native', proc_macro2_dep, native: true)
subprojects/packagefiles/quote-1-rs/meson.build +2 -2
index 4663295ccc..41feed9683 100644
@@ -5,7 +5,7 @@ project('quote-1-rs', 'rust',
 
 subproject('proc-macro2-1-rs', required: true)
 
-proc_macro2_dep = dependency('proc-macro2-1-rs-native')
+proc_macro2_dep = dependency('proc-macro2-1-rs-native', native: true)
 
 _quote_rs = static_library(
   'quote',
@@ -26,4 +26,4 @@ quote_dep = declare_dependency(
   link_with: _quote_rs,
 )
 
-meson.override_dependency('quote-1-rs-native', quote_dep)
+meson.override_dependency('quote-1-rs-native', quote_dep, native: true)
subprojects/packagefiles/syn-2-rs/meson.build +3 -3
index 21d817a33e..61cfc469c1 100644
@@ -7,8 +7,8 @@ subproject('proc-macro2-1-rs', required: true)
 subproject('quote-1-rs', required: true)
 subproject('unicode-ident-1-rs', required: true)
 
-proc_macro2_dep = dependency('proc-macro2-1-rs-native')
-quote_dep = dependency('quote-1-rs-native')
+proc_macro2_dep = dependency('proc-macro2-1-rs-native', native: true)
+quote_dep = dependency('quote-1-rs-native', native: true)
 unicode_ident_dep = dependency('unicode-ident-1-rs-native', native: true)
 
 _syn_rs = static_library(
@@ -37,4 +37,4 @@ syn_dep = declare_dependency(
   link_with: _syn_rs,
 )
 
-meson.override_dependency('syn-2-rs-native', syn_dep)
+meson.override_dependency('syn-2-rs-native', syn_dep, native: true)
subprojects/packagefiles/unicode-ident-1-rs/meson.build +1 -1
index 80d088282c..c398f59211 100644
@@ -19,4 +19,4 @@ unicode_ident_dep = declare_dependency(
   link_with: _unicode_ident_rs,
 )
 
-meson.override_dependency('unicode-ident-1-rs-native', unicode_ident_dep)
+meson.override_dependency('unicode-ident-1-rs-native', unicode_ident_dep, native: true)

========

Besides, I think we don't need the "-native" suffix in the dependency names since we already have that "native: true" argument. I also tested configuration and build after execute "find . -name 'meson.build' | xargs -n 1 sed -i 's/-native//g'" under subprojects/packagefiles, and it worked as well.

With the changes above, I'm able to cross-build except for one known linking issue [1].

[1] https://github.com/llvm/llvm-project/pull/93890

Thanks
Junjie Mao

Quoted 5 lines

Paolo

#10 lore raw

Re: [RFC PATCH v6 5/5] rust: add PL011 device model

Quoted 6 lines · Junjie Mao

I tested that branch by a cross-build to aarch64 on an x86_64 machine (with "./configure --cross-prefix=aarch64-linux-gnu- --rust-target-triple=aarch64-unknown-linux-gnu"). To configure successfully, I need to add "native: true" to every "dependency()" that refers to those dependencies. Also their "override_dependency" needs a "native: true" as well. Here are my detailed changes:

Great, thanks for the testing. I applied your changes and also removed "-native" according to your suggestion.

Paolo

#11 lore raw
In reply to Manos Pitsidianakis
Quoted 8 lines · Manos Pitsidianakis

Changes
=======

- Setting MSRV to 1.77.0:
* cstr crate MSRV is 1.64, which is more recent than Debian bookworm

     (1.63.0) <https://github.com/upsuper/cstr/blob/master/Cargo.toml>

* pl011's dependencies (mostly proc-macro2) don't support 1.63.0

proc-macro2 is listed as supporting 1.56.0, and in general I don't see particularly high MSRVs for any of your dependencies.

cstr needs to use version 0.2.10 in order to work with Rust 1.63.0.

As discussed on IRC, there are obvious advantages and disadvantages to using meson. The main disadvantage is the extra work when bumping the version of the dependencies or when adding a new one. The advantage is more uniformity and less moving parts. Overall, I think it's doable to use it. Dependencies will mostly be added in the early days of QEMU, and won't be updated too often due to our MSRV constraints.

The automatic Cargo.toml support in Meson is promising, but it doesn't work right now when cross compiling build-time dependencies (which have to use "native: true" or Meson rightly warns about mixing build-machine and host-machine binaries). So right now we'd have to write meson.build by hand for those.

My suggestion is however to name our manually-managed subprojects with the same convention that is used by "method = cargo" in Meson 1.5.0+, i.e. name-APIVER-rs:

	arbitrary-int-1-rs.wrap
	bilge-0.2-rs.wrap
	bilge-impl-0.2-rs.wrap
	either-1-rs.wrap
	itertools-0.11-rs.wrap
	proc-macro2-1-rs.wrap
	proc-macro-error-1-rs.wrap
	proc-macro-error-attr-1-rs.wrap
	quote-1-rs.wrap
	syn-2-rs.wrap
	unicode-ident-1-rs.wrap

and to access dependencies using meson.override_dependency() and dependency(), instead of get_variable(). This at least reduces future churn.

As to the individual patches:

- for patch 1, roughly the same changes I had made for cargo can be done for rustc, so that the cross file contains the right --target option. I'll reply to the individual patch.

- for patch 2, the only issue is that you are specifying --no-include-path-detection and that breaks for me on Fedora. I have not finished testing but it seems that it's enough to remove that line.

- for patches 4 and 5, I have minimal comments on the meson.build. For patch 5, however, I have already done the above renaming as part of getting cross compilation to work. We can synchronize on IRC on the best way of getting the changes to you.

Paolo

#12 lore raw
Quoted 11 lines · Paolo Bonzini
Quoted 8 lines · Manos Pitsidianakis

Changes
=======

- Setting MSRV to 1.77.0:
* cstr crate MSRV is 1.64, which is more recent than Debian bookworm

     (1.63.0) <https://github.com/upsuper/cstr/blob/master/Cargo.toml>

* pl011's dependencies (mostly proc-macro2) don't support 1.63.0

proc-macro2 is listed as supporting 1.56.0, and in general I don't see particularly high MSRVs for any of your dependencies.

The issue was with transitive deps, proc-macro-error crates etc stopped compiling when lowering the version, which means we'd have to patch the dependency's dependency to see if that'd work; otherwise, yes!

Quoted 21 lines

cstr needs to use version 0.2.10 in order to work with Rust 1.63.0.

As discussed on IRC, there are obvious advantages and disadvantages to using meson. The main disadvantage is the extra work when bumping the version of the dependencies or when adding a new one. The advantage is more uniformity and less moving parts. Overall, I think it's doable to use it. Dependencies will mostly be added in the early days of QEMU, and won't be updated too often due to our MSRV constraints.

The automatic Cargo.toml support in Meson is promising, but it doesn't work right now when cross compiling build-time dependencies (which have to use "native: true" or Meson rightly warns about mixing build-machine and host-machine binaries). So right now we'd have to write meson.build by hand for those.

My suggestion is however to name our manually-managed subprojects with the same convention that is used by "method = cargo" in Meson 1.5.0+, i.e. name-APIVER-rs:

	arbitrary-int-1-rs.wrap
	bilge-0.2-rs.wrap
	bilge-impl-0.2-rs.wrap
	either-1-rs.wrap
	itertools-0.11-rs.wrap
	proc-macro2-1-rs.wrap
	proc-macro-error-1-rs.wrap
	proc-macro-error-attr-1-rs.wrap
	quote-1-rs.wrap
	syn-2-rs.wrap
	unicode-ident-1-rs.wrap
Quoted 1 line

and to access dependencies using meson.override_dependency() and dependency(), instead of get_variable(). This at least reduces future churn.

Yes that makes sense!

Quoted 5 lines

As to the individual patches:

- for patch 1, roughly the same changes I had made for cargo can be done
for rustc, so that the cross file contains the right --target option. I'll reply to the individual patch.

That'd be great since I'm not familiar with how the cross file works.

Quoted 4 lines

- for patch 2, the only issue is that you are specifying --no-include-path-detection and that breaks for me on Fedora. I have not finished testing but it seems that it's enough to remove that line.

I had added that when trying to debug bindgen failing to find headers when dependencies were added (e.g. linux io_uring) or when compiling on macos, let's test again to see if it's indeed unnecessary!

Quoted 4 lines

- for patches 4 and 5, I have minimal comments on the meson.build. For
patch 5, however, I have already done the above renaming as part of getting cross compilation to work. We can synchronize on IRC on the best way of getting the changes to you.

Sounds good to me.

Thanks,
Manos

#13 lore raw
Quoted 10 lines · Manos Pitsidianakis
Quoted 8 lines · Paolo Bonzini
Quoted 7 lines · Manos Pitsidianakis

Changes
=======

- Setting MSRV to 1.77.0:
* cstr crate MSRV is 1.64, which is more recent than Debian bookworm

     (1.63.0) <https://github.com/upsuper/cstr/blob/master/Cargo.toml>
Quoted 8 lines
Quoted 4 lines
Quoted 1 line

* pl011's dependencies (mostly proc-macro2) don't support 1.63.0

proc-macro2 is listed as supporting 1.56.0, and in general I don't see particularly high MSRVs for any of your dependencies.

The issue was with transitive deps, proc-macro-error crates etc stopped compiling when lowering the version, which means we'd have to patch the dependency's dependency to see if that'd work; otherwise, yes!

Ah, I see now - you have to set the right cfg for proc-macro2 to compile with 1.63.0. Normally (including with "method = cargo") they are detected by build.rs:

    if rustc < 66 {
        println!("cargo:rustc-cfg=no_source_text");
    }

    if rustc < 79 {
        println!("cargo:rustc-cfg=no_literal_byte_character");
        println!("cargo:rustc-cfg=no_literal_c_string");
    }

(Meson's support for build.rs is very limited, but it does handle some simple cases and parses rustc-cfg from the output).

And bilge-impl uses let...else; we can patch it locally via the .wrap file's "diff_files" entry. Not great, but it's good that we can do it and that we have an example for similar issues in the future.

I updated my rust-for-manos branch with these discoveries. Of course it doesn't compile with 1.63.0 but it does at least configure successfully with

../configure --rustc=$(rustup +1.63.0 which rustc) --enable-rust

and build the subprojects' rlibs.

Quoted 6 lines
Quoted 4 lines

The automatic Cargo.toml support in Meson is promising [...] My suggestion is to name our manually-managed subprojects with the same convention that is used by "method = cargo" in Meson 1.5.0+, i.e. name-APIVER-rs:

Yes that makes sense!

Good!

Quoted 7 lines
Quoted 3 lines

- for patch 2, the only issue is that you are specifying --no-include-path-detection and that breaks for me on Fedora. I have not finished testing but it seems that it's enough to remove that line.

I had added that when trying to debug bindgen failing to find headers when dependencies were added (e.g. linux io_uring) or when compiling on macos, let's test again to see if it's indeed unnecessary!

Ok, crossing fingers.

Paolo