Writing plugins in C can be sometimes tedious, especially when using Glib to keep track of execution state. We can directly use the same C API but write our plugin in C++, benefiting from its great standard library offering strings, smart pointers, data structures and synchronization mechanisms.
It's common for downstream QEMU forks to provide C++ for plugins, like this: - https://github.com/panda-re/panda/tree/dev/panda/plugins - https://github.com/FlorentRevest/DejaView/tree/main/src/qemu_plugin Hopefully this will help more people to use upstream QEMU, and as a benefit, get their contribution back and help to develop plugins ecosystem upstream directly. This series first cleans up build system for plugins, factorizing details between contrib/plugins and tests/tcg/plugins folders. Then, we perform codebase cleanups to fix conflicts between existing headers and C++ headers. After that, we can update the C++ standard used by QEMU, to benefit fully from latest updates of the language. Finally, we define an empty C++ plugin, making sure we can keep track of possible regression in qemu-plugin header. Note: This series is *not* a trojan horse to bring C++ in QEMU codebase, nor to define an alternative C++ API for plugins. It's just enabling more users to get the most out of existing C plugin API. CI: https://gitlab.com/pbo-linaro/qemu/-/pipelines/2239199381 Pierrick Bouvier (11): plugins: move win32_linker.c file to plugins directory plugins: factorize plugin dependencies and library details plugins: use complete filename for defining plugins sources plugins: define plugin API symbols as extern "C" when compiling in C++ include: qemu/ctype.h -> qemu/qemu-ctype.h include: qemu/coroutine.h -> qemu/qemu-coroutine.h meson: fix supported compiler arguments in other languages than C meson: enable cpp (optionally) for plugins qga/vss-win32: fix clang warning with C++20 meson: update C++ standard to C++23 contrib/plugins: add empty cpp plugin meson.build | 24 ++-- block/parallels.h | 2 +- block/qcow2.h | 2 +- fsdev/qemu-fsdev-throttle.h | 2 +- hw/9pfs/9p.h | 2 +- include/block/block-global-state.h | 2 +- include/block/block-hmp-cmds.h | 2 +- include/block/block-io.h | 2 +- include/block/reqlist.h | 2 +- include/block/throttle-groups.h | 2 +- include/qemu/coroutine_int.h | 2 +- include/qemu/job.h | 2 +- .../qemu/{coroutine.h => qemu-coroutine.h} | 0 include/qemu/{ctype.h => qemu-ctype.h} | 0 include/qemu/qemu-plugin.h | 8 ++ migration/migration.h | 2 +- ui/console-priv.h | 2 +- block.c | 2 +- block/block-copy.c | 2 +- block/io_uring.c | 2 +- block/linux-aio.c | 2 +- block/mirror.c | 2 +- block/progress_meter.c | 2 +- block/ssh.c | 2 +- block/vdi.c | 2 +- block/vvfat.c | 2 +- chardev/char.c | 2 +- gdbstub/gdbstub.c | 2 +- hw/9pfs/coth.c | 2 +- hw/block/virtio-blk.c | 2 +- hw/core/bus.c | 2 +- hw/core/qdev-properties-system.c | 2 +- hw/core/qdev-properties.c | 2 +- hw/hyperv/syndbg.c | 2 +- hw/nvme/nguid.c | 2 +- hw/s390x/ccw-device.c | 2 +- hw/s390x/ipl.c | 2 +- hw/s390x/s390-virtio-ccw.c | 2 +- hw/scsi/scsi-generic.c | 2 +- migration/migration.c | 2 +- migration/rdma.c | 2 +- monitor/fds.c | 2 +- monitor/hmp.c | 2 +- nbd/client-connection.c | 2 +- net/colo-compare.c | 2 +- net/net.c | 2 +- net/tap-solaris.c | 2 +- {contrib/plugins => plugins}/win32_linker.c | 0 qapi/qapi-util.c | 2 +- qapi/qmp-dispatch.c | 2 +- qobject/json-parser.c | 2 +- target/ppc/ppc-qmp-cmds.c | 2 +- target/riscv/cpu.c | 2 +- target/riscv/riscv-qmp-cmds.c | 2 +- tests/qtest/libqtest.c | 2 +- tests/qtest/migration/migration-util.c | 2 +- tests/unit/test-aio-multithread.c | 2 +- tests/vhost-user-bridge.c | 2 +- ui/console.c | 2 +- ui/keymaps.c | 2 +- ui/ui-qmp-cmds.c | 2 +- util/cutils.c | 2 +- util/id.c | 2 +- util/qemu-co-shared-resource.c | 2 +- util/qemu-co-timeout.c | 2 +- util/qemu-coroutine-io.c | 2 +- util/readline.c | 2 +- util/thread-pool.c | 2 +- contrib/plugins/cpp.cpp | 119 ++++++++++++++++++ contrib/plugins/meson.build | 25 ++-- plugins/meson.build | 15 ++- qga/vss-win32/requester.cpp | 6 +- tests/tcg/plugins/meson.build | 18 +-- 73 files changed, 237 insertions(+), 104 deletions(-) rename include/qemu/{coroutine.h => qemu-coroutine.h} (100%) rename include/qemu/{ctype.h => qemu-ctype.h} (100%) rename {contrib/plugins => plugins}/win32_linker.c (100%) create mode 100644 contrib/plugins/cpp.cpp -- 2.47.3
