I have ~/.cargo/bin on my PATH, and all was working out well until I decided to get code coverage stats. I followed the directions in: Instrumentation-based Code Coverage - The rustc book, switching toolchains from stable to nightly, and adding the llvm-tools component. However, ~/.cargo/bin doesn't have the llvm tools in it. Find shows that they're in ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin/.
Did I miss some step that updates ~/.cargo/bin? Or do I need to update my PATH with the long ~/.rustop/toolchains... path prefix? If the latter, then I guess I also need some scripting to make sure my PATH matches the toolchain I'm using properly.
If you're using cargo-llvm-cov you shouldn't need to put the llvm tools in your $PATH.
~/.cargo/bin is for tools installed with cargo install, not for toolchain stuff.
rustup actually already manages all of that. If you open the cargo executable in your $PATH in a text editor you'll see that is in fact a wrapper script.
rustup copies binaries from the ~/.rustup/toolchains/<toolchain>/bin directory to ~/.cargo/bin, but seemingly no binaries from the path you are describing. I for one have the rust-lld binary in the same location on my machine and it is not part of binaries in the Cargo home directory. If you need to invoke it manually, I'd either call it using the full path (if I had to do so infrequently enough) or add the directory to your $PATH. I assume due to the llvm-tools being unstable and in preview mode is why they aren't copied to the Cargo home. Here another post on Zulip on this (the whole thread discusses the component), with a command you can run to get the correct directory from rustc.
Another problem: the compatibility between nightly Rust (1.82.0) and LLVM. The cargo-llvm-cov README says I need LLVM 19-rc. I guess I will need to clone and build that. Unless there is a way to get Cargo to do that?
If I'm going to be switching back and forth between stable (for most development) and nightly (to do things like get code coverage), what is the best way to manage needing different LLVM versions for different Rust versions?
I thought LLVM itself was an external dependency not managed by cargo/rustup. Are you saying that it is managed by cargo/rustup, and that I will get whatever LLVM version I need when switching between stable and nightly?
Yes, you should not have to manage a llvm distribution for most of development with Rust. It should be an implementation detail from your point of view.
To be clear, technically those are not copies but a sort of “wrapper script”.
In fact, all of them are the same executable, and the same executable as rustup [it’s literally all one and the same file, via hard-links]; it dispatches based on file-name (try executing a renamed copy of your rustc from .cargo/bin). Having a wrapper is how overrides, or the +nightly-style syntax is supported. It delegates to the right binaries in the .rustup directory then.