
Simplifying build in C++ - ingve
https://mropert.github.io/2017/10/19/simplifying_build-part1/
======
duality
It does not satisfy all of the items on the author's wish list, but I have
used and enjoyed Bazel[1] as perhaps the nearest build system in existence
that provides a notion of package management to C++. It does not hold prebuilt
binaries to satisfy dependencies. But it does cache builds.

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.

[1] [https://bazel.build](https://bazel.build)

~~~
oscargrouch
For C++ theres also 'GN' from Chrome, that is inspired in Bazel, and generate
ninja build files.

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/tools/gn/)

[https://chromium.googlesource.com/chromium/src/+/lkgr/tools/...](https://chromium.googlesource.com/chromium/src/+/lkgr/tools/gn/docs/quick_start.md)

~~~
duality
I encountered GN for the first time while looking at Google's nascent Fuchsia
OS. It looked interesting but I have dug further.

------
subb
The premise of matching modules and package one-to-one is I think incorrect.
The way I see it, a package is just a library with a description of its
dependencies, and possibly an already compiled binary. It could contains
multiple modules. Plus, you probably need to link with a specific package
version, and the module proposal doesn't have any way to specify a module
version. So you can't just extract package dependencies from module usage.

------
calumrobinson
> One last item remains (and possibly the most controversial): not using a
> language other than C++ to describe how to a package 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?

~~~
ridiculous_fish
Raw C++ is unsuitable as a build language, so you'll have to layer a DSL on
top of it. Either way you're learning a new language.

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).

~~~
desertrider12
C++ as it exists now is unsuitable, but I can imagine an alternate history
where C++ actually allowed arbitrary compile time execution (better than
macros and constexpr). Then someone would have made a library for build system
logic, and all the user would have to do is g++ project.cpp.

~~~
fatbob
Herb Sutter has a proposal for metaclasses, which involve running some
compile-time C++-like code. I don't think it would stretch to this, but it's
heading in your direction.

------
bobajeff
I still haven't learned how to use a build system yet. For me it's just way
easier to put the individual build commands in a .sh file and run it.

~~~
Skunkleton
Honestly, I think very few engineers fully learn a build system. The norm
seems to be learning just enough to hobble along. That said, you should really
try out GNU Make, CMake, or similar.

~~~
bobajeff
I have...

------
arximboldi
I like Nix. Only problem is it doesn't seem to work on damn Windows. Nix has,
in my setup, made the build system topic almost irrelevant, since it allows
for simpler build scripts to play well with other dependencies. Plus, it works
with stuff in any language and polyglot projects are a bliss. I really hope it
catches traction.

~~~
dj-wonk
I also like Nix. Can you share your particular workflow?

Also, how does your workflow handle ‘snapshot’ / temporary dependencies?

------
maxxxxx
C++ really needs an ABI standard. It would make builds and package management
much easier.

~~~
gpderetta
It is impossible to have a standard ABI for a language that is supposed to be
compiled down to machine code and run as native executable. The ABI is tied to
the OS and specific machine. At best you can have standardized machine
specific ABIs.

Which is exactly what we have.

~~~
maxxxxx
Machine specific ABI would already be great. Whenever I need a new library it
takes forever to figure out how to integrate it correctly and add to the
build. From observation this also trips over most newbies who don't know all
the subtleties.

------
epage
Decoupling build from dependency management I think is the great feature of
conan.

[https://www.conan.io/](https://www.conan.io/)

------
dj-wonk
Besides CMake, Bazel, and Conan, what build system or related project(s) are
worth looking at? Which one(s) would you recommend? (See other threads as
well)

~~~
oscargrouch
As i've said in another comment, theres also GN, the build system used for
Chrome.

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/tools/gn/)

[https://chromium.googlesource.com/chromium/src/+/lkgr/tools/...](https://chromium.googlesource.com/chromium/src/+/lkgr/tools/gn/docs/quick_start.md)

------
llimllib
Seems like the horse is out of the barn, across the hay field, down the
street, and over to the next town on this one.

------
geezerjay
No love for autotools?

