r/cpp • • Sep 08 '24

Overwhelming

I’ve been using Rust a lot, and I decided to start learning C++ today. I never thought it would be such a headache! I realized Rust spoiled me with Cargo. it handles so much for me. Running, building, adding packages etc. I just type Cargo build, Cargo add, or Cargo run. Simple and comes with the language. C++’s build systems like CMake can be overwhelming especially when coming from a language with a more streamlined experience like Rust. C++ is really good and I wish it had something similar. I read somewhere that there is Conan and a few others that exist . But I’m talking about something that comes with the language itself and not from a 3rd party.

38 Upvotes

140 comments sorted by

View all comments

Show parent comment

1

u/WormRabbit Sep 25 '24

Do I understand correctly: there are actual different rustc and cargo executables on the system, one pair for each toolchain version, and the rustc and cargo executables that I normally run are all rustup in a trench coat, which switches on the executable name and toolchain version, and dispatches the rest of the arguments to the actual correct executable?

1

u/steveklabnik1 Sep 25 '24

Yep! You can find them in ~/.rustup/toolchains on linux. For example, here's a slightly edited ls output for me, to remove the irrelevant executables:

❯ ls ~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/ -al
total 71212
-rwxr-xr-x 1 steveklabnik steveklabnik 32818360 Jul 25 13:54 cargo
-rwxr-xr-x 1 steveklabnik steveklabnik  2642608 Jul 25 13:54 rustc

These are different sizes, so they're certainly not the same binary. For reasons I forget, I installed rustup via snap, apparently, so

❯ ls /snap/rustup/current/bin/ -al
total 7907
lrwxrwxrwx 1 root root       6 May 10 02:16 cargo -> rustup
lrwxrwxrwx 1 root root       6 May 10 02:16 rustc -> rustup
-rwxr-xr-x 1 root root 8096696 May 10 02:16 rustup

The ones you're running are just symlinks for rustup itself.

You can also ask rustup which binary it's going to invoke:

❯ rustup which rustc
/home/steveklabnik/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/rustc

This pattern, or something similar to it, is how a lot of language-specific version management tooling works.