Paolo Bonzini <[email protected]> writes: > On 12/9/25 07:01, Markus Armbruster wrote: >> Markus Armbruster <[email protected]> writes: >> >>> I applied, ran make, and it didn't create qapi-types.rs and >>> test-qapi-types.rs for me. What am I missing? >> >> Looks like I have to run with -B qapi.backend.QAPIRsBackend. >> >> -B is meant for out-of-tree backends. Commit dde279925c9 explains: >> >> qapi: pluggable backend code generators >> >> The 'qapi.backend.QAPIBackend' class defines an API contract for code >> generators. The current generator is put into a new class >> 'qapi.backend.QAPICBackend' and made to be the default impl. >> >> A custom generator can be requested using the '-k' arg which takes a >> fully qualified python class name >> >> qapi-gen.py -B the.python.module.QAPIMyBackend >> >> This allows out of tree code to use the QAPI generator infrastructure >> to create new language bindings for QAPI schemas. This has the caveat >> that the QAPI generator APIs are not guaranteed stable, so consumers >> of this feature may have to update their code to be compatible with >> future QEMU releases. >> >> Using it for the in-tree Rust backend is fine for a prototype. >> Mentioning it in a commit message or the cover letter would've saved me >> some digging. > > Well, it wasn't intentional - right now it does this: > > test_qapi_rs_files = custom_target('QAPI Rust', > output: 'test-qapi-types.rs', > input: [ files(meson.project_source_root() + > '/tests/qapi-schema/qapi-schema-test.json') ], > command: [ qapi_gen, '-o', meson.current_build_dir(), '-b', > '@INPUT0@', '-B', 'qapi.backend.QAPIRsBackend', '-p', 'test-' ], > depend_files: [ qapi_inputs, qapi_gen_depends ]) > > so "make rust/tests/test-qapi-types.rs" will work, and so will "make" if > you have --enable-rust. > > Let us know what you'd prefer and we'll switch. Alternatively, > retconning -B's meaning so that it applies to Rust will work too. :)
Any particular reason *not* to generate Rust unconditionally along with C? To do it, stick gen_rs_types() into QAPICodeBackend.generate(). Then the build runs qapi-gen at most once[*]. [*] Lie. Sphinx runs the *frontend* another time.
