File tree Expand file tree Collapse file tree 1 file changed +10
-11
lines changed
Expand file tree Collapse file tree 1 file changed +10
-11
lines changed Original file line number Diff line number Diff line change @@ -5,22 +5,21 @@ use std::path::PathBuf;
55use std:: process:: Command ;
66
77fn bin_path ( ) -> PathBuf {
8- // Prefer Cargo-provided env var for the built binary
8+ // Prefer Cargo-provided env var for the built binary. This is the most reliable.
99 if let Ok ( p) = env:: var ( "CARGO_BIN_EXE_reasonable" ) {
1010 return PathBuf :: from ( p) ;
1111 }
12- // Fallback: derive workspace `target` from manifest dir (robust in workspaces)
13- let target_dir = env:: var ( "CARGO_TARGET_DIR" ) . ok ( ) . map ( PathBuf :: from) . unwrap_or_else ( || {
14- // `CARGO_MANIFEST_DIR` points to the `cli/` crate; workspace root is one level up
15- let manifest_dir = PathBuf :: from ( env ! ( "CARGO_MANIFEST_DIR" ) ) ;
16- manifest_dir. parent ( ) . unwrap_or ( & manifest_dir) . join ( "target" )
17- } ) ;
18- let mut p = target_dir;
19- p. push ( "debug" ) ;
20- p. push ( "reasonable" ) ;
12+
13+ // Inspired by similar projects: derive target dir from the crate location and
14+ // probe debug then release (with Windows .exe suffix when applicable).
15+ let base = PathBuf :: from ( env ! ( "CARGO_MANIFEST_DIR" ) ) . join ( ".." ) . join ( "target" ) ;
16+ let exe = if cfg ! ( windows) { "reasonable.exe" } else { "reasonable" } ;
17+
18+ let mut p = base. join ( "debug" ) . join ( exe) ;
2119 if !p. exists ( ) {
22- panic ! ( "could not locate CLI binary at {}" , p . display ( ) ) ;
20+ p = base . join ( "release" ) . join ( exe ) ;
2321 }
22+ assert ! ( p. exists( ) , "reasonable binary not found at {:?}" , p) ;
2423 p
2524}
2625
You can’t perform that action at this time.
0 commit comments