Skip to content

Commit

Permalink
plugins: allow to build C++ plugins
Browse files Browse the repository at this point in the history
Signed-off-by: Pierrick Bouvier <[email protected]>
  • Loading branch information
pbo-linaro committed Feb 23, 2025
1 parent da1d7f1 commit 0290065
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 10 deletions.
25 changes: 19 additions & 6 deletions contrib/plugins/meson.build
Original file line number Diff line number Diff line change
@@ -1,22 +1,35 @@
contrib_plugins = ['bbv', 'cache', 'cflow', 'drcov', 'execlog', 'hotblocks',
'hotpages', 'howvec', 'hwprofile', 'ips', 'stoptrigger',
'traps']
contrib_plugins = files(
'bbv.c',
'cache.c',
'cflow.c',
'drcov.c',
'execlog.c',
'hotblocks.c',
'hotpages.c',
'howvec.c',
'hwprofile.c',
'ips.c',
'stoptrigger.c',
'traps.c',
)

if host_os != 'windows'
# lockstep uses socket.h
contrib_plugins += 'lockstep'
contrib_plugins += files('lockstep.c')
endif

t = []
if get_option('plugins')
foreach i : contrib_plugins
mod_name = fs.name(fs.replace_suffix(i.full_path(), ''))
if host_os == 'windows'
t += shared_module(i, files(i + '.c') + 'win32_linker.c',
t += shared_module(mod_name, i + 'win32_linker.c',
include_directories: '../../include/qemu',
link_depends: [win32_qemu_plugin_api_lib],
link_args: win32_qemu_plugin_api_link_flags,
dependencies: glib)
else
t += shared_module(i, files(i + '.c'),
t += shared_module(mod_name, i,
include_directories: '../../include/qemu',
dependencies: glib)
endif
Expand Down
4 changes: 4 additions & 0 deletions include/qemu/ctype.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
* See the COPYING file in the top-level directory.
*/

#ifdef __cplusplus
#include_next <ctype.h>
#endif

#ifndef QEMU_CTYPE_H
#define QEMU_CTYPE_H

Expand Down
8 changes: 8 additions & 0 deletions include/qemu/qemu-plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
#include <stdbool.h>
#include <stddef.h>

#ifdef __cplusplus
extern "C" {
#endif

/*
* For best performance, build the plugin with -fvisibility=hidden so that
* QEMU_PLUGIN_LOCAL is implicit. Then, just mark qemu_plugin_install with
Expand Down Expand Up @@ -1062,4 +1066,8 @@ void qemu_plugin_u64_set(qemu_plugin_u64 entry, unsigned int vcpu_index,
QEMU_PLUGIN_API
uint64_t qemu_plugin_u64_sum(qemu_plugin_u64 entry);

#ifdef __cplusplus
} /* extern "C" */
#endif

#endif /* QEMU_QEMU_PLUGIN_H */
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
project('qemu', ['c'], meson_version: '>=1.5.0',
project('qemu', ['c', 'cpp'], meson_version: '>=1.5.0',
default_options: ['warning_level=1', 'c_std=gnu11', 'cpp_std=gnu++11', 'b_colorout=auto',
'b_staticpic=false', 'stdsplit=false', 'optimization=2', 'b_pie=true'],
version: files('VERSION'))
Expand Down
17 changes: 14 additions & 3 deletions tests/tcg/plugins/meson.build
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
test_plugins=files(
'bb.c',
'discons.c',
'empty.c',
'inline.c',
'insn.c',
'mem.c',
'syscall.c',
)

t = []
if get_option('plugins')
foreach i : ['bb', 'discons', 'empty', 'inline', 'insn', 'mem', 'syscall']
foreach i : test_plugins
mod_name = fs.name(fs.replace_suffix(i.full_path(), ''))
if host_os == 'windows'
t += shared_module(i, files(i + '.c') + '../../../contrib/plugins/win32_linker.c',
t += shared_module(mod_name, i + '../../../contrib/plugins/win32_linker.c',
include_directories: '../../../include/qemu',
link_depends: [win32_qemu_plugin_api_lib],
link_args: win32_qemu_plugin_api_link_flags,
dependencies: glib)
else
t += shared_module(i, files(i + '.c'),
t += shared_module(mod_name, i,
include_directories: '../../../include/qemu',
dependencies: glib)
endif
Expand Down

0 comments on commit 0290065

Please sign in to comment.