qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>,
	qemu-devel@nongnu.org
Cc: "Stefan Hajnoczi" <stefanha@redhat.com>,
	"Mads Ynddal" <mads@ynddal.dk>,
	"Peter Maydell" <peter.maydell@linaro.org>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"Daniel P. Berrangé" <berrange@redhat.com>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Thomas Huth" <thuth@redhat.com>,
	"Markus Armbruster" <armbru@redhat.com>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>,
	"Zhao Liu" <zhao1.liu@intel.com>,
	"Gustavo Romero" <gustavo.romero@linaro.org>,
	"Pierrick Bouvier" <pierrick.bouvier@linaro.org>,
	rowan.hart@intel.com,
	"Richard Henderson" <richard.henderson@linaro.org>
Subject: Re: [RFC PATCH v6 1/5] build-sys: Add rust feature option
Date: Thu, 8 Aug 2024 10:09:48 +0200	[thread overview]
Message-ID: <d3aee5cd-b92c-40d5-8f37-c0cc0facfe48@redhat.com> (raw)
In-Reply-To: <rust-pl011-rfc-v6-1.git.manos.pitsidianakis@linaro.org>

On 8/4/24 23:04, Manos Pitsidianakis wrote:
> diff --git a/configure b/configure
> index 019fcbd0ef..aac7f29f25 100755
> --- a/configure
> +++ b/configure
> @@ -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)

>     --enable-debug           enable common debug build options
>     --cpu=CPU                Build for host CPU [$cpu]
>     --disable-containers     don't use containers for cross-building
> diff --git a/meson.build b/meson.build
> index 97f63aa86c..9593fce47f 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -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).

> +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:

diff --git a/configure b/configure
index aac7f29f25c..f2d5a9a8d40 100755
--- a/configure
+++ b/configure
@@ -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"
diff --git a/meson.build b/meson.build
index b89ce025c1a..e656ef34aab 100644
--- a/meson.build
+++ b/meson.build
@@ -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'




  reply	other threads:[~2024-08-08  8:10 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-04 21:04 [RFC PATCH v6 0/5] rust-pl011-rfc-v6 Manos Pitsidianakis
2024-08-04 21:04 ` [RFC PATCH v6 1/5] build-sys: Add rust feature option Manos Pitsidianakis
2024-08-08  8:09   ` Paolo Bonzini [this message]
2024-08-04 21:04 ` [RFC PATCH v6 2/5] rust: add bindgen step as a meson dependency Manos Pitsidianakis
2024-08-04 21:04 ` [RFC PATCH v6 3/5] .gitattributes: add Rust diff and merge attributes Manos Pitsidianakis
2024-08-04 21:04 ` [RFC PATCH v6 4/5] rust: add crate to expose bindings and interfaces Manos Pitsidianakis
2024-08-08  8:13   ` Paolo Bonzini
2024-08-04 21:04 ` [RFC PATCH v6 5/5] rust: add PL011 device model Manos Pitsidianakis
2024-08-08  8:31   ` Paolo Bonzini
2024-08-12  8:50     ` Junjie Mao
2024-08-12  9:29       ` Paolo Bonzini
2024-08-08  6:10 ` [RFC PATCH v6 0/5] rust-pl011-rfc-v6 Paolo Bonzini
2024-08-08  7:49   ` Manos Pitsidianakis
2024-08-08 10:09     ` 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=d3aee5cd-b92c-40d5-8f37-c0cc0facfe48@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=alex.bennee@linaro.org \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=gustavo.romero@linaro.org \
    --cc=mads@ynddal.dk \
    --cc=manos.pitsidianakis@linaro.org \
    --cc=marcandre.lureau@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=rowan.hart@intel.com \
    --cc=stefanha@redhat.com \
    --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).