TIL how `+toolchain` works under the hood and it's pretty cool

202 points syskall

It turns out that cargo, rustc, rustup, etc. are all the exact same binary.

$ cd ~/.cargo/bin/
$ md5 cargo rustc rustup rustdoc rustfmt
MD5 (cargo) = 7d21dd2cbc12746d06a93f4e210b294c
MD5 (rustc) = 7d21dd2cbc12746d06a93f4e210b294c
MD5 (rustup) = 7d21dd2cbc12746d06a93f4e210b294c
MD5 (rustdoc) = 7d21dd2cbc12746d06a93f4e210b294c
MD5 (rustfmt) = 7d21dd2cbc12746d06a93f4e210b294c

Yep, it's all just the rustup binary under the hood. it uses argv[0] (the executable's path), extracts its file name, and uses it to determine which binary to proxy to.

You can literally rm cargo; cp rustup cargo; and you got your cargo back :)

Anyways, I know many of you are familiar with that pattern but I thought it was pretty cool.