When writing C++ applications, you will inevitably make use of external libraries. This is a good thing! Code re-use makes us more productive and let’s us build bigger and better products. With Buckaroo.pm we are trying to make this even easier, with a source-only package manager for C++.
Source-only? Yes, and here’s why:
Assuming the C++ code properly abstracts away any system libraries used, the C++ source-code is fully portable. Once it is compiled however, this property is lost since a binary must target a particular instruction set.
When debugging a project, it’s nice to be able to dig into the implementation of the library functions that you use. This is made particularly easy when you are building from source, since the exact code that you depend on is already on your machine!
Users of GCC will be aware of the
std::string ABI changes from 4.9 to 5.0. Whilst this change was necessary to switch to C++ 11, it caused lots of confusion in the community. If you’re already building your project from source, then upgrading is an easy task. 😌
Due to its code-generation features, this is particularly true of C++: the source-code of a library is often far smaller than its corresponding binary. In fact, with reproducible builds, source-code is an excellent form of compression!
A library with 1 compiler switch has 2 possible compiled binaries. A library with 2 compiler switches has 4 possible binaries. A library with 3 compiler switches has 8 possible binaries. A library with 4 compiler switches has 16 possible binaries. Now throw cross-compilation into the mix... You get the idea. Not all of these combinations are significant, but the complexity is enormous. When distributing from source, we can support all possible compiler flag settings by allowing the user to control the process.
C++ is all about building towers of abstraction that the compiler can tear down into efficient machine code. These abstractions are lost after compilation, and with it important information that might be used to optimize your code. When using binary libraries, you lose the opportunity to perform many cross-library optimizations. Building from source can yield faster code.
This is where a good build system is crucial. We chose Buck build, a reproducible build system developed and used by Facebook. Because Buck is reproducible, it becomes possible to cache intermediary build artifacts and share them across your team!