107 points · by jstimpfle · 8y ago · 90 comments
Please don't do this for open source projects. Other people may want to use your code, but they generally don't want yet another build system. There are already a lot of build systems that are building very complicated projects. Surely, one of these existing, widely used build systems can be made to work for your project.
If it's about making it easy for uninitiated collaborators to add new source files, then the listed build description format is pretty self-explanatory to use. And the build script just needs to be run. It takes no arguments, so I don't think there is a problem with that.
This misses the point IMHO. In practice, whatever complex the build system is, it's generally easy to add a new source file: simply grep for an existing source file name, find the build files that refers to it, and insert a similar line for your new file.
> And the build script just needs to be run. It takes no arguments, so I don't think there is a problem with that.
What about: cross compilation? ccache injection? verbose builds? parallelism control? installation prefix? Try being a package maintainer for a GNU/Linux distribution, where all of the above needs to be kept under control. You will despise custom build systems.
Established build systems (like GNU Autoconf (e.g gcc), and, to some extent, custom Autoconf (ffmpeg, libvpx)) handle all these cases pretty well, and provide fixed commande-line options (--prefix, --host) to control them. This means the project author doesn't get to decide how the option will be named and how it will work.
This make a huge difference if you're trying to packages for your distrib dozens of projects from dozens of various authors.
With a custom build system, the best case scenario is you have to re-learn all these options for each project. The worst case scenario is: one project doesn't support some use case (e.g cross-compiling), so you have to maintain a patch that hacks into the build files to add the behavior your need.
The best case scenario would be that it handles all of those scenarios in A) a highly readable way and B) has high quality documentation that demonstrates the use of all the necessary features in context.
Make's approach appears to be to use cryptic flags and settings and the best case documentation appears to be "have you tried stack overflow?". It is not the be all and end all of build systems.
Additionally, for many of the non-C++ workflows I want to accommodate, the 'make' approach appears to be hack around its deficiencies with bash scripting. Stringing together hacky bash scripts is not what I would describe as a best case scenario in any project.
I don't think of this guy's project is a meaningful competitor to make/cmake but equally, I can envisage other projects doing a better job than make on its home turf.
None of those are features that developers care about. They are only of interest to package maintainers, systems administrators and other lunatics.
Making an idiosyncratic system is satisfying, but the usefulness of your work is decreased if it's decorated with locally invented barriers to comprehension.
Rock on; scratch your itches.
If you write a generic makefile the uninitiated collaborator doesn't have to do anything to add new source files.
Honestly even bazel isn't built with bazel. (it can be, but they do that as a test)
It's like rolling a whole new project into your existing ones... For no clear reason.
Perhaps it's a learning experience, however there's no reason to hobble a project with it.
Thankfully, I doubt most established projects would suddenly switch to a custom build system.
Also there are plenty of auxiliary tools developed for build systems which are at best, difficult to reproduce.
If one needs to improve a build system... Try a pull request?
> there's no reason to hobble a project with it.
I think this underestimates the complexity and overhead of using and configuring some* existing build systems, and also overestimates the complexity of running (no need to edit the build config for most contributions to the project, provided the build system works well) a custom build system.
Established build systems are often complex due to being heavily generalised and configurable. I've seen projects with build configs that are longer and more complex than a custom build system for that project could be.
> there are plenty of auxiliary tools developed for build systems
This is the key comment. You can create your own custom build system while using lower level build-related libraries. There's no need to reinvent the wheel entirely.
* I said "some" existing build systems: I'm sure some are simpler than others, so this may not apply universally.
Our use case was a developer tool that would take in project files, sources, and assets, and bundle them for various platforms, push code to devices, or launch simulators for you. Notably, Shake made it fairly easy to ensure that we never needed to implement a “clean” command—all dependencies were correctly tracked.
Having strong static types and the Haskell library ecosystem available was a huge win for convenience and correctness over something like Make. Shake makes it easy to do concurrent builds with full or limited parallelism, minimise incremental build time, write multi-stage rules where e.g. you need to run the compiler to calculate the dependencies of a file, and properly handle commands that generate multiple output files. Nowadays it even supports progress reporting, profiling, and some linting of build rules.
Also for a project, a custom build system means, that you cannot hire anybody, who knows the build system, however if you are using any established build system, you can.
And also, software developers tend to forget, that they are not the only users of a build system, and usually it needs to be integrated into a build&release pipeline.
In my experience the biggest (or most annoying?) problem though is not setting up the dependencies and executing the steps along the DAG but doing the configuration part of a build: What libraries are installed on the system, giving the user ways to opt in/out of build-time features, figuring out how to build shared libraries on the target OS, how to crosscompile, there’s tons of of these that may need solving depending on your project.
ninja does a fantastic job about handling the core and leaving all the other annoying things for someone else to solve (like cmake with the ninja backend :)
The first is a bash script that ends in
$1 ${2:}
or something in that region. Then I can define functions and call them directly from the command line. It's rather protable (if you have bash or I bothered to write POSIX sh compatible)The other was a simple DAG similar to how the author describes it. Each task was a root node and subtasks were nodes connected to it. To figure out which tasks to run I'd simply scan the entire task graph for what has no subtasks and spawn a thread/process for each runnable task. Once a task finished, it's removed from the DAG. Successfully used to run database upgrade tasks (update multiple tables at once if they queries don't depend on eachother)
The only thing I ask of a custom build system is that it A) includes the classic "all" and "clean" options B) it doesn't have any dependencies beyond what I can expect from any random distro, C) autodetect libraries in common locations, not the locations on the original dev machine and D) don't require root permissions. ever. (outside "install" and maybe we can insert a rant in here how a lot of packages don't have a "uninstall" or "remove" option, making me track down the files it shat onto my disk)
As I explained my motivation was primarily keeping my build description in my own datastructures (see the text database). IMO that's a very worthwhile goal. I then went on to see what it takes to NIH everything, and it turns out that detecting what files need to be rebuilt is hairy, especially considering transitive C includes (which requires a dependency cache). But there is no one solution to these problems, and I do think there is some value in controlling that logic.
And if you get the concepts right, it can be done. I've divided the code into loosely coupled building blocks. That hopefully makes it easier to understand. It should also be possible to recombine these blocks to make different build systems.
If the project allows it, though, your dependencies can be shrunk down until there's no issue. This is far more the case with target languages that already understand modules (e.g. Rust or Python versus C or JS), or "one big framework" projects where you are relying on linking in the one framework and having it do all the heavy lifting on the build side of things.
Actually customizing a build substantially beyond that, tends to be the case more often when you have something like a compiler within your own pipeline, like automatically transforming and clipping source art assets into optimized, UI-ready form. With those systems there is a lot to be said for a simple script that you can debug.
But, as many people pointed out, having a custom build system calls for trouble (eg cross compilation, prefixes, feature control) and often produces a lot of work to maintain or cater to new needs.
Source: We roll a package based, distributed build and test system. Most build packages wrap around cmake. A core dev created it, and while he works on the build system, he can't work on the product. And if he ever decides to switch company or has a severe accident, well... (The code is mostly well written, but still the code base is huge since it was adapted to changing needs in the past decade; and while we're not tiny, we're small enough to lack the resources of having him train a second person in the guts of the system - I know probably 70% of it and am regularly lost).
If it was up to me, we'd take a look at bazel.
And there's this huge sunk-cost that makes it functionally impossible to suggest replacing with anything else. It mostly works but it's getting crustier by the day.
So I feel your pain.
Autotools has really come a long way since the bad old days back in the early 2000s. It's got some crusty corner cases, but I like it more and more as I use it.
With CMake, everything seems like it's easy to bury yourself in custom macros. And before you know it, you have a build system that's complex, hard to debug, and impossible to re-target. Scons is similar (although at least you can step through the code in Python).
I'd encourage anybody to try it out. At least, if your codebase is C or C++ and you don't need to target Windows.
What is the scope? Is this an open source project? How many people are working with it?
To me it looks like this is a personal project that only you are working on. I don't see any problem using this approach. I mean, I use a batch file as my build "system" for my personal projects. But for anything else it would be worth discussing the trade-offs versus using one of the available build systems.
I didn't understand how this works: scanCmd = 'scanincludes-%s' %(oPath). What is this scanincludes thing?
> scanCmd = 'scanincludes-%s' %(oPath)
I have each node in the DAG identified by a unique string, including command nodes. This one is a name I make up for the node that is responsible for rescanning the dependencies of a particular compilation (the compilation is identified by the .o path)
This argument and others similar to it are often repeated but I've yet to see any of those people describe what makes it awkward.
>and it is restricted to filesystem files and shell commands
It'd be pretty easy to make a makefile that depends on say a specific row on a SQL database using dummy files. Also changing the language for recipes is trivial and painfully obvious. If you can't do something as simple as `SHELL := /your/own/interpreter' then why do you think you are qualified to make a build system?
Creating dummy files is inefficient, inelegant, and unmaintainable. Changing SHELL does not solve the inconvenience of having start a new process and having to go through a command-line interface each time.
Btw. watch your language, please.
GNU Make's documentation is very well written though. Like, shockingly well. Don't be afraid to read through it if you see some weird syntax that you can't figure out.
I don't mean to insult you, so please don't take this the wrong way... The Point I want to make is this: Is it even a reasonable project to build a build system that does everything for everybody? It would appear -- from plenty of evidence around in most open-source projects -- that mostly each of them had to work around at least a couple of restrictions in their off-the-shelf build-system, and I haven't seen a reasonable sized project that got away without additional scripting.
So if the developer already has the need for custom scripting, why not take python? And if it Takes less Time+LOC to roll your own project-customized build-system than it would take you to integrate a "general-purpose" build-system... There is a very strong case for a small python script like the one presented here.
If there's a case for an existing build system here, the system in question is not make. There are much better systems out there (scons, cmake...). Just my two cents.
Make can be used for automation of many different tasks, for example web page rendering or database creation, to name a few. And, it has built in rules for handling header files correctly; you would do well to study and understand them.
It's a general purpose DAG runner. It's not really feasible to add parsing for all the different possible languages that one might want to use imports in. Luckily at least GCC and Clang both have the option -MMD and any sane compiler for other languages should have something similiar.
Using a saner tool than plain make for C/C++ is worth it every time in my book.
make can still be very useful for other stuff, though.
Honestly though, raw GNU Make isn't too bad either, except for the not having any good built-in mechanisms for a 'configuration' step.
Having the full power of Python really is something else. So I was considering generating simple repetitive Make rules. But I wanted to explore what it takes to do the rest myself, as well. Setting up dependencies for Make is not nice, either. Having the code under control means being able to adapt to any requirement. It would be easy for example to convert this into a build server kind of thing.
Having a 10s delay is not acceptable to me. I didn't experience that myself though.
There is no simple repetitive make rules in the build system of the project I am on: all the rules are generated using macros. gnumake is a full scripting language that is dedicated to timestamp dependencies. It can manipulate easily lists of string (as long as they do not contain spaces). What are the advanced things that requires a better language ?
There is something awfully wrong if processing 5000 files and cached dependendencies takes 10s. It should take a few ms at most, even if written in a scripting language like Python. I would not be surprised if this is because that build system heavily misuses GNU Make's variable substitution features, instead of being written in a language that features proper data structures (e.g. set, map)