qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[RFC v3 10/32] build-sys: add --with-rust{-target} & basic build infrast


From: marcandre . lureau
Subject: [RFC v3 10/32] build-sys: add --with-rust{-target} & basic build infrastructure
Date: Tue, 7 Sep 2021 16:19:21 +0400

From: Marc-André Lureau <marcandre.lureau@redhat.com>

Add the build-sys infrastructure to optionally build Rust code.
Introduce a top-level workspace, so various sub-projects (libraries,
executables etc) can be developed together, sharing the dependencies and
output directory.

If not Tier 1 (aarch64 and x86), all of the host architecture QEMU
supports should be Tier 2:
https://doc.rust-lang.org/nightly/rustc/platform-support.html

Rust is generally available on various distributions (thanks to Firefox,
I suppose). If not, it can usually be installed with rustup.

configure will enable Rust support automatically if cargo is present.
Rust support can be disabled --without-rust. When detecting windows
cross building, it will use the $cpu-pc-windows-gnu target by
default (more default mappings could be added over time). This can be
changed with --with-rust-target=RTT.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 configure         | 11 +++++++++++
 meson.build       | 27 +++++++++++++++++++++++++++
 .gitignore        |  1 +
 Cargo.toml        |  2 ++
 meson_options.txt |  5 +++++
 5 files changed, 46 insertions(+)
 create mode 100644 Cargo.toml

diff --git a/configure b/configure
index 48ff2837d9..470b90543f 100755
--- a/configure
+++ b/configure
@@ -445,6 +445,8 @@ fuse="auto"
 fuse_lseek="auto"
 multiprocess="auto"
 slirp_smbd="$default_feature"
+with_rust="auto"
+with_rust_target=""
 
 malloc_trim="auto"
 gio="$default_feature"
@@ -1586,6 +1588,12 @@ for opt do
   ;;
   --disable-slirp-smbd) slirp_smbd=no
   ;;
+  --with-rust) with_rust=enabled
+  ;;
+  --without-rust) with_rust=disabled
+  ;;
+  --with-rust-target=*) with_rust_target="$optarg"
+  ;;
   *)
       echo "ERROR: unknown option $opt"
       echo "Try '$0 --help' for more information"
@@ -1773,6 +1781,8 @@ Advanced options (experts only):
   --extra-ldflags=LDFLAGS  append extra linker flags LDFLAGS
   --cross-cc-ARCH=CC       use compiler when building ARCH guest test cases
   --cross-cc-flags-ARCH=   use compiler flags when building ARCH guest tests
+  --with-rust              enable Rust compilation
+  --with-rust-target=RTT   use the given Rust target triple
   --make=MAKE              use specified make [$make]
   --python=PYTHON          use specified python [$python]
   --sphinx-build=SPHINX    use specified sphinx-build [$sphinx_build]
@@ -5199,6 +5209,7 @@ if test "$skip_meson" = no; then
         -Db_coverage=$(if test "$gcov" = yes; then echo true; else echo false; 
fi) \
         -Db_lto=$lto -Dcfi=$cfi -Dcfi_debug=$cfi_debug \
         -Dmalloc=$malloc -Dmalloc_trim=$malloc_trim -Dsparse=$sparse \
+        -Dwith_rust=$with_rust -Dwith_rust_target=$with_rust_target \
         -Dkvm=$kvm -Dhax=$hax -Dwhpx=$whpx -Dhvf=$hvf -Dnvmm=$nvmm \
         -Dxen=$xen -Dxen_pci_passthrough=$xen_pci_passthrough -Dtcg=$tcg \
         -Dcocoa=$cocoa -Dgtk=$gtk -Dmpath=$mpath -Dsdl=$sdl 
-Dsdl_image=$sdl_image \
diff --git a/meson.build b/meson.build
index cbf3ce19ae..63b61a2bc8 100644
--- a/meson.build
+++ b/meson.build
@@ -108,6 +108,29 @@ endif
 
 bzip2 = find_program('bzip2', required: install_edk2_blobs)
 
+cargo = find_program('cargo', required: get_option('with_rust'))
+with_rust = cargo.found()
+
+if with_rust
+  rust_target_triple = get_option('with_rust_target')
+  if meson.is_cross_build()
+    # more default target mappings may be added over time
+    if rust_target_triple == '' and targetos == 'windows'
+      rust_target_triple = host_machine.cpu() + '-pc-windows-gnu'
+    endif
+    if rust_target_triple == ''
+      error('cross-compiling, but no Rust target-triple defined.')
+    endif
+  endif
+endif
+config_host_data.set('CONFIG_WITH_RUST', with_rust)
+
+if get_option('optimization') in ['0', '1', 'g']
+  rs_build_type = 'debug'
+else
+  rs_build_type = 'release'
+endif
+
 ##################
 # Compiler flags #
 ##################
@@ -2916,6 +2939,10 @@ if targetos == 'windows'
     summary_info += {'Windows SDK':   config_host['WIN_SDK']}
   endif
 endif
+summary_info += {'Rust support':      with_rust}
+if with_rust and rust_target_triple != ''
+  summary_info += {'Rust target':     rust_target_triple}
+endif
 summary_info += {'CFLAGS':            ' '.join(get_option('c_args')
                                                + ['-O' + 
get_option('optimization')]
                                                + (get_option('debug') ? ['-g'] 
: []))}
diff --git a/.gitignore b/.gitignore
index eb2553026c..78715bc7c4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,6 @@
 /GNUmakefile
 /build/
+/target/
 *.pyc
 .sdk
 .stgit-*
diff --git a/Cargo.toml b/Cargo.toml
new file mode 100644
index 0000000000..c4b464ff15
--- /dev/null
+++ b/Cargo.toml
@@ -0,0 +1,2 @@
+[workspace]
+members = []
diff --git a/meson_options.txt b/meson_options.txt
index a9a9b8f4c6..fe9f90634b 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -155,3 +155,8 @@ option('slirp', type: 'combo', value: 'auto',
 option('fdt', type: 'combo', value: 'auto',
        choices: ['disabled', 'enabled', 'auto', 'system', 'internal'],
        description: 'Whether and how to find the libfdt library')
+
+option('with_rust', type: 'feature', value: 'auto',
+       description: 'Enable Rust support')
+option('with_rust_target', type : 'string', value: '',
+       description: 'Rust target triple')
-- 
2.33.0.113.g6c40894d24




reply via email to

[Prev in Thread] Current Thread [Next in Thread]