xref: /openbmc/qemu/rust/qemu-api/meson.build (revision c596199f639cdf4cc021c9bc076e4a1e64e9d50f)
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/cell.rs',
20      'src/c_str.rs',
21      'src/definitions.rs',
22      'src/device_class.rs',
23      'src/offset_of.rs',
24      'src/vmstate.rs',
25      'src/zeroable.rs',
26    ],
27    {'.' : bindings_rs},
28  ),
29  override_options: ['rust_std=2021', 'build.rust_std=2021'],
30  rust_abi: 'rust',
31  rust_args: _qemu_api_cfg,
32)
33
34rust.test('rust-qemu-api-tests', _qemu_api_rs,
35          suite: ['unit', 'rust'])
36
37qemu_api = declare_dependency(
38  link_with: _qemu_api_rs,
39  dependencies: qemu_api_macros,
40)
41
42# Rust executables do not support objects, so add an intermediate step.
43rust_qemu_api_objs = static_library(
44    'rust_qemu_api_objs',
45    objects: [libqom.extract_all_objects(recursive: false),
46              libhwcore.extract_all_objects(recursive: false)])
47
48test('rust-qemu-api-integration',
49    executable(
50        'rust-qemu-api-integration',
51        'tests/tests.rs',
52        override_options: ['rust_std=2021', 'build.rust_std=2021'],
53        rust_args: ['--test'],
54        install: false,
55        dependencies: [qemu_api, qemu_api_macros],
56        link_whole: [rust_qemu_api_objs, libqemuutil]),
57    args: [
58        '--test',
59        '--format', 'pretty',
60    ],
61    protocol: 'rust',
62    suite: ['unit', 'rust'])
63