On 24/4/25 20:33, Pierrick Bouvier wrote:

QAPI
====

QAPI generated files contain conditional clauses to define various structures,
enums, and commands only for specific targets. This forces files to be
compiled for every target. What we try to do here is to build them only once
instead.

In the past, we identied that the best approach to solve this is to expose code
for all targets (thus removing all #if clauses), and stub missing
symbols for concerned targets.

This series build QAPI generated code once, by removing all TARGET_{arch} and
CONFIG_KVM clauses. What it does *not* at the moment is:
- prevent target specific commands to be visible for all targets
   (see TODO comment on patch 2 explaining how to address this)

+   # "#if TARGET_S390X && CONFIG_KVM" will become:
+   # "if (target_s390x() || kvm_enabled()) {"

I like it.

- nothing was done to hide all this from generated documentation

 From what I understood, the only thing that matters is to limit qmp commands
visible. Exposing enums, structure, or events is not a problem, since they
won't be used/triggered for non concerned targets. Please correct me if this is
wrong, and if there are unexpected consequences for libvirt or other consumers.

What about function name clashes? I.e.:

389 ##
390 # @query-cpu-definitions:
391 #
392 # Return a list of supported virtual CPU definitions
393 #
394 # Returns: a list of CpuDefinitionInfo
395 #
396 # Since: 1.2
397 ##
398 { 'command': 'query-cpu-definitions', 'returns': ['CpuDefinitionInfo'],
399   'if': { 'any': [ 'TARGET_PPC',
400                    'TARGET_ARM',
401                    'TARGET_I386',
402                    'TARGET_S390X',
403                    'TARGET_MIPS',
404                    'TARGET_LOONGARCH64',
405                    'TARGET_RISCV' ] } }

$ git grep qmp.query.cpu.definitions
target/arm/arm-qmp-cmds.c:238:CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp) target/i386/cpu.c:6418:CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp) target/loongarch/loongarch-qmp-cmds.c:30:CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp) target/mips/system/mips-qmp-cmds.c:28:CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp) target/ppc/ppc-qmp-cmds.c:192:CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp) target/riscv/riscv-qmp-cmds.c:56:CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp) target/s390x/cpu_models_system.c:85:CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp)

Prepend target name to these functions and dispatch generated code?

Reply via email to