executable-path 1.0.1

Get the path of a binary target's executable
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use std::{env, path::PathBuf};

/// Takes the name of a binary target and returns the path to the target's executable.
pub fn executable_path(name: &str) -> PathBuf {
  if let Some(value) = env::var_os(format!("CARGO_BIN_EXE_{}", name)) {
    return value.into();
  }

  let mut path = env::current_exe().unwrap();
  path.pop();
  if path.ends_with("deps") {
    path.pop();
  }
  let exe = String::from(name) + env::consts::EXE_SUFFIX;
  path.push(exe);
  path
}