executable_path/lib.rs
1use std::{env, path::PathBuf};
2
3/// Takes the name of a binary target and returns the path to the target's executable.
4pub fn executable_path(name: &str) -> PathBuf {
5 if let Some(value) = env::var_os(format!("CARGO_BIN_EXE_{}", name)) {
6 return value.into();
7 }
8
9 let mut path = env::current_exe().unwrap();
10 path.pop();
11 if path.ends_with("deps") {
12 path.pop();
13 }
14 let exe = String::from(name) + env::consts::EXE_SUFFIX;
15 path.push(exe);
16 path
17}