r/cpp • u/TheRavagerSw • 3d ago
Why we shouldn't want a remote package registry, universal package manager or a binary toolchain orchestrator
Hi, as most of you now, we get cargo good cmake bad posts and comments here nearly every week.
I want to write a definitive post to answer these criticisms. In this post I'm going to argue for a decentralized approach instead, and will try to list some cons and pros of this approach.
Cargo is the package manager of the rust language, it stores packages in source form in a remote registry called crates.io, It also sort of acts as a build system, as you invoke it directly, rather than calling the package manager first then the build system. The problem with this approach is that you don’t own sources, you don’t know about licenses. If one of your packages break, trying to fix it is very annoying. Also builds are very slow, since you don’t have local binary cache for packages. Additionally, unlike a sane dependency model as proposed by Titus Winters. Cargo relies on semver. This means your dependency tree will not scale and will be hard to maintain.
Rustup is a toolchain orchestrator tool that downloads compiler, stdlib and various other tools from the internet.
It seems very nice to be able to setup a toolchain in seconds, as opposed to doing that with c++ which takes very long.
The drawback of this approach is the lack of knowledge about dependencies of your tools wnd especially stdlib. You need to know what version of xcode or msvc you app is compiled against.
What to do then?
We need a decentralized solution, organizations should clone their deps from a remote and write package recipes for them, we need some sort of organization to collaborate and several standards to make this easier, such as a binary package format.
Cargo and rustup are currently more closer to web technologies in toolchain departmant than c++, I don’t see why everyone is so obsessed about it. There is a new slop project written on it every minute, and we think that's a good thing. It is not, it made library quality very questionable.
Wrote on my phone so probably a lot of typos.
20
u/NewLlama 3d ago
This is one of the most talked about issues in the C++ ecosystem but it doesn't seem like you've brought any insights to the discussion?
24
u/La-ze 3d ago edited 3d ago
This seems painfully unaware. Your solution describes the existing problem.
C/C++ is decentralized and that's currently the problem. It is every dev for themselves, with no standard compiler, or maker. Never mind all the compiler & maker flags, compiler & maker versions, and C/C++ language versions. This makes package management an insane exercise in C/C++. It's not a pro, that companies have whole teams dedicated to C/C++ build systems to understand them better. This is an unmitigated engineering failure, of a system that should nominally be transparent.
Meanwhile, a rust dev can just look at their manifest or cargo to see what version of a given crate is being used. There's no lost knowledge. They have a standard compiler, maker and package manager. No matter how unoptimal it is, it is far superior to the alternative.
9
u/t_hunger 3d ago edited 2d ago
I think you actually want a central repository that publishes version information only after you uploaded the sources for that version. How else can you guarantee that the sources for each published version does not vanish from the internet?
The decentralized approach sounds super cool, but what good does a local repo of sources/binaries do when your users can not get the same sources/binaries because the repo has moved or the author removed the version or the hosting server is offline? Ok, crates.io being offline would be a desaster, but I hope that is less likely than some random private forge hosting some obscure library being MIA.
Semver works decently well in Rust: They have cargo-semver-check to automatically catch breakages. Its not perfect, but pretty good and constantly improving.
Why would I care for xcode and msvc versions when I install rust using rustup? Stdlib is in the same package as the compiler, as is the rust language server... they all are built to work seamlessly together and any decent IDE will just pick up the language server automatically and you are ready to go.
8
u/dearonesama 3d ago
wanna invent new package manager? Now we've n+1 incompatible package managers.
8
u/RogerLeigh Scientific Imaging and Embedded Medical Diagnostics 2d ago
Because it's one of the key pain points of C++.
Did you read this essay yet? By /u/VinneFalco. Great summary and examples.
It really boils down to this: how hard and costly is it to develop an application in C++ vs other languages. In time, money and effort. The current answer is "very hard", and unless there's some compelling benefit to the pain and suffering, it makes a lot of sense to use a different language.
And it's not just about getting the libraries, it's also about how composable those libraries are once you've got them. Too many C++ libraries have completely disjoint and incompatible APIs. It's an extra source of pain having to try and glue them all together.
In a previous project, I wrote essentially a cross-platform CMake superbuild project which was in effect a mini vcpkg (before vcpkg existed). It used ExternalProject to fetch and build all of my organisation's dependencies on multiple platforms, just so we could start to use them. Months of effort, including all of the CI and testing and review, just to get to the point we can include and link with boost, libtiff, zlib, xerces and others. Compared with just using cargo. vcpkg helps, but only to a point.
I work with non-programmers who are currently using AI to write entire desktop applications using Rust and Tauri as well as other technologies. And they are good! Really good. Doing low-level control of external hardware devices, talking to AWS and other services using their APIs, 3D rendering, all sorts. To write and test the equivalent applications in C++ would be multi-man-year efforts to get to parity with something they managed to get together in a week. There's a huge gulf in capabilities here, and C++ is on the wrong side of it.
I still use C++ daily as a firmware engineer, but if I was to need to develop a GUI tool or application would I bother today? Likely not. I could use Rust+Tauri and have a working prototype before lunchtime.
I've used C++ for nearly 25 years now. It's never been the nicest language, but it was interesting and productive and let you do great things which other languages struggled with. But it's always had nasty pain points. It used to be worth using it because the benefits outweighed the pain. But I do feel that the equation has now changed. It's horribly painful and inefficient, and there are other languages out there which can do a better job with far less pain, and do it much more quickly and effectively.
Running a business, can I really justify using C++ except where it's strictly necessary? Not really. It has to make sense, and the cost:benefit no longer justifies it.
4
u/fortsnek274 3d ago
A CPS folder with CPS files. And they will name dependencies.
And hopefully, people don't have to do that just to use a lib. But it's necessary to handle things specially now because lib sources do not have a standardised format. Unless it's a simple CMake flow.
You just need to wave a magical wand to get all libraries everywhere to follow a standardised source package/repository format. That would be a step to solve dependency management. Package managers wouldn't need "recipes" anymore. Of course, this is the hard part.
And then you could have just a little bit of centralisation to map package names to source URLs. Then, at least it doesn't need much maintenance. Don't need to wait for version updates. Binaries cache optional.
3
u/ts826848 2d ago
Mind elaborating on what that model is for those of us who aren't in the loop?
Would you mind sharing instances of this happening in the Rust ecosystem? Can't say I've heard of SemVer (or Cargo's version thereof) causing scaling issues in the way the quote implies.
2
u/rileyrgham 3d ago
"Definitive" is a lofty ambition. Alas, failed 😁
11
u/steveklabnik1 2d ago
Just clearing up some misconceptions:
cargo vendorwill put the appropriate sources into your tree.Because each package has a manifest with a license, you do. There's tons of tooling for this. For example, you can set up a whitelist of licenses and then automatically check that all of your dependencies use them. https://embarkstudios.github.io/cargo-deny/checks/licenses/index.html
Break in what way?
You do have a local binary cache: it's in your
targetdirectory. There isn't a global cache, by default, but you can set one up.Rust's builds being slow has nothing to do with packages. Well, if anything, more packages makes the build faster, since crates are Rust's compilation unit. There is incremental builds within a crate but the fastest incremental build is no incremental build.
In what way?
You'll want to read up on https://www.reddit.com/r/cpp/comments/1hgpz0y/wg21_aka_c_standard_committee_december_2024/m2lt4tn/
23
u/Goldy-kun 3d ago
I can't really understand how could this cope continues for so many years despite seeing how most of your concerns either don't really matter or don't happen outright with every other system which solves these problems.
We have had package managers for years, tool chains built either into frameworks or the languages themselves for years. There is nothing out there that you could see to change your mind.
But to be fair the biggest saving grace C++ has is that in a few years we will probably treat our "code" as we tried compiled binaries so the DX, maintainability and other massive issues it has will not matter but at the same time realize that if we reach that point, I don't think LLMs will like C++ over Rust and if Rust proves capable of doing the same or better, C++ will be done.
Of course you could continue to cope about "decentralized solutions" which means no solution at all because you want someone else to do it in a way that you don't want anything to do with it and it doesn't affect you at all or someone could finally take the reins and actually build the solutions that have already been proven time and time again on nearly anything else being built out there today.
There is a point where you have to just realize that what C++ is doing today is not reasonable and has no future. I personally don't care about Rust, I don't think it's a magic button that solves most of the bigger issues out there but I can't possibly say they haven't fixed the same things C++ has had issues for years and also delivered on something else, making it more approachable for non-system people to the point that today Laravel, a web php framework, wants to move to Rust. Do you think there would be a world where they would have wanted to move to C++? Not in a million years.
2
u/UndefinedDefined 2d ago
I think honestly that C++ is suffering because of package management and standardized build system (standardized not in terms of ISO, just something 99.9% people would use).
Instead of using third-party libraries, we are "standardizing" them so they can be in std, because of dependency nightmares. But this solution doesn't scale. C++ is getting more and more bloated, because a beginner doesn't know how to properly work with dependencies, so to make C++ beginner friendly it needs to bundle many libraries that could be external.
This is doing no good to C++. Look what the industry is using, it's not the built-in stuff, the built-in stuff is a baggage.
-1
u/halfflat 3d ago
I'm not going to praise Cargo, but I certainly can't defend CMake.