Redo: A recursive, general-purpose build system
I feel like DJB&#x27;s ideas behind redo are actually some of his most poorly thought-out ideas. It seems that he thought, &#x27;Make has &lt;problem&gt;. To solve &lt;problem&gt;, a new build system should have &lt;solution&gt;.&#x27; In other words, he seems to just used additive solutions instead of subtractive ones. [1]<p>Most build systems seem to be like that, adding features on top of features. The end result is usually complicated and finicky.<p>I think that&#x27;s why build systems are among the software developers hate most. And I do mean <i>hate</i>. (The first time and only time I saw an acquaintance, a normally calm person, have an outburst was talking about a build system.)<p>I think the ideal build system will be subtractive, not additive.<p>So I guess this is as good a time as any to talk about my current project, a build system. :)<p>(Most of this will be copied from two comments I made on lobste.rs.)<p>First, there is a paper that already lays out the features needed for an optimal build system: A Sound and Optimal Incremental Build System with Dynamic Dependencies. [2] The features are:<p>1. Dynamic dependencies.<p>2. Flexible &quot;file stamps.&quot;<p>3. Targets and build scripts are Turing-compete.<p>That&#x27;s it. Really.<p>The first item is needed based on the fact that dependencies can change based on the configuration needed for the build of a package. Say you have a package that needs libcurl, but only if users enable network features.<p>It is also needed to import targets from another build. I’ll use the libcurl example above. If your package’s build target has libcurl as a dependency, then it should be able to import libcurl’s build files and then continue the build making the dependencies of libcurl’s build target dependencies of your package’s build targets.<p>In other words, dynamic dependencies allow a build to properly import the builds of its dependencies.<p>The second item is the secret sauce and is, I believe, the greatest idea from the paper. The paper calls them “file stamps,” and I call them “stampers.” They are basically arbitrary code that returns a Boolean showing whether or not a target needs updating or not.<p>A Make-like target’s stampers would check if the file mtime is less than any of its dependencies. A more sophisticated one might check that any file attributes of a target’s dependencies have changed. Another might hash a file.<p>The third is needed because otherwise, you can’t express some builds, but tying it with dynamic dependencies is also the bridge between building in the large (package managers) and building in the small (“normal” build systems).<p>Why does this tie it all together? Well, first consider trying to implement a network-based caching system. In most build systems, it’s a special thing, but in a build system with the above the things, you just need write a target that:<p>1. Uses a custom stamper that checks the hash of a file, and if it is changed, checks the network for a cached built version of the new version of the file.<p>2. If such a cache version exists, make updating that target mean downloading the cache version; otherwise, make updating the target mean building it as normal.<p>Voila! Caching in the build system with no special code.<p>That, plus being able to import targets from other build files is what ties packages together and what allows the build system to tie package management and software building together.<p>I’ll leave it as an exercise to the reader to figure out how such a design could be used to implement a Nix-like package manager.<p>(By the way, the paper uses special code and a special algorithm for handling circular dependencies. I think this is a bad idea. I think this problem is neatly solved by being able to run arbitrary code. Just put mutually dependent targets into the same target, which means targets need to allow multiple outputs, and loop until they reach a fixed point.)<p>So how would this build system fit into the table (page 27, Table 2) of the &quot;Build Systems a la Carte&quot; paper?<p>It fits 8 of the 12 slots.<p>This is done with another feature: power-limiting. It will be possible to tell my build system to restrict itself, and any attempt to go beyond would result in an error. (This is useful in many situations, but especially to help new people in a team.) My build system can restrict itself along three axes: dependencies, stampers, and code.<p>To implement dynamic dependencies, you need a suspending scheduler, so obviously, my build system<p>The stampers are actually what defines the rebuilding strategy (and it can be different for each and every target), so there could be stampers for all of the rebuilding strategies.<p>This, technically, my build system could fill all four slots under the “Suspending” scheduler strategy in the far right column in table 2 on page 27.<p>In fact, packages will probably be build files that use deep constructive traces, thus making my build system act like Nix for packages, while in-project build files will use any of the other three strategies as appropriate. For example, a massive project run by Google would probably use “Constructive Traces” for caching and farming out to a build farm, medium projects would probably use “Verifying Traces” to ensure the flakiness of mtime didn’t cause unnecessary cleans, and small projects would use “Dirty Bit” because the build would be fast enough that flakiness wouldn’t matter.<p>This will be what makes my build system solve the problem of scaling from the smallest builds [3] to medium builds [4] to the biggest builds [5]. That is, if it actually does solve the scaling problem, which is a <i>BIG</i> “if”. I hope and think it will, but ideas are cheap; execution is everything.<p>Additionally, you can turn off dynamic dependencies, which would effectively make my build system use the “Topological” scheduler strategy. Combine that with the ability to fill all four rebuilder strategy slots, and my build system will be able to fill 8 out of the 12.<p>Filling the other four is not necessary because anything you can do with a “Restarting” scheduler you can do with a “Suspending” scheduler and Turing-complete code. (Just use a loop or a stamper recheck as necessary to simulate restarting.) And restarting can be more complicated to implement. So in essence, my build system will fill every category in the BSalC paper.<p>And I could do that because I took things away instead of adding more.<p>[1]: <a href="https:&#x2F;&#x2F;www.nature.com&#x2F;articles&#x2F;d41586-021-00592-0" rel="nofollow">https:&#x2F;&#x2F;www.nature.com&#x2F;articles&#x2F;d41586-021-00592-0</a><p>[2]: <a href="https:&#x2F;&#x2F;www.informatik.uni-marburg.de&#x2F;~seba&#x2F;publications&#x2F;pluto-incremental-build.pdf" rel="nofollow">https:&#x2F;&#x2F;www.informatik.uni-marburg.de&#x2F;~seba&#x2F;publications&#x2F;plu...</a><p>[3]: <a href="https:&#x2F;&#x2F;neilmitchell.blogspot.com&#x2F;2021&#x2F;09&#x2F;small-project-build-systems.html" rel="nofollow">https:&#x2F;&#x2F;neilmitchell.blogspot.com&#x2F;2021&#x2F;09&#x2F;small-project-buil...</a><p>[4]: <a href="https:&#x2F;&#x2F;neilmitchell.blogspot.com&#x2F;2021&#x2F;09&#x2F;reflecting-on-shake-build-system.html" rel="nofollow">https:&#x2F;&#x2F;neilmitchell.blogspot.com&#x2F;2021&#x2F;09&#x2F;reflecting-on-shak...</a><p>[5]: <a href="https:&#x2F;&#x2F;neilmitchell.blogspot.com&#x2F;2021&#x2F;09&#x2F;huge-project-build-systems.html" rel="nofollow">https:&#x2F;&#x2F;neilmitchell.blogspot.com&#x2F;2021&#x2F;09&#x2F;huge-project-build...</a>