r/cpp • • 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.

0 Upvotes

55 comments sorted by

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?

-9

u/TheRavagerSw 3d ago

How so, I haven't seen a single post in a year that argue for local package registries.

9

u/altmly 3d ago

Because you didn't bring any arguments? 

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.

-4

u/TheRavagerSw 2d ago

It is not superior. Everything you listed is critical and must be known by the developer. I listed many other reasons in the post too, but you haven't read them.

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.

1

u/TheRavagerSw 2d ago

Because any app you compile depends on stdlib, no knowing that could cause runtime or compilation errors.

Bugs happen, sometimes Xcode beta sdk breaks your app, so you have to downgrade etc, or ucrt team makes something inline static.

6

u/t_hunger 2d ago

Why would it? Its all statically linked and self contained. You take the binary and put it anywhere and it runs fine.

0

u/TheRavagerSw 2d ago

Not everything is statically linked, glibc for example.

4

u/t_hunger 2d ago edited 2d ago

True, glibc tends to be "whatever version used during built or newer". Not much of a problem in practice, but it can be an issue. Same solution as with C++ works with rust as well: Build on an old distribution (the stdlib packages do that for all I can tell... and other code typically does not depend on glibc) or use the musl target of the compiler and have a binary that runs in an empty container:-)

That's literally one rustup command to install the target and one flag to cargo.

5

u/steveklabnik1 2d ago

How else can you guarantee that the sources for each published version does not vanish from the internet?

This is the primary reason crates.io exists. Depending on repository upstreams means they can go away at any time.

8

u/dearonesama 3d ago

wanna invent new package manager? Now we've n+1 incompatible package managers.

0

u/TheRavagerSw 2d ago

Any new tool is useless without a collaboration group. I also don't have everything figured out to write one. I still can't decide if compiler should be a binary package for example. Because other tools are packages, such as glslang compiler.

3

u/delta_p_delta_x 2d ago

without a collaboration group

EcoStd was rejected by WG21 (seemingly in favour of contracts). There is a group of dedicated people interested in solidifying the C++ ecosystem, but the WG doesn't seem to care about anything but the language and standard library specifications; realities of implementations be damned.

2

u/TheRavagerSw 2d ago

Well, I hope to create a private group myself and grow it if my career allows it. I'm just not ready for it yet.

Still, sad situation

4

u/grafikrobot OPeNDAP/B2/EcoStd/Lyra/Predef/C++Alliance/Boost/WG21 2d ago

We already have a public group working on build and packaging *external* to wg21/iso. Maybe you could contribute there. Instead of more fractured efforts. We certainly need the help given the eternal lackluster investments in language tooling.

5

u/grafikrobot OPeNDAP/B2/EcoStd/Lyra/Predef/C++Alliance/Boost/WG21 2d ago

EcoStd was rejected by WG21 (seemingly in favour of contracts).

I'm guessing "contracts" is a typo. Because, no, that was not the case (as the author of what you linked to).

5

u/Minimonium 2d ago

seemingly in favour of contracts

What non-sense is it? The eco papers were dropped by the "leadership" out of the schedule to merely talk more shit about safe keywords (during Safe C++ vs "profiles" shitfest) and what not. It had nothing to do with Contracts.

8

u/RogerLeigh Scientific Imaging and Embedded Medical Diagnostics 2d ago

I don’t see why everyone is so obsessed about it.

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.

0

u/TheRavagerSw 2d ago

I read that post before it got removed.

The problem is cargo's approach is flawed. No matter how easy it is. It only looks convenient on the surface, the moment you try to do something else, it shows.

It is a language package manager, which means cross language projects are near impossible to do. It doesn't have the subtle improvements that make the difference, for example does rust have a notion of "compile dependencies with 02 debuginfo and compile the main project with full debug"?

What about binary dependencies like glslang, you can write cmake scripts that output a binary package, and it includes tools like that.

What about libraries that build tools to build themselves?

4

u/t_hunger 2d ago edited 2d ago

It is a language package manager, which means cross language projects are near impossible to do.

Like the thousand of C libraries on crates.io?

It doesn't have the subtle improvements that make the difference, for example does rust have a notion of "compile dependencies with 02 debuginfo and compile the main project with full debug"?

That one is indeed super inconvenient: Thats two lines you need to add. Same to patch any source you are using :-)

What about libraries that build tools to build themselves?

You mean like the cc or cmake crates used to build C/C++ code straight with a compiler or cmake? Yes, it's way less convenient than to use rust code with cargo, but it certainly can be done.

