Skip to content

Commit

Permalink
add cargo env workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
MabezDev committed Sep 18, 2024
1 parent 413b67b commit 239c379
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions esp-config/src/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ pub fn generate_config(
// only rebuild if build.rs changed. Otherwise Cargo will rebuild if any
// other file changed.
println!("cargo:rerun-if-changed=build.rs");
#[cfg(not(test))]
env_change_work_around();

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

// A work-around for https://github.com/rust-lang/cargo/issues/10358
// This can be removed when https://github.com/rust-lang/cargo/pull/14058 is merged.
// Unlikely to work on projects in workspaces
#[cfg(not(test))]
fn env_change_work_around() {
let mut out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());

// We clean out_dir by removing all trailing directories, until it ends with
// target
while !out_dir.ends_with("target") {
if !out_dir.pop() {
// We ran out of directories...
return;
}
}
out_dir.pop();

let dotcargo = out_dir.join(".cargo/");
if dotcargo.exists() {
println!(
"cargo:rerun-if-changed={}",
dotcargo.clone().join("config.toml").to_str().unwrap()
);
println!(
"cargo:rerun-if-changed={}",
dotcargo.clone().join("config").to_str().unwrap()
);
}
}

fn emit_configuration(
prefix: &str,
configs: &HashMap<String, Value>,
Expand Down

0 comments on commit 239c379

Please sign in to comment.