Skip to content

Commit 239c379

Browse files
committed
add cargo env workaround
1 parent 413b67b commit 239c379

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

esp-config/src/generate.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ 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+
#[cfg(not(test))]
80+
env_change_work_around();
7981

8082
// ensure that the prefix is `SCREAMING_SNAKE_CASE`
8183
let prefix = format!("{}_", screaming_snake_case(prefix));
@@ -94,6 +96,36 @@ pub fn generate_config(
9496
configs
9597
}
9698

99+
// A work-around for https://github.com/rust-lang/cargo/issues/10358
100+
// This can be removed when https://github.com/rust-lang/cargo/pull/14058 is merged.
101+
// Unlikely to work on projects in workspaces
102+
#[cfg(not(test))]
103+
fn env_change_work_around() {
104+
let mut out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());
105+
106+
// We clean out_dir by removing all trailing directories, until it ends with
107+
// target
108+
while !out_dir.ends_with("target") {
109+
if !out_dir.pop() {
110+
// We ran out of directories...
111+
return;
112+
}
113+
}
114+
out_dir.pop();
115+
116+
let dotcargo = out_dir.join(".cargo/");
117+
if dotcargo.exists() {
118+
println!(
119+
"cargo:rerun-if-changed={}",
120+
dotcargo.clone().join("config.toml").to_str().unwrap()
121+
);
122+
println!(
123+
"cargo:rerun-if-changed={}",
124+
dotcargo.clone().join("config").to_str().unwrap()
125+
);
126+
}
127+
}
128+
97129
fn emit_configuration(
98130
prefix: &str,
99131
configs: &HashMap<String, Value>,

0 commit comments

Comments
 (0)