A bit of friction when you use another language is not bad IMHO: It provides an incentive to replace the crate with something native to make the build easier:-) C dependencies are such a pain to cross-compile: You need to install the right compilers, make sure they are found and all that.

2

u/TheRavagerSw 2d ago

Do you know which flags are used to compile those C libraries?

Please elaborate on two lines

Of course, just rewrite everything in rust argument.

3

u/t_hunger 2d ago
[profile.dev.package."*"]
debug = false

makes all dependencies use release builds. Use the crate name instead of * to set it for a specific dependency.

-1

u/TheRavagerSw 2d ago

do dependencies have debug info?
msan? what about C or C++ libraries compiled by cargo?

3

u/t_hunger 2d ago

C dependencies tend to follow the debug/release switch of cargo as far as that can be mapped over easily. Why would I need msan? If safety was important, I'd use a native dependency. When a unsafe dependency is fine and I know the rust wrapper will not let me pass broken inputs to the library, then msan is not really helpful. I am not even sure how well that will work with an FFI boundary in the way.

1

u/t_hunger 2d ago

Do you know which flags are used to compile those C libraries?

Those needed to make them work with the crate ecosystem. I never had a reason to check any of the sys crates yet.

0

u/TheRavagerSw 2d ago

Well they matter a lot, it just works isn't a responsible statement

4

u/t_hunger 2d ago

What for? Cargo features configure what gets enabled and what not. Cargo makes sure the binary will work with my target architecture and that dependencies have the right flags set to work.

These flags do matter a lot when you have to fiddle them into a build system yourself. Even on C++ most flags are hidden when you can use a properly built CMake dependency in a CMake project.

4

u/steveklabnik1 2d ago

Do you know which flags are used to compile those C libraries?

https://doc.rust-lang.org/cargo/reference/build-script-examples.html#building-a-native-library and similar stuff on that page

Please elaborate on two lines

https://doc.rust-lang.org/cargo/reference/profiles.html#overrides

7

u/t_hunger 2d ago edited 2d ago

The problem is cargo's approach is flawed. No matter how easy it is. It only looks convenient on the surface, the moment you try to do something else, it shows.

You did stumble on a point here: Cargo is easy because the rust community has strong conventions in place that almost everybody follows. Nobody tries to do random things, using random tools. The limitations cargo has are well known and people tend to design their stuff to play to its strength.

Contrast that to C++, where no project shares conventions with any other project as a matter of pride. Everybody used a combination of different tools. Some have home grown documentation systems or necesary preprocessing steps. You need super flexible build tools, with thousands of knobs to tune them, so that different projects can use them anyway. Any project will need to tweak many of those flags to make it work somehow for their little corner of the world.

Good tooling is a social issue more than a technical one IMHO. People would need to compromise and invest effort to a change to a common system for the greater good -- and redesign parts of their approaches on how to consume, build and expose libraries, incl. best practices on how to document code etc.

I just can not see that happen. Cargo only works because it has been there before a critical mass of developers were using rust.

1

u/Minimonium 2d ago

It sounds like you simply want Conan, because Conan can do that. Also I heard about folks who were doing multi-language projects in Conan (including invoking Cargo from it).

3

u/TheRavagerSw 2d ago

I already use it

2

u/Bart_V 2d ago

https://old.reddit.com/r/cpp/comments/1y9x3pm/c_needs_to_catch_up_and_fast/

Deleting that post is insane. It's a well written essay (probably with AI, but who doesn't these days) on an important topic, well thought off and with plenty of references and data points. The resulting discussion was interesting and civilized. Why shut that down? This community...

3

u/fortsnek274 2d ago

Maybe next time, the author will just put his words out as-is rather than generating them. Then I might read it.

2

u/draeand 1d ago

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.

You do know that a package manager is not magically going to solve this? And frankly, I see the decentralization of C++ as a net positive. Sure, having something like Cargo is an advantage... Until you get a supply-chain attack and since your program depends on 1000 plus other libraries, which have their own transitive dependencies, all the way down, you'll have a really hard time solving that problem. I know of a Rust-built app that has well over 800 different crates. Just to build that app. Can you imagine a C++ app needing 800 packages from vcpkg? Because I have never, once, needed that many vcpkg packages to develop, well, anything.

1

u/t_hunger 1d ago

Yet cargo has one huge advantage wrt. supply chain attacks: You have visibility into the entire dependency chain and a simple way to update all dependencies when needed.

