Skip to content

Commit

Permalink
Fix: Respect CARGO_TARGET_DIR if set
Browse files Browse the repository at this point in the history
  • Loading branch information
phil-opp committed Feb 14, 2024
1 parent 2f43534 commit 18044f6
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions apis/c++/node/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@ fn main() {
println!("cargo:rerun-if-changed=src/lib.rs");

// rename header files
let root = Path::new(env!("CARGO_MANIFEST_DIR"))
.ancestors()
.nth(3)
.unwrap();
let src_dir = root
.join("target")
let src_dir = target_dir()
.join("cxxbridge")
.join("dora-node-api-cxx")
.join("src");
Expand All @@ -38,6 +33,18 @@ fn main() {
bridge_files.clear();
}

fn target_dir() -> PathBuf {
std::env::var("CARGO_TARGET_DIR")
.map(PathBuf::from)
.unwrap_or_else(|_| {
let root = Path::new(env!("CARGO_MANIFEST_DIR"))
.ancestors()
.nth(3)
.unwrap();
root.join("target")
})
}

#[cfg(feature = "ros2-bridge")]
mod ros2 {
use std::path::{Component, Path, PathBuf};
Expand Down Expand Up @@ -107,12 +114,7 @@ mod ros2 {
.join("ros2_bindings.rs.cc");

// copy message files to target directory
let root = Path::new(env!("CARGO_MANIFEST_DIR"))
.ancestors()
.nth(3)
.unwrap();
let target_path = root
.join("target")
let target_path = target_dir()
.join("cxxbridge")
.join("dora-node-api-cxx")
.join("dora-ros2-bindings.h");
Expand Down

0 comments on commit 18044f6

Please sign in to comment.