executable_path_finder

Function find_with_cargo_home

Source
pub fn find_with_cargo_home(exec: &str) -> Option<Utf8PathBuf>
Expand description

find_with_cargo_home return a PathBuf for the given executable, it tries to find it in PATH, environment variables and CARGO_HOME.

The current implementation checks three places for an executable to use:

  1. $PATH/<executable_name> example: for cargo, this tries all paths in $PATH with appended cargo, returning the first that exists
  2. Appropriate environment variable (erroring if this is set but not a usable executable) example: for cargo, this checks $CARGO environment variable; for rustc, $RUSTC; etc
  3. $CARGO_HOME/bin/<executable_name> where $CARGO_HOME defaults to ~/.cargo (see https://doc.rust-lang.org/cargo/guide/cargo-home.html) example: for cargo, this tries $CARGO_HOME/bin/cargo, or ~/.cargo/bin/cargo if $CARGO_HOME is unset. It seems that this is a reasonable place to try for cargo, rustc, and rustup