What is the difference between binaries in ~/.rustup vs ~/.cargo?
Asked Answered
S

1

9

I just installed Rust with rustup on MacOS and noticed that there are two rustc and two cargo binaries:

  • ~/.cargo/bin/rustc (cargo)
  • ~/.rustup/toolchains/stable-x86_64-apple-darwin/bin/rustc (cargo)

Their versions are exactly the same, but diff shows there exists some difference. So why are there two different rustc (cargo) binaries and which one should I use?

Scotia answered 30/1, 2017 at 23:24 Comment(0)
C
13

The reason there are two files named rustc is because rustup is a toolchain multiplexer. It lets you install many versions of Rust and easily switch between them.

The binary installed at ~/.cargo/bin/rustc proxies to the current toolchain that you have selected. Each installed compiler is kept under the toolchains directory.

Although the compiler in the toolchains directory appears to be a smaller file, that's only because it's dynamically linked instead of statically linked.

More information can be found on rustup's README.

Crutchfield answered 31/1, 2017 at 1:12 Comment(5)
So the binaries in .cargo are basically proxies to the current toolchain, right?Scotia
@ZizhengTai Yes, exactly.Crutchfield
@squiguy: You might want to expand your answer to explain why the files are different.Kanchenjunga
@MatthieuM. Done. Feel free to edit my answer(s) in the future.Crutchfield
@ZizhengTai to clarify, the cargo, rust-gdb, rust-lldb, rustc, rustdoc, and rustup binaries in .cargo/bin/ are all the same file. The first 5 all proxy to the relevant toolchain file.Gas

© 2022 - 2024 — McMap. All rights reserved.