Browse Source
The crate purpose is only to provide integration tests at this point, that can't easily be moved to a specific crate. It's also often a good practice to have a single integration test crate (see for ex https://github.com/rust-lang/cargo/issues/4867) Drop README.md, use docs/devel/rust.rst instead. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Link: https://lore.kernel.org/r/20250827104147.717203-20-marcandre.lureau@redhat.com Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>pull/305/head
committed by
Paolo Bonzini
15 changed files with 35 additions and 230 deletions
@ -1,2 +0,0 @@ |
|||||
# Ignore generated bindings file overrides. |
|
||||
/src/bindings.inc.rs |
|
||||
@ -1,19 +0,0 @@ |
|||||
# 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 |
|
||||
$ make bindings.inc.rs |
|
||||
``` |
|
||||
|
|
||||
## Generate Rust documentation |
|
||||
|
|
||||
Common Cargo tasks can be performed from the QEMU build directory |
|
||||
|
|
||||
```console |
|
||||
$ make clippy |
|
||||
$ make rustfmt |
|
||||
$ make rustdoc |
|
||||
``` |
|
||||
@ -1 +0,0 @@ |
|||||
../util/build.rs |
|
||||
@ -1,75 +0,0 @@ |
|||||
_qemu_api_cfg = run_command(rustc_args, |
|
||||
'--config-headers', config_host_h, '--features', files('Cargo.toml'), |
|
||||
capture: true, check: true).stdout().strip().splitlines() |
|
||||
|
|
||||
c_enums = [ |
|
||||
'MemoryDeviceInfoKind', |
|
||||
] |
|
||||
_qemu_api_bindgen_args = [] |
|
||||
foreach enum : c_enums |
|
||||
_qemu_api_bindgen_args += ['--rustified-enum', enum] |
|
||||
endforeach |
|
||||
|
|
||||
blocked_type = [ |
|
||||
'Chardev', |
|
||||
'Error', |
|
||||
'MemTxAttrs', |
|
||||
'MemoryRegion', |
|
||||
'ObjectClass', |
|
||||
'VMStateDescription', |
|
||||
'device_endian', |
|
||||
] |
|
||||
foreach type: blocked_type |
|
||||
_qemu_api_bindgen_args += ['--blocklist-type', type] |
|
||||
endforeach |
|
||||
|
|
||||
# TODO: Remove this comment when the clang/libclang mismatch issue is solved. |
|
||||
# |
|
||||
# Rust bindings generation with `bindgen` might fail in some cases where the |
|
||||
# detected `libclang` does not match the expected `clang` version/target. In |
|
||||
# this case you must pass the path to `clang` and `libclang` to your build |
|
||||
# command invocation using the environment variables CLANG_PATH and |
|
||||
# LIBCLANG_PATH |
|
||||
_qemu_api_bindings_inc_rs = rust.bindgen( |
|
||||
input: 'wrapper.h', |
|
||||
dependencies: common_ss.all_dependencies(), |
|
||||
output: 'bindings.inc.rs', |
|
||||
include_directories: bindings_incdir, |
|
||||
bindgen_version: ['>=0.60.0'], |
|
||||
args: bindgen_args_common + _qemu_api_bindgen_args, |
|
||||
) |
|
||||
|
|
||||
_qemu_api_rs = static_library( |
|
||||
'qemu_api', |
|
||||
structured_sources( |
|
||||
[ |
|
||||
'src/lib.rs', |
|
||||
'src/bindings.rs', |
|
||||
'src/prelude.rs', |
|
||||
], |
|
||||
{'.' : _qemu_api_bindings_inc_rs}, |
|
||||
), |
|
||||
override_options: ['rust_std=2021', 'build.rust_std=2021'], |
|
||||
rust_abi: 'rust', |
|
||||
rust_args: _qemu_api_cfg, |
|
||||
dependencies: [anyhow_rs, bql_rs, chardev_rs, common_rs, foreign_rs, hwcore_rs, libc_rs, migration_rs, qemu_macros, |
|
||||
qom_rs, system_rs, util_rs, hwcore], |
|
||||
) |
|
||||
|
|
||||
qemu_api_rs = declare_dependency(link_with: [_qemu_api_rs], |
|
||||
dependencies: [qemu_macros, qom, hwcore, chardev, migration]) |
|
||||
|
|
||||
test('rust-qemu-api-integration', |
|
||||
executable( |
|
||||
'rust-qemu-api-integration', |
|
||||
files('tests/vmstate_tests.rs'), |
|
||||
override_options: ['rust_std=2021', 'build.rust_std=2021'], |
|
||||
rust_args: ['--test'], |
|
||||
install: false, |
|
||||
dependencies: [bql_rs, common_rs, util_rs, migration_rs, qom_rs, qemu_api_rs]), |
|
||||
args: [ |
|
||||
'--test', '--test-threads', '1', |
|
||||
'--format', 'pretty', |
|
||||
], |
|
||||
protocol: 'rust', |
|
||||
suite: ['unit', 'rust']) |
|
||||
@ -1,33 +0,0 @@ |
|||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
||||
#![allow(
|
|
||||
dead_code, |
|
||||
improper_ctypes_definitions, |
|
||||
improper_ctypes, |
|
||||
non_camel_case_types, |
|
||||
non_snake_case, |
|
||||
non_upper_case_globals, |
|
||||
unnecessary_transmutes, |
|
||||
unsafe_op_in_unsafe_fn, |
|
||||
clippy::pedantic, |
|
||||
clippy::restriction, |
|
||||
clippy::style, |
|
||||
clippy::missing_const_for_fn, |
|
||||
clippy::ptr_offset_with_cast, |
|
||||
clippy::useless_transmute, |
|
||||
clippy::missing_safety_doc, |
|
||||
clippy::too_many_arguments |
|
||||
)] |
|
||||
|
|
||||
//! `bindgen`-generated declarations.
|
|
||||
|
|
||||
use chardev::bindings::Chardev; |
|
||||
use migration::bindings::VMStateDescription; |
|
||||
use qom::bindings::ObjectClass; |
|
||||
use system::bindings::{device_endian, MemTxAttrs, MemoryRegion}; |
|
||||
use util::bindings::Error; |
|
||||
|
|
||||
#[cfg(MESON)] |
|
||||
include!("bindings.inc.rs"); |
|
||||
|
|
||||
#[cfg(not(MESON))] |
|
||||
include!(concat!(env!("OUT_DIR"), "/bindings.inc.rs")); |
|
||||
@ -1,18 +0,0 @@ |
|||||
// Copyright 2024, Linaro Limited
|
|
||||
// Author(s): Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
|
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
||||
|
|
||||
#![cfg_attr(not(MESON), doc = include_str!("../README.md"))] |
|
||||
#![deny(clippy::missing_const_for_fn)] |
|
||||
|
|
||||
#[rustfmt::skip] |
|
||||
pub mod bindings; |
|
||||
|
|
||||
// preserve one-item-per-"use" syntax, it is clearer
|
|
||||
// for prelude-like modules
|
|
||||
#[rustfmt::skip] |
|
||||
pub mod prelude; |
|
||||
|
|
||||
// Allow proc-macros to refer to `::qemu_api` inside the `qemu_api` crate (this
|
|
||||
// crate).
|
|
||||
extern crate self as qemu_api; |
|
||||
@ -1,5 +0,0 @@ |
|||||
// Copyright 2024 Red Hat, Inc.
|
|
||||
// Author(s): Paolo Bonzini <pbonzini@redhat.com>
|
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
||||
|
|
||||
//! Commonly used traits and types for QEMU.
|
|
||||
@ -1,53 +0,0 @@ |
|||||
/*
|
|
||||
* QEMU System Emulator |
|
||||
* |
|
||||
* Copyright (c) 2024 Linaro Ltd. |
|
||||
* |
|
||||
* Authors: Manos Pitsidianakis <manos.pitsidianakis@linaro.org> |
|
||||
* |
|
||||
* 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. |
|
||||
*/ |
|
||||
|
|
||||
|
|
||||
/*
|
|
||||
* This header file is meant to be used as input to the `bindgen` application |
|
||||
* in order to generate C FFI compatible Rust bindings. |
|
||||
*/ |
|
||||
|
|
||||
#ifndef __CLANG_STDATOMIC_H |
|
||||
#define __CLANG_STDATOMIC_H |
|
||||
/*
|
|
||||
* Fix potential missing stdatomic.h error in case bindgen does not insert the |
|
||||
* correct libclang header paths on its own. We do not use stdatomic.h symbols |
|
||||
* in QEMU code, so it's fine to declare dummy types instead. |
|
||||
*/ |
|
||||
typedef enum memory_order { |
|
||||
memory_order_relaxed, |
|
||||
memory_order_consume, |
|
||||
memory_order_acquire, |
|
||||
memory_order_release, |
|
||||
memory_order_acq_rel, |
|
||||
memory_order_seq_cst, |
|
||||
} memory_order; |
|
||||
#endif /* __CLANG_STDATOMIC_H */ |
|
||||
|
|
||||
#include "qemu/osdep.h" |
|
||||
#include "qemu-io.h" |
|
||||
#include "exec/memattrs.h" |
|
||||
#include "hw/char/pl011.h" |
|
||||
@ -1,12 +1,11 @@ |
|||||
[package] |
[package] |
||||
name = "qemu_api" |
name = "tests" |
||||
version = "0.1.0" |
version = "0.1.0" |
||||
authors = ["Manos Pitsidianakis <manos.pitsidianakis@linaro.org>"] |
description = "Rust integration tests for QEMU" |
||||
description = "Rust bindings for QEMU" |
|
||||
readme = "README.md" |
|
||||
resolver = "2" |
resolver = "2" |
||||
publish = false |
publish = false |
||||
|
|
||||
|
authors.workspace = true |
||||
edition.workspace = true |
edition.workspace = true |
||||
homepage.workspace = true |
homepage.workspace = true |
||||
license.workspace = true |
license.workspace = true |
||||
@ -0,0 +1,14 @@ |
|||||
|
test('rust-integration', |
||||
|
executable( |
||||
|
'rust-integration', |
||||
|
files('tests/vmstate_tests.rs'), |
||||
|
override_options: ['rust_std=2021', 'build.rust_std=2021'], |
||||
|
rust_args: ['--test'], |
||||
|
install: false, |
||||
|
dependencies: [bql_rs, common_rs, util_rs, migration_rs, qom_rs]), |
||||
|
args: [ |
||||
|
'--test', '--test-threads', '1', |
||||
|
'--format', 'pretty', |
||||
|
], |
||||
|
protocol: 'rust', |
||||
|
suite: ['unit', 'rust']) |
||||
Loading…
Reference in new issue