Touch up PR 1275
diff --git a/build.rs b/build.rs
index 7f951de..afcfea3 100644
--- a/build.rs
+++ b/build.rs
@@ -3,13 +3,11 @@
use std::process::Command;
fn main() {
- let cc_path = if let Some(manifest_dir) = env::var_os("CARGO_MANIFEST_DIR") {
- PathBuf::from(manifest_dir).join("src").join("cxx.cc")
- } else {
- PathBuf::from("src/cxx.cc")
- };
+ let manifest_dir_opt = env::var_os("CARGO_MANIFEST_DIR").map(PathBuf::from);
+ let manifest_dir = manifest_dir_opt.as_deref().unwrap_or(Path::new(""));
+
cc::Build::new()
- .file(&cc_path)
+ .file(manifest_dir.join("src/cxx.cc"))
.cpp(true)
.cpp_link_stdlib(None) // linked via link-cplusplus crate
.flag_if_supported(cxxbridge_flags::STD)
@@ -20,8 +18,8 @@
println!("cargo:rerun-if-changed=include/cxx.h");
println!("cargo:rustc-cfg=built_with_cargo");
- if let Some(manifest_dir) = env::var_os("CARGO_MANIFEST_DIR") {
- let cxx_h = Path::new(&manifest_dir).join("include").join("cxx.h");
+ if let Some(manifest_dir) = &manifest_dir_opt {
+ let cxx_h = manifest_dir.join("include").join("cxx.h");
println!("cargo:HEADER={}", cxx_h.to_string_lossy());
}