-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding a generic build order rule #8123
Comments
What do you expect |
I don't actually know much (or anything) about ninja syntax itself, so it's hard to answer your question. Yet while I was looking for a possible way to make such order dependency with meson, I found this ninja docs: https://ninja-build.org/manual.html#ref_dependencies Clearly the "Order-only dependencies" is what we want. In my example, the
Oh I see. Well it does make sense as here |
Sorry fatfingered a reply away, but basically there should be a depends kwarg on the resource compilation instead, so you only need to define the depend in the one place that actually needs it. It is typically better to be explicit as it leads to better parallelization. "Wait for random things to happen here" kind of things is problematic in that it scales very badly. One delay is ok, but ten is not. And, sadly, people have a tendency to try to fix their parallelism issues by adding random delays and pauses hoping for the best rather than fixing the core issue. |
What, no. This is like 30 years of good practice for dependency handling down the drain if you do this. A target should basically bring its own dependency and meson/ninja is therefore able to handle them perfectly and without any error. This is exactly for this reason for instance that Typically here I grepped and counted over 30 occurrences where we used this rc file. If we were to do it by hand, then what happens the day when we changed the dependencies? We redo each and every rule. Of course, this is something common in build system (maintaining source files dependant of each others), but when we have the opportunity to simplify this like here because the dependency is itself a rule target, why not take it?
There is really nothing random here, not sure why you say this. We have a target which depends on another. So we should not use the dependent one before its dependency is built. This is like the base of software building. 🙂
You will always have people making crap build rules, you can't change this. But a lot of crap rules are made because the build system is lacking on the needed feature allowing to make the proper rule. Typically here, this is one such case. If we don't find a way to make our target depend on its actual dependency, then we will end up making very crappy build rules to work around this meson issue (I would even call this a bug). I mean, just look at the case. It's not a "random delay or pause". We are not doing something random "hoping for the best". I looked in our build (when it failed), then saw the problem which is that one target depends on another. And currently there is absolutely no way in meson to create this dependency relationship. This is not random. It's build investigation, accurate diagnosis and search for an actual logics (which is: a dependency should not be used before its own dependencies are created).
Anyway I had a thought the other day regarding this doc I found about ninja's "Order-only dependencies". From what I seem to have understood what meson does at configure time, I think it should absolutely be able to create these order-only dependencies at configure time with such a syntax on every rule where such a wait dependency is used. It should be good and semantically correct. |
Ok, my bad, I missed this. In this particular case you should be able to do this: rc_sources += windows.compile_resources(
gimp_plugins_rc,
args: [
'--define', 'ORIGINALFILENAME_STR="@0@"'.format(plugin_name+'.exe'),
'--define', 'INTERNALNAME_STR="@0@"' .format(plugin_name),
'--define', 'TOP_SRCDIR="@0@"' .format(meson.source_root()),
],
include_directories: [
rootInclude, appInclude,
],
)
plugin_sources += [rc_sources, gitversion_h] and it should do the right thing. This means "gitversion_h must exist when the sources generated by the resource compiler are compiled" whereas I was thinking of "gitversion_h must exist when the resource file is being generated". |
The correct solution here, in general, is the existing declare_dependency() which can be used to create a dependency object that a) provides The dependency object will guarantee that any target depending on the .rc source as input, also depends on the header having been generated. |
These two approaches are pretty much the same. You can choose either one depending on which one suits your project setup better. |
This was proposed in meson bug tracker: mesonbuild/meson#8123
I don't think this would work because
So unless mistaken, it looks like the good meson code would be:
As I said, I really don't like this approach which feels like a huge stepback from advanced build system logics, because it means we must maintain a list of dependencies and always update it in 35 places (I
This seemed a lot better because it let me imagine I could just do this and be done with it (because
Then anything depending on
So with my change, I now get this error:
Therefore I would still need to use the actual dependency returned by So I still think some command is needed to actually create a specific dependency order as needed. |
That's a pity, but, I wonder if windows.compile_resources() could be improved to accept |
Note that it's not the only one you'd have to change. While testing other variants, I saw among the 35 uses, we have a bunch like this one:
Which gets as error:
This means that you'd |
Today I again had a similar issue. This time, I needed to change a XML file through
If instead I try to just hardcode the output name of the
Sure! It is supposed to be built by the first step, but since I can't use the CustomTarget as input of Anyway I could work around the issue by reversing the order of operations, i.e. doing a Of course meson is not responsible for Simplicity first in other words. |
I don't think this is a good example, because the problem here isn't about dependency ordering. The problem is that configure_file runs during You cannot depend on build rules before the build finishes configuring. This is precisely why configure_file detects that you aren't allowed to do it and tells you that you can't do that -- you can only use source files or other files that exist during configuration (the output of another configure_file is a valid input, for example). You tried to hack around this by casting CustomTarget to string but the underlying problem remained the same, so it still failed. |
Ah right. I had forgotten about this. It's a bit confusing. This being said, a build-time configure_file-style call would be nice. |
It's possible to use xsltproc as a configure_file command, and it will then run during every configure step. Also force reconfigure if the source file is modified. |
Yeah, that would be interesting. I've hacked around this in the past by using configure_file to produce a shell script with replaced parameters to sed. That sed script then runs at build time. Implementing it in meson and guaranteeing it works on all platforms (internally running a python implementation) could be pretty useful and I'd be amenable to reviewing and merging such a thing. The main use case would be for files that need to be replaced with configured values, but which frequently change -- it's very awkward to reconfigure the entire project every time a data file is modified, worse when it's the main installable artifact that just needs the install prefix inserted at the top. :D |
Depending on where it's used, this list of action can be either in the "dockable" or the "dialogs" action group. The meson rule is a bit more complicated than I wished it were because of the ever-so-blocking lack of simple dependency in meson. Cf. my latest comment: mesonbuild/meson#8123 (comment)
Depending on where it's used, this list of action can be either in the "dockable" or the "dialogs" action group. The meson rule is a bit more complicated than I wished it were because of the ever-so-blocking lack of simple dependency in meson. Cf. my latest comment: mesonbuild/meson#8123 (comment)
Depending on where it's used, this list of action can be either in the "dockable" or the "dialogs" action group. The meson rule is a bit more complicated than I wished it were because of the ever-so-blocking lack of simple dependency in meson. Cf. my latest comment: mesonbuild/meson#8123 (comment)
Depending on where it's used, this list of action can be either in the "dockable" or the "dialogs" action group. The meson rule is a bit more complicated than I wished it were because of the ever-so-blocking lack of simple dependency in meson. Cf. my latest comment: mesonbuild/meson#8123 (comment)
Depending on where it's used, this list of action can be either in the "dockable" or the "dialogs" action group. The meson rule is a bit more complicated than I wished it were because of the ever-so-blocking lack of simple dependency in meson. Cf. my latest comment: mesonbuild/meson#8123 (comment)
Depending on where it's used, this list of action can be either in the "dockable" or the "dialogs" action group. The meson rule is a bit more complicated than I wished it were because of the ever-so-blocking lack of simple dependency in meson. Cf. my latest comment: mesonbuild/meson#8123 (comment)
Depending on where it's used, this list of action can be either in the "dockable" or the "dialogs" action group. The meson rule is a bit more complicated than I wished it were because of the ever-so-blocking lack of simple dependency in meson. Cf. my latest comment: mesonbuild/meson#8123 (comment)
Depending on where it's used, this list of action can be either in the "dockable" or the "dialogs" action group. The meson rule is a bit more complicated than I wished it were because of the ever-so-blocking lack of simple dependency in meson. Cf. my latest comment: mesonbuild/meson#8123 (comment)
Depending on where it's used, this list of action can be either in the "dockable" or the "dialogs" action group. The meson rule is a bit more complicated than I wished it were because of the ever-so-blocking lack of simple dependency in meson. Cf. my latest comment: mesonbuild/meson#8123 (comment)
Describe the bug
Currently meson has specific build order logics depending on the type of rule. On some rule, it may depend on
input
, ordepends
or the main source files forexecutable()
, and so on. Unfortunately as soon as we get into a case not planned by meson developers, we are either stuck or forced to do ugly or bug-prone build logics.I'd like to get a syntax to block some target build rule until some other target got built first. Maybe it could be something like:
To Reproduce
The use case we had today (in GIMP build):
git-version.h
with this rule:meson.build
, we generategimp-plug-ins.rc
from some template:gimp_plugins_rc
in a few dozenmeson.build
like this:What happens
The problem is that
gimp-plug-ins.rc
actually has an#include "git-version.h"
. So we don't needgit-version.h
to generate the.rc
file, but the later is simply useless without the.h
. Or to be more accurate: the build will fail if the.rc
was built first. Asmeson
kind of starts everything in the same time, it sometimes work, but sometimes doesn't. It's a race condition. We just had a CI build on a tag which failed whereas it was succeeding on the commit the tag is on (i.e. exact same code), just because of this race condition.Expected behavior
I looked up documentation and I see that we could add
depends: [ gitversion_h ],
on each and everywindows.compile_resources()
calls. We have more than 30 of these. And we have another rc file which has the same issue, and finally we have other rc files generated from the first one. Basically we have a lot of these calls. We could all update them, but this is bug prone as hell. This should be taken care of on the rc generation level. Basicallygimp_plugins_rc
target should not be created beforegitversion_h
target. This is basic build order which makes sense (even thoughgitversion_h
is not a dependency to buildgimp_plugins_rc
, it is definitely a dependency to use it, so it makes no sense to makegimp_plugins_rc
available beforegitversion_h
).This is why I am not asking to add a
depends:
option onconfigure_file()
or or any other target type. Instead I propose a generic call to wait for another target. My proposed naming idea was await()
call, though it could be anything else as long as it allows to create call orders when needed:The fact is also that we can never take every special case into account. There will always exist some special build case where we need to wait for another target (for reason X or Y which matters to the project). So a generic
wait()
rule is really worth it as it would take care of all the remaining needs.system parameters
This was a cross-build but it doesn't matter for the requested feature.
Build on Linux Fedora 33 for Windows, but once again, this is a generic feature so OS don't matter.
Python 3.9.0
meson --version
0.55.3
ninja --version
if it's a Ninja build1.10.1
The text was updated successfully, but these errors were encountered: