@@ -23,19 +23,29 @@ fn main() {
23
23
let out_dir = env:: var ( "OUT_DIR" ) . unwrap ( ) ;
24
24
let mut target_dir = Path :: new ( & out_dir) ;
25
25
26
- // Depending on how this is util is built, the directory structure. This seems to work for now.
27
- // Here are three cases to test when changing this:
26
+ // Depending on how this is util is built, the directory structure changes.
27
+ // This seems to work for now. Here are three cases to test when changing
28
+ // this:
29
+ //
28
30
// - cargo run
29
31
// - cross run
30
32
// - cargo install --git
31
33
// - cargo publish --dry-run
34
+ //
35
+ // The goal is to find the directory in which we are installing, but that
36
+ // depends on the build method, which is annoying. Additionally the env
37
+ // var for the profile can only be "debug" or "release", not a custom
38
+ // profile name, so we have to use the name of the directory within target
39
+ // as the profile name.
32
40
let mut name = target_dir. file_name ( ) . unwrap ( ) . to_string_lossy ( ) ;
41
+ let mut profile_name = name. clone ( ) ;
33
42
while name != "target" && !name. starts_with ( "cargo-install" ) {
34
43
target_dir = target_dir. parent ( ) . unwrap ( ) ;
44
+ profile_name = name. clone ( ) ;
35
45
name = target_dir. file_name ( ) . unwrap ( ) . to_string_lossy ( ) ;
36
46
}
37
47
let mut dir = target_dir. to_path_buf ( ) ;
38
- dir. push ( env :: var ( "PROFILE" ) . unwrap ( ) ) ;
48
+ dir. push ( profile_name . as_ref ( ) ) ;
39
49
dir. push ( "deps" ) ;
40
50
let mut path = None ;
41
51
0 commit comments