Skip to content

Commit 5597c96

Browse files
committed
devices: work with proper paths in build script
We shouldn't stringify paths, because not all paths are valid UTF-8 strings, meaning we could fail operations spuriously. Work with proper Rust paths to not run into such issues. Signed-off-by: Daniel Müller <deso@posteo.net>
1 parent de22b0d commit 5597c96

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

src/devices/build.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
use std::path::PathBuf;
2+
13
fn main() {
2-
let init_binary_path = std::env::var("KRUN_INIT_BINARY_PATH").unwrap_or_else(|_| {
3-
format!(
4-
"{}/../../init/init",
5-
std::env::var("CARGO_MANIFEST_DIR").unwrap()
6-
)
7-
});
8-
println!("cargo:rustc-env=KRUN_INIT_BINARY_PATH={init_binary_path}");
4+
let init_binary_path = std::env::var_os("KRUN_INIT_BINARY_PATH")
5+
.map(PathBuf::from)
6+
.unwrap_or_else(|| {
7+
let manifest_dir = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap());
8+
manifest_dir.join("../../init/init")
9+
});
10+
println!(
11+
"cargo:rustc-env=KRUN_INIT_BINARY_PATH={}",
12+
init_binary_path.display()
13+
);
914
println!("cargo:rerun-if-env-changed=KRUN_INIT_BINARY_PATH");
1015
}

0 commit comments

Comments
 (0)