r/cpp • • 4d ago

Why is there no proper build system (CMake exists but...yk) like cargo in C++?

Meson and Bazel exist but I have not seen widespread adoptability.

Edit: I forgot to add package manager in title as well lmao

0 Upvotes

52 comments sorted by

14

u/jesseschalken 4d ago

There's a bazillion build systems for C++. People are not running g++ directly as part of their workflow.

Are you talking about a package manager?

2

u/GodRishUniverse 4d ago

Yes... I was about to write in title but missed it lmao - human error. But package manager as well

2

u/LB-- Professional+Hobbyist 4d ago

Because C++ ABI is too fragile. A package you build and publish today will be unusable once the next compiler version is out. The C++ community isn't willing to sacrifice performance to fix that problem. Linux addresses the problem by distributing compiled binaries in their package manager, built to work with the compiler toolchain also distributed with their package manager, and most libraries stick primarily to the ancient C ABI which is nearly set in stone at this point. It's not a very useful solution for C++-to-C++ dependencies.

0

u/donaljones 2d ago

Irrelevant? Rust doesn't have a stable ABI either and cargo works fine

-1

u/LB-- Professional+Hobbyist 2d ago

You are talking about a different ABI from me. Rust lets you mix and match different versions/editions of the language in a single binary without worry of breaking things. C++ does not. If I compile one C++ dependency as C++11 and my main program as C++20, best case scenario I get a linker error, worst case scenario I get undefined behavior at runtime. You have to be very careful to avoid such problems in C++, so most people build everything from source with the same standard and compiler settings and just tweak individual sources/dependencies that are known to be safe to tweak, when required. A package manager would have to have a deep understanding of which things would cause problems and require syncing build settings and which things are fine to let build settings differ, among many other things. I have so far not seen a single package manager better than git submodule and adding sources to my project's build.

1

u/13steinj 2d ago

The -std version does not trigger UB across versions. Compilers explicitly call this out.

That said, there have been mistakes over the years that have made it so that across stdlib versions (not std revisions, generally not compiler versions but they tend to go hand in hand with stdlib versions), you can end up with an ABI break. In my experience it is more likely if you use a downstream (e.g. linux distro, that has patches) compiler, rather than upstream.

That said, this is also irrelevant as to why C++ doesn't have a standard package manager.

1

u/LB-- Professional+Hobbyist 1d ago

I was not talking about the C++ standard library, and I don't know why you assumed I was, given the context of the conversation being for package/dependency management. There's very little a compiler can do to guard against ABI breaks from changing C++ language standard in random C++ dependencies.

16

u/ezoe 4d ago

C++ wasn't and still isn't owned or developed by single organization.

After Bjarne Stroustrup implemented the original C with Classes and C++, many companies tried to write their own C++ compilers.

Bjarne Stroustrup didn't started an organization to centralize the evolution of C++ but he instead chose ISO standard.

During late 1980s to 1990s, there were so many environments and the nature of C++, C compatibility, zero overhead and compiled to native code, made creating these common build system with package manager difficult.

Even after 2000s, C++ still retain the old way and there is no strong central authority to develop the common package manager for C++.

7

u/ventZl 4d ago

One thing to remember is that common build systems with package management are largely late-90s thing at best. That holds only if we consider autohell belonging to this category. If not, then we'll get past year 2000.

When C++ was establishing that concept wasn't even viable. Transferring huge amounts of data "just for sake of comfortable build" wasn't feasible for many people even around year 2000.

0

u/GodRishUniverse 4d ago

Interesting! Thanks for the insight. Do you think uptaking a package manager project for C++ a good idea?

13

u/ezoe 4d ago

Good luck inventing 15th completing standards.

https://xkcd.com/927/

0

u/GodRishUniverse 4d ago

Lmao πŸ˜…

8

u/t_hunger 4d ago edited 4d ago

No. Good tooling needs conventions that everybody follows. That's why cargo and company work: The came in early and established conventions. It is way too late to introduce conventions into C++ now.

Any tool will start out implementing the conventions of the project they know best and be easy to use. The next project finds that compelling and wants to adopt your tool for its easy of use. Of course they can not adapt to all the conventions of the first project, so you add a few compromises: A switch to turn off something, a knob to configure something else. Repeat a couple of times and any user will need to twiddle a lot of knobs to get anything done.

C++ developers (especially the senior ones) are heavily invested into whatever they are using to build the code they work on. They spend decades building scripts, scaffolding, and setting up their systems with exactly the right stuff installed into the right places. They hardly ever notice the suffering new people have to go through. They are in a position to insist your tool does not improve anything (they care for) or that you better make sure nothing (as meassured by their setup working without updating any script) actually changes.

In one project we wanted to replace the build system after 15 years of use. A senior dev had scripts that used the previous tools syntax and conventions. He insisted that those scripts continued to run unchanged: He does not see the need to change anything that worked flawlessly (his words, not mine) for 20 years. So the new build tool ended up with the requirement to be compatible with both the current and the previous build tool. Working on C++ tooling is a very frustrating experience at times.

