diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 815c774e..a22afa64 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -507,7 +507,7 @@ jobs: if: runner.target == 'x86_64-pc-windows-gnu' run: | sudo apt install g++-mingw-w64-x86-64 gcc-mingw-w64-x86-64 - - name: "Build" + - name: "Check" uses: actions-rs/cargo@v1 with: use-cross: true diff --git a/apis/c++/node/build.rs b/apis/c++/node/build.rs index 6ca8f623..05ebfd50 100644 --- a/apis/c++/node/build.rs +++ b/apis/c++/node/build.rs @@ -9,10 +9,7 @@ fn main() { println!("cargo:rerun-if-changed=src/lib.rs"); // rename header files - let src_dir = target_dir() - .join("cxxbridge") - .join("dora-node-api-cxx") - .join("src"); + let src_dir = origin_dir(); let target_dir = src_dir.parent().unwrap(); std::fs::copy(src_dir.join("lib.rs.h"), target_dir.join("dora-node-api.h")).unwrap(); std::fs::copy( @@ -28,8 +25,8 @@ fn main() { bridge_files.clear(); } -fn target_dir() -> PathBuf { - std::env::var("CARGO_TARGET_DIR") +fn origin_dir() -> PathBuf { + let default_target = std::env::var("CARGO_TARGET_DIR") .map(PathBuf::from) .unwrap_or_else(|_| { let root = Path::new(env!("CARGO_MANIFEST_DIR")) @@ -37,7 +34,22 @@ fn target_dir() -> PathBuf { .nth(3) .unwrap(); root.join("target") - }) + }); + let cross_target = default_target + .join(std::env::var("TARGET").unwrap()) + .join("cxxbridge") + .join("dora-node-api-cxx") + .join("src"); + let target_dir = if cross_target.exists() { + cross_target + } else { + default_target + .join("cxxbridge") + .join("dora-node-api-cxx") + .join("src") + }; + + target_dir } #[cfg(feature = "ros2-bridge")] @@ -113,7 +125,7 @@ mod ros2 { .join("ros2_bindings.rs.cc"); // copy message files to target directory - let target_path = target_dir() + let target_path = origin_dir() .join("cxxbridge") .join("dora-node-api-cxx") .join("dora-ros2-bindings.h");