1_qemu_api_cfg = run_command(rustc_args, 2 '--config-headers', config_host_h, '--features', files('Cargo.toml'), 3 capture: true, check: true).stdout().strip().splitlines() 4 5# _qemu_api_cfg += ['--cfg', 'feature="allocator"'] 6if get_option('debug_mutex') 7 _qemu_api_cfg += ['--cfg', 'feature="debug_cell"'] 8endif 9 10c_enums = [ 11 'DeviceCategory', 12 'GpioPolarity', 13 'MachineInitPhase', 14 'MemoryDeviceInfoKind', 15 'MigrationPolicy', 16 'MigrationPriority', 17 'QEMUChrEvent', 18 'QEMUClockType', 19 'ResetType', 20 'device_endian', 21 'module_init_type', 22] 23_qemu_api_bindgen_args = [] 24foreach enum : c_enums 25 _qemu_api_bindgen_args += ['--rustified-enum', enum] 26endforeach 27c_bitfields = [ 28 'ClockEvent', 29 'VMStateFlags', 30] 31foreach enum : c_bitfields 32 _qemu_api_bindgen_args += ['--bitfield-enum', enum] 33endforeach 34 35# TODO: Remove this comment when the clang/libclang mismatch issue is solved. 36# 37# Rust bindings generation with `bindgen` might fail in some cases where the 38# detected `libclang` does not match the expected `clang` version/target. In 39# this case you must pass the path to `clang` and `libclang` to your build 40# command invocation using the environment variables CLANG_PATH and 41# LIBCLANG_PATH 42_qemu_api_bindings_inc_rs = rust.bindgen( 43 input: 'wrapper.h', 44 dependencies: common_ss.all_dependencies(), 45 output: 'bindings.inc.rs', 46 include_directories: bindings_incdir, 47 bindgen_version: ['>=0.60.0'], 48 args: bindgen_args_common + _qemu_api_bindgen_args, 49 ) 50 51_qemu_api_rs = static_library( 52 'qemu_api', 53 structured_sources( 54 [ 55 'src/lib.rs', 56 'src/assertions.rs', 57 'src/bindings.rs', 58 'src/bitops.rs', 59 'src/callbacks.rs', 60 'src/cell.rs', 61 'src/chardev.rs', 62 'src/errno.rs', 63 'src/error.rs', 64 'src/irq.rs', 65 'src/log.rs', 66 'src/memory.rs', 67 'src/module.rs', 68 'src/prelude.rs', 69 'src/qdev.rs', 70 'src/qom.rs', 71 'src/sysbus.rs', 72 'src/timer.rs', 73 'src/uninit.rs', 74 'src/vmstate.rs', 75 'src/zeroable.rs', 76 ], 77 {'.' : _qemu_api_bindings_inc_rs}, 78 ), 79 override_options: ['rust_std=2021', 'build.rust_std=2021'], 80 rust_abi: 'rust', 81 rust_args: _qemu_api_cfg, 82 dependencies: [anyhow_rs, foreign_rs, libc_rs, qemu_api_macros, qemuutil_rs, 83 qom, hwcore, chardev, migration], 84) 85 86rust.test('rust-qemu-api-tests', _qemu_api_rs, 87 suite: ['unit', 'rust']) 88 89qemu_api = declare_dependency(link_with: [_qemu_api_rs], 90 dependencies: [qemu_api_macros, qom, hwcore, chardev, migration]) 91 92# Doctests are essentially integration tests, so they need the same dependencies. 93# Note that running them requires the object files for C code, so place them 94# in a separate suite that is run by the "build" CI jobs rather than "check". 95rust.doctest('rust-qemu-api-doctests', 96 _qemu_api_rs, 97 protocol: 'rust', 98 dependencies: qemu_api, 99 suite: ['doc', 'rust']) 100 101test('rust-qemu-api-integration', 102 executable( 103 'rust-qemu-api-integration', 104 files('tests/tests.rs', 'tests/vmstate_tests.rs'), 105 override_options: ['rust_std=2021', 'build.rust_std=2021'], 106 rust_args: ['--test'], 107 install: false, 108 dependencies: [qemu_api]), 109 args: [ 110 '--test', '--test-threads', '1', 111 '--format', 'pretty', 112 ], 113 protocol: 'rust', 114 suite: ['unit', 'rust']) 115