How do I find out the default rustc compiler version used by cargo?


As the title says, I’m trying to find the default rustc version used by cargo. One caveat is that I’ll be calling cargo from a directory that does not have a Cargo.toml (use-case: this is happening in a top-level configure script in a multi-language project) Any ideas?


I believe you can do ${RUSTC:-rustc} --version from the directory where the Cargo will be launched. By default Cargo just uses the rustc from $PATH, and this can be overridden with RUSTC environment variable.


Oh really? For some reason I thought that because cargo supported multiple compilers I’d have to ask it which compiler it was invoking. Does that mean that if I switch the default compiler to nightly it symlinks rustc to the directory that contains the nightly compiler?


Cargo just invokes rustc executable from PATH. Looks like you are using rustup, and it is rustup job to redirect rustc from PATH to the actual toolchain active in the current directory. It does not symlink anything. Instead, it installs itself as cargo and rustc (diff ~/.cargo/bin/cargo ~/.cargo/bin/rustc) and, when you run it, rustup looks at the command line to get the name of the tool and at the current directory to figure the correct override, and then execs the necessary tool from some particular toolchain.


Thank you so much @matklad!