Why does all cargo binaries have the same hash?

When I compute the hash of the following binaries in my .cargo/bin directory I got the same hash for all of them:

cargo-clippy.exe
cargo-fmt.exe
cargo-miri.exe
cargo.exe
clippy-driver.exe
rls.exe
rust-analyzer.exe
rust-gdb.exe
rust-gdbgui.exe
rust-lldb.exe
rustc.exe
rustdoc.exe
rustfmt.exe
rustup.exe

I'm curious to know why it's done like this and how it can work if it's all the same binary.

These are called proxies by rustup, AFAIK:

rustup is a toolchain multiplexer. It installs and manages many Rust toolchains and presents them all through a single set of tools installed to ~/.cargo/bin. The rustc and cargo executables installed in ~/.cargo/bin are proxies that delegate to the real toolchain. rustup then provides mechanisms to easily change the active toolchain by reconfiguring the behavior of the proxies.

~ The Rustup Book

2 Likes

because they are actually same binary, which is rustup.

To clarify, rustup changes its behavior without changing its content at all by looking at the first command line argument, which is the executable's name.

2 Likes

Ouch. Those binaries aren't really small...
Using minimal binaries that call rustup with the right parameter would save a lot of space!

They are hard-linked so there is actually only one copy with many names.

2 Likes

They've recently been changed to symlinks.

2 Likes

Indeed, they are!

I'm really surprised; I thought those were notoriously tricky to manage on Windows. But that was some time ago.

Rustup first tries to symlink and if that fails it hardlinks. Symlinks work on Windows when dev mode is enabled, while hardlinks always work.

2 Likes