
On 5/7/25 12:55 AM, Markus Armbruster wrote: [...]
- First, it's already broken because we rely on ifdef that won't be there in Rust or Go.
I don't think it's broken. QAPI 'if' translates straightforwardly to C #if, but that doesn't mean it cannot be translated to conditional compilation / metaprogramming in other languages.
In fact, the value of 'if' used to be C constant expressions suitable for use with #if, and we changed it to its current form specifically to enable Rust work, in merge commit c83fcfaf8a5. Marc-André's was trying to develop Rust bindings back then, and if I remember correctly this change was enough to let him implement 'if' with Rust.
Sure, I didn't mean "this approach is doomed", simply that it needs changes, the same way code doing a runtime check would need changes as well.
- Second, it's code, we can just change it later if needed.
True!
- Third, those json are consumed only by QEMU (right?), so we are free to write/modify them as we want.
Also true.
The only thing that must stay the same is what we expose to the consumer in the schema, and which commands we expose in qemu.
We may evolve the external interface as long as we honor our compatibility promise.
You're aiming for "no change at all" there. I understand why that's desirable. But if it should turn out that a bit of compatible change simplifies the job, we can take the simpler route.
I have a local prototype doing what was described: introduce a runtime_if, additional to if (no worries, the name can be changed later), exposing schema parts conditionnally, and same for visiting types and registering commands. It's not too ugly, and easy to combine compilation if and runtime if together. I should be able to post it next week.
[...]
Regards, Pierrick.