@@ -76,6 +76,7 @@ pub fn generate_config(
7676 // only rebuild if build.rs changed. Otherwise Cargo will rebuild if any
7777 // other file changed.
7878 println ! ( "cargo:rerun-if-changed=build.rs" ) ;
79+ env_change_work_around ( ) ;
7980
8081 // ensure that the prefix is `SCREAMING_SNAKE_CASE`
8182 let prefix = format ! ( "{}_" , screaming_snake_case( prefix) ) ;
@@ -94,6 +95,35 @@ pub fn generate_config(
9495 configs
9596}
9697
98+ // A work-around for https://github.com/rust-lang/cargo/issues/10358
99+ // This can be removed when https://github.com/rust-lang/cargo/pull/14058 is merged.
100+ // Unlikely to work on projects in workspaces
101+ fn env_change_work_around ( ) {
102+ let mut out_dir = PathBuf :: from ( env:: var_os ( "OUT_DIR" ) . unwrap ( ) ) ;
103+
104+ // We clean out_dir by removing all trailing directories, until it ends with
105+ // target
106+ while !out_dir. ends_with ( "target" ) {
107+ if !out_dir. pop ( ) {
108+ // We ran out of directories...
109+ return ;
110+ }
111+ }
112+ out_dir. pop ( ) ;
113+
114+ let dotcargo = out_dir. join ( ".cargo/" ) ;
115+ if dotcargo. exists ( ) {
116+ println ! (
117+ "cargo:rerun-if-changed={}" ,
118+ dotcargo. clone( ) . join( "config.toml" ) . to_str( ) . unwrap( )
119+ ) ;
120+ println ! (
121+ "cargo:rerun-if-changed={}" ,
122+ dotcargo. clone( ) . join( "config" ) . to_str( ) . unwrap( )
123+ ) ;
124+ }
125+ }
126+
97127fn emit_configuration (
98128 prefix : & str ,
99129 configs : & HashMap < String , Value > ,
0 commit comments