Small Project Build Systems (2021)
neilmitchell.blogspot.com
neilmitchell.blogspot.com
I'm thrilled people are developing other options, building a project "forwards".
FYI "strace" on Linux makes it doable to trace build dependencies. Alas it doesn't work on macOS, and I haven't found an easy equivalent.
Ptrace is one option for tracing dependencies, but it comes with a performance hit. A low-level alternative would be ftrace (https://lwn.net/Articles/608497/) or dtrace (https://en.wikipedia.org/wiki/DTrace).
Tup uses LD_PRELOAD to intercept calls to C file i/o functions. On OSX it looks DYLD_INSERT_LIBRARIES would be the equivalent.
If I'm working on a complex software project, I'll probably use an appropriate build system. Maybe Bazel, CMake, sometimes even Autotools.
But I'll probably also keep a Makefile somewhere, and use it to automate the process of running that shiny build system.
I've been using a simple unity-build ad-hoc build.bat/build.sh "system" for years now, works wonders.
YAGNI will serve you well, 99.99999(repeating)% of everyone's code will only be built and run on 1, maybe 2 platforms, why bother with these insane monstrosities that we call 'build systems"?
The few times I've needed to build for a new platform I just wrote that build script then and there, took a few minutes and that was it.
Modern machines can churn through a tens if not hundreds of K lines of C code in less than a second, so incremental builds aren't needed either (and if anything, with too many translation units you end up with linking being a bottleneck).
Single TU benefits:
- Global optimizations "for free".
- Make all functions static (except main) and you get --gc-sections "for free".
- Linking is blazingly fast.
- Don't have to bother with header files.
- No one has to download anything to built my code, I make it work on a default msvc/gcc/clang install (i.e if you have gcc, cl or clang in your path when running build.bat/build.sh, it will build).
* one TU with code that is fast to compile and modified often
* another TU with code that is slow to compile but modified rarely
I still use header files, but the fast-to-compile and modified-often code goes directly into headers, so I can still organize my code into separate files.
https://github.com/akkartik/mu1/blob/master/build2
More details: https://news.ycombinator.com/item?id=33574154#33575045
If Bazel didn't have so many gotchas, it could be the one:
cc_library(
hdrs = [ "app.h" ],
srcs = [ "app.cc" ],
)How do we streamline this? bzlmod and bcr are steps in this direction, but it still seems far away to me.
People avoid Bazel due to Java like vegans avoid a meal containing meat; it's silly honestly.
I developed my own tool for building C/C++ projects which follows this style. It automatically handles things like Qt moc and scans the source files for headers, so in your example even the hdrs line can be omitted.
really like gnu make now. i know it can solve the problems i have, and chatgpt helped me get there. when dependencies are setup properly, it's quite amazing to see it work.
I do still use Makefiles directly when there isn't an environment to search for - namely AVR projects where there are no libs to find.