1

u/GodRishUniverse 4d ago

Damn. Makes sense to be honest. I would also be apprehensive if something works for 20 years and we want to change it

2

u/t_hunger 4d ago

Spoiler: It has not worked flawlessly ever. The previous built tool was severely broken in many ways. That is what made those scripts necessary in the first place. The current one had fixed most issues, but left others unfixed -- because the scripts working around those problems would break otherwise.

The new one also makes a ton of compromises to accomodate our old-timers.

3

u/steveklabnik1 4d ago

Do you think uptaking a package manager project for C++ a good idea?

A few years ago there was an attempt, but the relevant people, in my understanding, burned out in the process. See here: https://www.reddit.com/r/cpp/comments/1hgpz0y/wg21_aka_c_standard_committee_december_2024/m2lt4tn/

5

u/johannes1234 4d ago

Since different people have different opinions and C++ has a few decades of history during which the environment (from DOS machines with floppy disks to today's machines) changed and during which people created their systems and moved them along, based on their needs.

Also one decided that the standard focusses on the language and leaves the way compilers work and at invoked out and has a world where multiple compilers exist.

4

u/official_business 3d ago

any project of any complexity will have its own build system and no one is going to rewrite that because the committee pulled something out of its ass.

My company would ignore any such project completely.

7

u/TheRavagerSw 4d ago

Look, this is a very complicated problem.

Build systems operate on higher level compared to your toolchain, which is a fancy word for a collection of tools such as your compiler/linker/sdk. Your build system uses these tools to produce binaries. Package managers operate in a higher level then this, they call these build systems in a specific order and store their output to some location in your disk.

The way you would ideally build your software is that, you have sources in your disk, you write package recipes for them, you call your package manager, it calls build systems and builds the thing you want.

The real complexity occurs at the fundementals, such as when you need to build a program to build or use a library(icu, qt) or it relies on different languages. Such as some old math libraries using fortran.

Rust's cargo isn't a good solution, because it relies on a global registry, meaning you download sources from the internet when you build stuff. Additionally, if you want to use languages other than rust, it fails to deliver. Rust is only really useful in professional settings if you use bazel.

So, this is a very hard problem without easy solutions, employers should pay competent devs their due to get it solved. Rust isn't a solution and never will be.

1

u/Certhas 16h ago

Except none of the supposed problems of cargo are all that true or all that relevant to the point. Maybe cargo doesn't solve the problems associated to the largest and most complex builds. But if it solves all problems for everything below that, that is a massive success. For situations that are genuinely complex, it's okay that you have to learn a genuinely complex tool. It is a nonsense argument that there is no value in making the easy things easy because the complex things also exist.

Others have commented about the real points: You need to be early to establish conventions. It's now very hard/impossible for C++ to solve this problem. But Rust, Go, Zig have a genuine advantage here. And this is actually especially relevant in heterogeneous environments where C++ is not the main language (my situation). We avoid having to build C/C++ if at all possible.

(It's also worth actually getting things right: Cargo supports custom registries and vendoring dependencies, so no you don't have to download stuff from the internet when you build, though that is a (sensible) default it is designed around.)

3

u/lordnacho666 4d ago

History. There's just a lot of things that build up with an old language like cpp, and with no original build system various people have tried to do their own.

4

u/Aerocatia 4d ago

I think CMake with the Common Package Specification is really really good and I wish vcpkg would use it. It solves a lot of the problems seen with C++ packaging and does not introduce some flaws seen with Rust's cargo.

2

u/nderflow 4d ago

Because C and C++ were in widespread use before Internet access was widespread.

As far as I know the kind of package/dependency management you're thinking of was not well known before the invention of the Perl CPAN system.

2

u/ventZl 4d ago

Given the extremely wide variety of ecosystems where C and C++ are used, it is naive expect that any build system that will cover them all won't get as complex as CMake, or leave a lot of stuff at the user (as Makefiles and/or Cargo).

2

u/Abject-Kitchen3198 4d ago

What's wrong with make?

2

u/CreativeAlbatross319 4d ago

Same reason as Go, Zig or Rust not widely adopted in the industry, except hobby projects and few leading projects from big corps.

There is a term for this: path dependence

2

u/cisco1988 Cloud Engineer 4d ago

Ok for rust and zig but go is used a lot

6

u/CreativeAlbatross319 4d ago

Let me guess, it's the same group of people using Bazel? :D

1

u/cisco1988 Cloud Engineer 4d ago edited 4d ago

kinda more. A lot of webservices, webapp, docker and so on :D

1

u/13steinj 2d ago

C++ does not have a reference implementation, only a standard specification.

Historically, people would just share source tarballs, sometimes static archives. In practice, the latter works often enough to have been acceptable from more or less the start of C up until 2011. After that, with the required ABI break in C++, even though itself irrelevant, I have seen an exponential uptick in poorly formed static archives. Usually because they shove in another common dependency without versioning/mangling the symbols.

CMake isn't perfect, but it gets the job done and is flexible and powerful enough for everyone's needs. Where it isn't, it's open source-- submit a PR. Package management for a number of languages attempted to get standardized over 2016-2020, there was a widespread crisis in getting a package manager for multiple languages. But with no reference nor majority implementation for C++, neither did a single one come about. Nowadays there are 3 (4?) major competing systems: Conan, VCPkg, Bazel, and CPM (/honestly just raw vmake FetchContent). All that said, the public registries are all subpar. Convincing a project to have a high quality canonical recipe, let alone 3+, is a high bar.

There was work to standardize a spec with the Ecosystem IS and also with the Common Package Specification. The former died after the committee made it clear they didn't care, the latter is too early to tell if it will be useful. The Ecosystem IS, IMO naively, rejected creating or blessing an existing package manager as an "official" one.

1

u/UndefinedDefined 4d ago

In the long run all the "history" arguments are irrelevant.

Starting a go or rust project is super simple and building programs using these languages too. Try to build servo browser and compare that to building chromium.

I think that this entry barrier is doing no good to C++ honestly.

1

u/Slsyyy 4d ago

History. C/C++ build system was designed in an evolutionary fashion starting from simple header/source files and shared/static libs. This blurs responsibility of each part (compiler, build tools, package manager, modules) and each of them suck, because they don't work together and try to be as independent as possible

The correct way from a modern perspective is to have everything developed together with a single goal of building the end result artifact

0

u/mark_99 4d ago

I'd recommend using pixi for toolchain, cmake+ninja for build and either Conan or vcpkg for package management.

-1

u/n1ghtyunso 4d ago

the problem is not that there isn't one, its that there isnt (just) one

-12

u/zuzmuz 4d ago

cause it's a poorly designed language with a horribly fragmented ecosystem.

5

u/[deleted] 4d ago

[removed] β€” view removed comment

11

u/urdh 4d ago

If anything, C++ has too many build systems. And it’s not like cargo is the only way to build Rust projects, either.

7

u/Tumaix 4d ago

everysingle one you pointed out is not like cargo.

cargo manages dependencies and buildsystem, without the need of complex scripting languages for the project.

1

u/amoskovsky 4d ago

There are C++ package managers, which are pretty close to Cargo.

E.g. Cabin (former Poac)

Cabin exists for almost a decade.

Don't you think if there was a real need in such a tool and/or if the Cargo way was appropriate for C++ use case, then Cabin would dominate after such a long time?

But yet, it has some marginal usage share.

-3

u/Sniffy4 4d ago

huh? the whole point of most of these systems is to manage dependencies so files are not rebuilt. No idea what you're saying.

(CMake doesnt apply, its an IDE-project generator not a build system)

4

u/khedoros 4d ago

I think their point is that Cargo acts as a package manager, like Conan and Vcpkg, as well as a build system. It "manages dependencies" in the sense of fetching and building external dependencies of your project, rather than just in the sense of rebuilding stale artifacts in the project.

2

u/Sniffy4 4d ago

So this is a matter of expectations then. To fetch package-dependencies you have to have repos to fetch them from, and such things did not exist in a standardized way 30 years ago when some of these systems were designed.

Instead you fetched and configured the whole thing manually. Today, the C++ ecosystem has package-managers, as you mention.

0

u/Tumaix 4d ago

and they are not like cargo.
to be frank, i build one and i applied to present at fosdem a no-project project manager for use in educational purposes that act as cargo, for c++:
small configuration file, no-nonsense, that uses conan behind the scenes and manages the buildsystem.

4

u/Sniffy4 4d ago

again, you are expecting a software ecosystem developed in the 90s and 2000s for a language created in 1986 to act exactly like a tool for a language newly-released in 2015.

Surprise, it doesnt.

1

u/Tumaix 4d ago

see that i wrote above that i made one that works like this.
there is no excuse for the tools to suck as much as they do.

1

u/vatsanant01 4d ago

Meson is really good. It solves the major "user-friendly" issue with build systems.

1

u/aoi_saboten 4d ago

A tiny bit of nitpicking. CMake is a build system generator which generates build system files (e.g ninja, make, etc). XMake is a build system but it can also generate files for other build systems (CMake, ninja, meson, make, etc)

1

u/cpp-ModTeam 4d ago

AI-generated posts and comments are not allowed in this subreddit.

-2

u/monsoon-man 4d ago

Here is you answer... C++ folks love crawling on broken glass!

-1

u/ezoe 4d ago

I think what OP think in my is the de-facto single standard build system with built in package manager backed by central remote package hosting service: cargo, pip(or uv is the best for the latest cook kids?), gem, node(or deno, bun? Can't you guys settle it down to unify it?), reber3

-1

u/GodRishUniverse 4d ago

I did research lmao - there are so many but CMake is the standard and the most well used one and unlike tools like cargo (I am really impressed by how well it works) I was curious why C++ didnt have with such ease of use