Ask HN: Semi-automatic build configuration? C++ Modules?
Consider the following:<p>* 25 million lines of C&#x2F;C++ code in one Git repo<p>* Mission critical code<p>* Statically linked except for system&#x2F;libc etc<p>* No cross compile. Apart from debug v. release builds there&#x27;s one target arch: Intel x86_64 Linux<p>* Management wants assurance all code built without skipping files and&#x2F;or missing a link; want automatic and correct-by-construction build process wherever possible. Do not want devs abandoning files not used etc etc [1]<p>* Devs add (periodically remove) libs. Code changes all the time<p>* things not in scope: Xcode&#x2F;Vstudio or anything that wants to configure in a IDE. Solution must be 100% at command line<p>Coarse first cut solution:<p>* Mandate official dirs holding code e.g. src&#x2F;lib, include<p>* Mandate meta file format and content which describes library&#x27;s dependencies. This is manual and therefore we accept it&#x27;s an opportunity defect. Thankfully library additions smallish, and once OK, stay OK mostly. Anyway risk non-zero here.<p>* Mandate where unit, integration tests go<p>* Mandate where tasks (things with &#x27;main()&#x27;) go<p>* Mandate file names e.g. if &#x27;foo.c&#x2F;foo.h&#x27; is part of a library &#x27;Infra&#x27; we expect to see &#x27;src&#x2F;lib&#x2F;infra&#x2F;src&#x2F;lib_infra_foo.c, src&#x2F;lib&#x2F;infra&#x2F;include&#x2F;lib_infra_foo.h&#x27; so that file names are somewhat self describing<p>* Write script to roll-up above outputting a CMakeLists.txt (or ninja etc) input. From there a real Makefile follows with build flags<p>* CI test rejects PRs with source outside official dirs or failing org structure<p>* In sum directory structure and content induce a lot of what&#x27;s built. What the structure cannot say is deferred to meta data files. This solution makes an argument that so long as the meta data is right, the build system will reflect the number and structure. Compilation and linker errors flush out the rest.<p>Exotic additions could include:<p>* clang ast passes to insure public code in lib_infra_foo.c has callers somewhere (we provide switches to gcc so the linker excises code not called in a lib too)<p>* verify builds for header inclusion correctness e.g. build src&#x2F;lib&#x2F;infra&#x2F;src&#x2F;lib_infra_foo.c and inspect that it&#x27;s first include is src&#x2F;lib&#x2F;infra&#x2F;include&#x2F;lib_infra_foo.h and all headers it drags in are actually used<p>Does anybody have a better first-cut idea or think libs as C++ modules will hit a sweet spot?<p>[1] There are ways to argue with or against management. In the master craftsman sense, devs don&#x27;t need handholding. As source&#x2F;libs are added or removed devs will update Cmake (ninja) build files and ... case-closed. In the palpable-fear sense, management and release managers want some assurance things are organized smartly. Devs are help no doubt, but devs sometimes screw stuff up. Better to be sure. In this post the motivation isn&#x27;t salient. Engineering a reasonable solution is.