Features/Meson/Design: Difference between revisions

From QEMU
No edit summary
No edit summary
Line 1: Line 1:
Rules.mak has gotten insane, let's get rid of it!
Rules.mak has gotten insane, let's get rid of it!


More seriously, the current build system causes clutter in the toplevel Makefiles, and it makes simple tasks harder than they should be. For example, each executable in contrib/ has to touch three files: Makefile, Makefile.objs and contrib/*/Makefile.objs.
More seriously, the current build system causes clutter in the toplevel Makefiles, and it makes simple tasks harder than they should be. For example, each executable in contrib/ has to touch three files: Makefile, Makefile.objs and contrib/*/Makefile.objs.


Meson has several advantages that directly matter for QEMU including the following:
Meson has several advantages that directly matter for QEMU including the following:
Line 10: Line 10:


The transition is designed around the following goals:
The transition is designed around the following goals:
* it should remain trivial to do things that used to be trivial, and most "make" invocations should be kept the same at least until everything is converted and we can perhaps declare a flag day.  People are used to "make check" or "make subdir-x86_64-softmmu", those should continue to work while the transition is in progress.
* the build system should make it trivial to do trivial things; easy to do things that are a matter of cut-and-paste from something that already exist; possible to do everything else.
* it should remain trivial to do things that used to be trivial, and most "make" invocations should be kept the same at least until everything is converted (and we can perhaps declare a flag day)It should not become harder to do things that are a matter of cut-and-paste.
* it should be possible to modify meson.build without knowing QEMU specific details, and that should be ''already'' possible now at the beginning of the transition (to avoid creating technical debt).  This means keeping the magic confined in Makefile rules and external scripts, while having a pretty plain meson.build.
* it should be possible to modify meson.build without knowing QEMU specific details, and that should be ''already'' possible now at the beginning of the transition (to avoid creating technical debt).  This means keeping the magic confined in Makefile rules and external scripts, while having a pretty plain meson.build.


[https://patchew.org/QEMU/1560165301-39026-1-git-send-email-pbonzini@redhat.com/ A PoC was posted] in June 2019.  It includes a program called "ninjatool" that replaces ninja for the few cases where meson invokes it directly (<tt>ninja -t compdb</tt>, <tt>ninja -t clean</tt>) and that also is able to convert build.ninja files to Make syntax. Because of this, it is trivial to have make build products that depend on meson build products. Therefore bottom up is the natural direction for the conversion.
[https://patchew.org/QEMU/1560165301-39026-1-git-send-email-pbonzini@redhat.com/ A PoC was posted] in June 2019.  It includes a program called "ninjatool" that replaces ninja for the few cases where meson invokes it directly (<tt>ninja -t compdb</tt>, <tt>ninja -t clean</tt>) and that also is able to convert build.ninja files to Make syntax. Because of this, it is trivial to have make build products that depend on meson build products. Therefore bottom up is the natural direction for the conversion.


This fits in a generic plan to drop Makefile magic in favor of build rule generators written in high-level languages. For example, in order to keep <tt>make check</tt>-like rules working, we could generate Makefile rules from the output of <tt>meson introspect --tests</tt>.
This fits in a generic plan to drop Makefile magic in favor of build rule generators written in high-level languages. For example, in order to keep <tt>make check</tt>-like rules working, we could generate Makefile rules from the output of <tt>meson introspect --tests</tt>.  This, together with the use of ninja2make also gives us an escape mechanism in case we want to do something that Meson cannot (yet) do, or doesn't do the way we want it.


The alternative of having two parallel build systems was rejected.  This would introduce extra work for people not involved in the conversion, and the risk of bitrotting one of the two build systems is large.
The alternative of having two parallel build systems was rejected.  This would introduce extra work for people not involved in the conversion, and the risk of bitrotting one of the two build systems is large.

Revision as of 16:02, 27 June 2019

Rules.mak has gotten insane, let's get rid of it!

More seriously, the current build system causes clutter in the toplevel Makefiles, and it makes simple tasks harder than they should be. For example, each executable in contrib/ has to touch three files: Makefile, Makefile.objs and contrib/*/Makefile.objs.

Meson has several advantages that directly matter for QEMU including the following:

  • build definitions in a very readable and user friendly DSL, which supports looping and conditions
  • ability to introspect the build definitions so that you can find out what is built without building it (the DSL is not Turing complete and most objects in it are immutable, so it cannot be abused that much :))
  • support for a non-recursive build from per-subdirectory input (similar to Makefile.objs)
  • ease of distributing a full copy of Meson to support distros that ship an older version (no dependencies apart from Python 3.5).

The transition is designed around the following goals:

  • the build system should make it trivial to do trivial things; easy to do things that are a matter of cut-and-paste from something that already exist; possible to do everything else.
  • it should remain trivial to do things that used to be trivial, and most "make" invocations should be kept the same at least until everything is converted (and we can perhaps declare a flag day). It should not become harder to do things that are a matter of cut-and-paste.
  • it should be possible to modify meson.build without knowing QEMU specific details, and that should be already possible now at the beginning of the transition (to avoid creating technical debt). This means keeping the magic confined in Makefile rules and external scripts, while having a pretty plain meson.build.

A PoC was posted in June 2019. It includes a program called "ninjatool" that replaces ninja for the few cases where meson invokes it directly (ninja -t compdb, ninja -t clean) and that also is able to convert build.ninja files to Make syntax. Because of this, it is trivial to have make build products that depend on meson build products. Therefore bottom up is the natural direction for the conversion.

This fits in a generic plan to drop Makefile magic in favor of build rule generators written in high-level languages. For example, in order to keep make check-like rules working, we could generate Makefile rules from the output of meson introspect --tests. This, together with the use of ninja2make also gives us an escape mechanism in case we want to do something that Meson cannot (yet) do, or doesn't do the way we want it.

The alternative of having two parallel build systems was rejected. This would introduce extra work for people not involved in the conversion, and the risk of bitrotting one of the two build systems is large.

Prerequisites

Here I had listed possible blockers for the transition. Barring bugs, Meson 0.51.0 should have all that is needed to port QEMU, in particular the following pull requests:

Status