[PATCH v3 00/11] plugins: enable C++ plugins

Pierrick Bouvier posted 11 patches 2 weeks, 6 days ago
Failed in applying to current master (apply log)
Maintainers: "Alex Bennée" <alex.bennee@linaro.org>, Alexandre Iooss <erdnaxe@crans.org>, Mahmoud Mandour <ma.mandourr@gmail.com>, Pierrick Bouvier <pierrick.bouvier@linaro.org>, Richard Henderson <richard.henderson@linaro.org>, Paolo Bonzini <pbonzini@redhat.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Kostiantyn Kostiuk <kkostiuk@redhat.com>, Michael Roth <michael.roth@amd.com>
There is a newer version of this series
docs/devel/tcg-plugins.rst                  |   4 +-
meson.build                                 |  26 +++--
include/{qemu => plugins}/qemu-plugin.h     |  11 +-
include/qemu/plugin.h                       |   2 +-
plugins/core.c                              |   2 +-
{contrib/plugins => plugins}/win32_linker.c |   0
tests/tcg/plugins/mem.c                     |  59 ++++------
contrib/plugins/cpp.cpp                     | 119 ++++++++++++++++++++
contrib/plugins/meson.build                 |  25 ++--
plugins/meson.build                         |  17 ++-
qga/vss-win32/requester.cpp                 |   6 +-
scripts/clean-includes                      |   2 +-
tests/tcg/plugins/meson.build               |  18 +--
13 files changed, 204 insertions(+), 87 deletions(-)
rename include/{qemu => plugins}/qemu-plugin.h (99%)
rename {contrib/plugins => plugins}/win32_linker.c (100%)
create mode 100644 contrib/plugins/cpp.cpp
[PATCH v3 00/11] plugins: enable C++ plugins
Posted by Pierrick Bouvier 2 weeks, 6 days ago
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/2242427013

v3
--

- fix indentation in patch 2

v2
--

- drop coroutine.h rename patch as it's not needed
- drop ctype.h rename patch, and move qemu-plugin.h to include/plugins
- fix mem.c to not depend on other QEMU headers

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++
  tests/tcg/plugins/mem.c: remove dependency on qemu headers
  plugins: move qemu-plugin.h to include/plugins/
  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

 docs/devel/tcg-plugins.rst                  |   4 +-
 meson.build                                 |  26 +++--
 include/{qemu => plugins}/qemu-plugin.h     |  11 +-
 include/qemu/plugin.h                       |   2 +-
 plugins/core.c                              |   2 +-
 {contrib/plugins => plugins}/win32_linker.c |   0
 tests/tcg/plugins/mem.c                     |  59 ++++------
 contrib/plugins/cpp.cpp                     | 119 ++++++++++++++++++++
 contrib/plugins/meson.build                 |  25 ++--
 plugins/meson.build                         |  17 ++-
 qga/vss-win32/requester.cpp                 |   6 +-
 scripts/clean-includes                      |   2 +-
 tests/tcg/plugins/meson.build               |  18 +--
 13 files changed, 204 insertions(+), 87 deletions(-)
 rename include/{qemu => plugins}/qemu-plugin.h (99%)
 rename {contrib/plugins => plugins}/win32_linker.c (100%)
 create mode 100644 contrib/plugins/cpp.cpp

-- 
2.47.3
Re: [PATCH v3 00/11] plugins: enable C++ plugins
Posted by Pierrick Bouvier 2 weeks, 1 day ago
On 1/19/26 11:11 AM, Pierrick Bouvier wrote:
> 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/2242427013
> 
> v3
> --
> 
> - fix indentation in patch 2
> 
> v2
> --
> 
> - drop coroutine.h rename patch as it's not needed
> - drop ctype.h rename patch, and move qemu-plugin.h to include/plugins
> - fix mem.c to not depend on other QEMU headers
> 
> 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++
>    tests/tcg/plugins/mem.c: remove dependency on qemu headers
>    plugins: move qemu-plugin.h to include/plugins/
>    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
> 
>   docs/devel/tcg-plugins.rst                  |   4 +-
>   meson.build                                 |  26 +++--
>   include/{qemu => plugins}/qemu-plugin.h     |  11 +-
>   include/qemu/plugin.h                       |   2 +-
>   plugins/core.c                              |   2 +-
>   {contrib/plugins => plugins}/win32_linker.c |   0
>   tests/tcg/plugins/mem.c                     |  59 ++++------
>   contrib/plugins/cpp.cpp                     | 119 ++++++++++++++++++++
>   contrib/plugins/meson.build                 |  25 ++--
>   plugins/meson.build                         |  17 ++-
>   qga/vss-win32/requester.cpp                 |   6 +-
>   scripts/clean-includes                      |   2 +-
>   tests/tcg/plugins/meson.build               |  18 +--
>   13 files changed, 204 insertions(+), 87 deletions(-)
>   rename include/{qemu => plugins}/qemu-plugin.h (99%)
>   rename {contrib/plugins => plugins}/win32_linker.c (100%)
>   create mode 100644 contrib/plugins/cpp.cpp
> 

sent v4 (fixed conflict with master):
https://lore.kernel.org/qemu-devel/20260124182921.531562-1-pierrick.bouvier@linaro.org/T/#t
Re: [PATCH v3 00/11] plugins: enable C++ plugins
Posted by Philippe Mathieu-Daudé 2 weeks, 6 days ago
AFAICT this series is fully reviewed.

On 19/1/26 20:11, Pierrick Bouvier wrote:

> 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++
>    tests/tcg/plugins/mem.c: remove dependency on qemu headers
>    plugins: move qemu-plugin.h to include/plugins/
>    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