Hi group,
I'm asking here because I'm not sure I have this narrowed down enough to open a Github issue.
I started using the Ninja generator, and boy, I don't want to go back to Make ever again. This should really be the standard way of building stuff, as make is just so bad compared to it.
It's not just the speed, but far more the correctness when running parallel builds (-j).
This the grep I'm currently using to trigger a rebuild if Make fails for some reason:
if grep -q \
-e "fatal error: opening dependency file" \
-e "unable to open output file" \
-e "Error opening output file" \
-e "cannot open output file" \
-e "internal compiler error" \
-e "No rule to make target" \
-e "hardware or OS problem" \
-e "can't create precompiled header" \
-e "one or more PCH files were found, but they were invalid" \
makeoutput.txt; then
(trigger rebuild...)
And yes, I did a lot of research on this, and tried to rule out broken filesystems, overheating, faulty hardware, etc. But I see these sporadic failures on 4 different machines (Linux, Mac OS), and even on occasion when running a fresh install of Ubuntu inside a VM. Maybe it's not Make's fault, and the Makefiles that Premake generates aren't compatible with parallel builds? Anyway, Ninja is much more robust in that regard, parallel builds are the default, and it shows.
So I really want to use Ninja, but can't because my project relies on post build commands to copy external libraries to the target directory. The Ninja generator (
https://github.com/jimon/premake-ninja) works great so far, but it doesn't support any custom build commands.
I gave it a shot myself, but I'm not sure if this can be implemented for Ninja the same way as for Makefiles. The problem is that Ninja syntax doesn't allow more than one command for a build rule. You can chain commands on Linux with &&, but this won't work on Windows, where you would have to use a horrible cmd.exe /c kludge to wrap the commands. I'd like to avoid that if possible.
So it would be better if the post build command could be a separate rule that is chained to the "link" rule, as I only want the post build command to run whenever the project is built, and that means running after the linker. However, I tried to add a another rule like this:
targetdir = bin/macosx/ninja/debug
rule postbuildcommand1
command = cp path/to/sdk/library.dylib $targetdir
description = post build command
build postbuildcommands: postbuildcommand1
build bin/macosx/ninja/debug/libmyproject.dylib: link (...all of my dependencies...) || postbuildcommands
And this kinda works, but now everytime I run the ninja command, the post build command is run even if there were no changes in between. I guess this is because Ninja needs inputs and outputs for rules, otherwise it assumes it has to run the rule everytime? Inputs and outputs are not known to Premake for post build commands, though.
A workaround could be to add another build target that just executes the custom build commands, and nothing else. It's really a kludge, too, so I though maybe you guys have some ideas how to approach this.
Sorry for the long read...
Thanks for taking the time, and any help is appreciated!
-Jones