xref: /qemu/rust/qemu-api/meson.build (revision 4be0fce498d0a08f18b3a9accdb9ded79484d30a)
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 rustc.version().version_compare('>=1.77.0')
7  _qemu_api_cfg += ['--cfg', 'has_offset_of']
8endif
9if get_option('debug_mutex')
10  _qemu_api_cfg += ['--feature', 'debug_cell']
11endif
12
13_qemu_api_rs = static_library(
14  'qemu_api',
15  structured_sources(
16    [
17      'src/lib.rs',
18      'src/bindings.rs',
19      'src/bitops.rs',
20      'src/cell.rs',
21      'src/c_str.rs',
22      'src/definitions.rs',
23      'src/device_class.rs',
24      'src/irq.rs',
25      'src/offset_of.rs',
26      'src/prelude.rs',
27      'src/sysbus.rs',
28      'src/vmstate.rs',
29      'src/zeroable.rs',
30    ],
31    {'.' : bindings_rs},
32  ),
33  override_options: ['rust_std=2021', 'build.rust_std=2021'],
34  rust_abi: 'rust',
35  rust_args: _qemu_api_cfg,
36)
37
38rust.test('rust-qemu-api-tests', _qemu_api_rs,
39          suite: ['unit', 'rust'])
40
41qemu_api = declare_dependency(
42  link_with: _qemu_api_rs,
43  dependencies: qemu_api_macros,
44)
45
46# Rust executables do not support objects, so add an intermediate step.
47rust_qemu_api_objs = static_library(
48    'rust_qemu_api_objs',
49    objects: [libqom.extract_all_objects(recursive: false),
50              libhwcore.extract_all_objects(recursive: false)])
51
52test('rust-qemu-api-integration',
53    executable(
54        'rust-qemu-api-integration',
55        'tests/tests.rs',
56        override_options: ['rust_std=2021', 'build.rust_std=2021'],
57        rust_args: ['--test'],
58        install: false,
59        dependencies: [qemu_api, qemu_api_macros],
60        link_whole: [rust_qemu_api_objs, libqemuutil]),
61    args: [
62        '--test',
63        '--format', 'pretty',
64    ],
65    protocol: 'rust',
66    suite: ['unit', 'rust'])
67