That's not the case in many C++ projects. You typically know what you vendored, but what did those vendor? Add header-only libraries that get dumped somewhere into the source tree (yours or your dependencies) and copy and pasted snippets where its not worth adding a full dependency. E.g. I ran into zlib compress/decompress in several versions in all codebases > 1M lines. Sometimes devs are clever, they rename the symbols to avoid things breaking when users link against zlib... making it hard to find these. How do you update any of these? Will you even know you need to update something?

4

u/fortsnek274 3d ago

such as a binary package format.

A CPS folder with CPS files. And they will name dependencies.

and write package recipes for them

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.

2

u/TheRavagerSw 2d ago

There could be some sort of organizations that could maintain a registry, but it could only be used to fork it to an organisation.

You can't do that without recipes because there are multiple build systems and multiple languages and multiple tools. Many people don't realise, we also use tools in form of packages, ICU Wayland scanner Qt moc etc.

1

u/fortsnek274 2d ago

Yes, hence, the magic wand. But CPS does list executables too. And if you had a magical Standardised Source Package format, there would be some standardised way of acquiring other tooling. Which would be described by a standardised recipe format.

Maybe it could be similar to conan's way of grabbing source packages directly from git. It would expect a conan file.

3

u/ts826848 2d ago

unlike a sane dependency model as proposed by Titus Winters

Mind elaborating on what that model is for those of us who aren't in the loop?

This means your dependency tree will not scale and will be hard to maintain.

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/TheRavagerSw 2d ago

Titus winters proposed "live at the head" for managing dependencies in C++. You can check out the talk here https://youtu.be/tISy7EJQPzI.

The talk explains the issues in detail.

0

u/ts826848 2d ago

I see, I'll have to find time to listen to that at some point. Did a brief search as well; do the contents of this article by Titus match that of the talk?

2

u/rileyrgham 3d ago

"Definitive" is a lofty ambition. Alas, failed 😁

-3

u/TheRavagerSw 3d ago

I agree

11

u/steveklabnik1 2d ago

Just clearing up some misconceptions:

you don’t own sources,

cargo vendor will put the appropriate sources into your tree.

you don’t know about licenses.

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

If one of your packages break, trying to fix it is very annoying

Break in what way?

Also builds are very slow, since you don’t have local binary cache for packages.

You do have a local binary cache: it's in your target directory. 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.

Cargo relies on semver. This means your dependency tree will not scale and will be hard to maintain.

In what way?

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.

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.

5

u/UndefFox 2d ago

It would be nice to see those who experience the limitations of the system to participate in such discussions rather than general folks. Not much can be obtained with 100s "It works for me"/ Otherwise it creates polarised consensus in the comments.

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++?

Doubt it's because of language, and rather the fact C++ afaik doesn't have ecosystem for web dev stuff, unlike Rust that got a few during it's hype pandemic/

1

u/steveklabnik1 2d ago

Doubt it's because of language, and rather the fact C++ afaik doesn't have ecosystem for web dev stuff, unlike Rust that got a few during it's hype pandemic/

The creator posted this today: https://x.com/taylorotwell/status/2128190652580352275

When I decided that I would bring Laravel to another language, Rust and Go were the two obvious choices. Both are extremely fast, type-safe, compiled languages. In the AI age, why not write in very fast, type-safe, compiled languages?

Rust and Go were the two ecosystems where I felt I could contribute something unique that didn't quite exist yet. Unlike TypeScript, where well-established frameworks and communities have already been built, Go is one of the most widely deployed backend languages in the world, yet it hasn't had a definitive batteries-included, full-stack framework that also pairs cleanly with a modern frontend via Inertia and React / Vue. I hope the community finds this worthy to fill that gap.

He didn't explicitly say that C++ was not considered for any specific reason, just that Rust and Go were 'obvious'.

4

u/UndefFox 1d ago

...yet it hasn't had a definitive batteries-included, full-stack framework that also pairs cleanly with a modern frontend via Inertia and React / Vue.

I would say this one was more of a deciding factor. I don't think C++ has any such well established and batteries-included framework, let alone full-stack one...

0

u/steveklabnik1 1d ago

You read this one backwards. They built one (Laravel) because Go does not have one yet. Not having one is the reason it was chosen, not the reason to not choose it.

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.

1

u/TheRavagerSw 2d ago

It is just a build system, very replacable, unlike cargo.

1

u/steveklabnik1 2d ago

You can absolutely replace Cargo if you want to. Meta does, using buck, for example. The Rust kernel uses their own build system.

Cargo and rustc were developed separately specifically so that you can use a different build system if you like.

1

u/TheRavagerSw 2d ago

Well I have nothing against rust language, just cargo and rustup.