Simplifying build in C++
mropert.github.io
mropert.github.io
Nor does Bazel use C++ syntax to describe the build, instead using a variant of Python called Skylark, but this feels (to me) much less onerous to pick up than the custom scripting language CMake uses.
Bazel also provides a notion of visibility of dependencies that allow you in effect to control which build targets are exposed to other targets as allowed dependencies. And allows the build tool to specify a toolchain (compiler, linker, etc.) and machine architecture. This information is used when building all the dependencies, which in effect satisfies the author's request for compatibility between packages. You might even argue that a (caching) build from source may be better than attempting to serve prebuilt binaries.
Getting up to speed can take a little doing though as the original docs weren't great and there are some counter intuitive things about it. I think the docs are improving but some things a little odd like everything gets dumped into ~/.cache/bazel without any command line option to change [1]. Feels like the first time I used git where you suspect that the authors designed it to be difficult to keep the lazy away.
https://docs.bazel.build/versions/master/output_directories....
You can also specify a toolchain, have custom actions for asset or code generation, etc..
GN itself is in C++, unlike the older build system for chrome 'GYP', and it produces a binary tool, that can process meta build file with a syntax very similar to Bazel.
https://chromium.googlesource.com/chromium/src/tools/gn/
https://chromium.googlesource.com/chromium/src/+/lkgr/tools/...
Would you use it for an open source project? It feels onerous to ask users and contributors to install a moderately esoteric build tool (which in turn requires Java) to build a C++ project.
Totally agree on this point. Why learn all the quirks of the CMake language just to express the structure of my program?
As to "why learn all the quirks of CMake," the selling points of CMake are its widespread availability, maturity, and coverage. For example, just on the packaging side, it knows how to create tarballs, .debs, .rpms, Windows .msi files, multiple flavors of Mac installers...
Less mature build tools require you to implement this stuff manually. CMake mostly handles it for you (and has the scars to prove it).
All those actions can be easily modeled in a libraries coupled with a DSL.
It has enabled Cargo use its own package ecosystem at build time as well, so build scripts can easily reuse other crates instead of reinventing the wheel for each project.
It also saved Cargo from needing to be a build system that works with everything and supports everyone (the midlayer mistake[1]) and instead 3rd party build-time crates and *-sys library wrappers provide the flexibility.
Python uses a Python script as the main entry point to the package, and it's commonly problematic as doing all kinds of weird shit so your package builds (on your machines, until you change your configuration) is a smaller step than looking up what the system already provides, and thus the default. It also makes static package in(tro)spection much more difficult.
I get the feeling that they're making the exact same mistake that Cabal/cabal-install did in the Haskell world[1] -- they just don't have complex-enough builds and/or a big enough ecosystem yet to know it.
(In Cabal/cabal-install there's a "Custom" build type where "anything goes". Unfortunately that means that it's basically impossible for any higher-level tooling to have any idea of what's going on in the build... and hence it thus powerless to introspect anything useful. It's a huge pain.)
[1] Not that I blame them, it's just such a tempting thing to do rather than completely redesigning the build system to accomodate everything and provide enough introspection/metadata. So it goes, I guess...
There has been some discussion about making things more declarative, if this is ultimately the right approach, etc. But you have to do something before you can know for sure what the problem space entails.
In our case, one of the largest uses of build.rs is to link to things written in C and C++; there's no unified tooling there, so if you wanted to make some sort of DSL to handle this, you'd have to also solve that problem, which is a huge undertaking.
I am pretty convinced that "we" (as an industry) already actually know 95% of what the 'problem space' of a build system is, but everybody just wants to greenfield and try to do their own. Why? Because it's more fun! There's no actual real rationale for reinventing everything every few years. I guess it comes about from a lack of attention to history and a lack of attention to the state of the art, e.g. Shake in Haskell-land.
Sorry to be so negative. I'm sure that Cargo at least works really well according to the 80-20 rule :).
(AFAIUI Cabal:Custom had exactly the same reasoning, btw. "It's too difficult! Let's just give up and allow anything.")
It might be a practical reality that this is just unavoidable if you want to achieve success, but at a meta-level I think deserves thinking about whether builds should actually be allowed the full Turing Complete treatment. At least, theoretically: As long as we continue 'allowing' Custom for practical reasons and without serious thought, there can be no progress.
(Btw, I'm quite mad which it comes to this type of thing. I spend way too much time thinking about build systems, etc.)
EDIT: This problem manifests EVERYWHERE: Docker builds randomly guess wrong about whether inputs have changed, cabal-install gets it wrong, SBT/Zinc doesn't quite track dependencies correctly, etc. etc. and it's infuriating.
Also, how does your workflow handle ‘snapshot’ / temporary dependencies?
Right now the "best" solutions are COM (aka UWP) on Windows, and the C++ Itanium ABI description.
Even C does not have one, just that most mix language ABI with OS ABI, which happen to be the same on OS written in C.
If you pick something else, not written in C, for example IBM i, then the ABI is actually TIMI, the OS/400 bytecode format.
MBIs, the binary format for modules, might be the answer but until then there are many issues to tackle and agree upon.
Which is exactly what we have.
It's bazel-like, in C++, so you can have a binary tool, and it outputs ninja build files.
https://chromium.googlesource.com/chromium/src/tools/gn/
https://chromium.googlesource.com/chromium/src/+/lkgr/tools/...
There's a pretty interesting compiler wrapper called "fastbuild" that really lives up to its name.
C/C++ build environments are fascinating to me because there are so many. They solve this swarm of overlapping problems in many different ways.