[r2r_common] Move link search prints to print_cargo_link_search()

This commit is contained in:
aeon 2022-11-25 03:02:50 +08:00
parent c136d1400f
commit 55cce8caec
4 changed files with 27 additions and 14 deletions

View File

@ -3,6 +3,7 @@ use std::path::PathBuf;
fn main() {
r2r_common::print_cargo_watches();
r2r_common::print_cargo_link_search();
let mut builder = r2r_common::setup_bindgen_builder();
builder = builder.header("src/action_wrapper.h");

View File

@ -55,15 +55,6 @@ pub fn setup_bindgen_builder() -> bindgen::Builder {
println!("adding clang arg: {}", clang_arg);
builder = builder.clang_arg(clang_arg);
}
env::var("CMAKE_LIBRARIES")
.unwrap_or_default()
.split(':')
.into_iter()
.filter(|s| s.contains(".so") || s.contains(".dylib"))
.flat_map(|l| Path::new(l).parent().and_then(|p| p.to_str()))
.unique()
.for_each(|pp| println!("cargo:rustc-link-search=native={}", pp));
} else {
let ament_prefix_var_name = "AMENT_PREFIX_PATH";
let ament_prefix_var = env::var(ament_prefix_var_name).expect("Source your ROS!");
@ -114,17 +105,36 @@ pub fn setup_bindgen_builder() -> bindgen::Builder {
}
});
}
let lib_path = Path::new(p).join("lib");
if let Some(s) = lib_path.to_str() {
println!("cargo:rustc-link-search=native={}", s)
}
}
}
builder
}
pub fn print_cargo_link_search() {
if env::var("CMAKE_INCLUDE_DIRS").is_ok() {
if let Ok(paths) = env::var("CMAKE_LIBRARIES") {
paths
.split(':')
.into_iter()
.filter(|s| s.contains(".so") || s.contains(".dylib"))
.flat_map(|l| Path::new(l).parent().and_then(|p| p.to_str()))
.unique()
.for_each(|pp| println!("cargo:rustc-link-search=native={}", pp));
}
} else {
let ament_prefix_var_name = "AMENT_PREFIX_PATH";
if let Ok(paths) = env::var(ament_prefix_var_name) {
for path in paths.split(':') {
let lib_path = Path::new(path).join("lib");
if let Some(s) = lib_path.to_str() {
println!("cargo:rustc-link-search=native={}", s)
}
}
}
}
}
pub fn get_wanted_messages() -> Vec<RosMsg> {
let msgs = if let Ok(cmake_package_dirs) = env::var("CMAKE_IDL_PACKAGES") {
// CMAKE_PACKAGE_DIRS should be a (cmake) list of "cmake" dirs

View File

@ -7,6 +7,7 @@ use std::path::PathBuf;
fn main() {
r2r_common::print_cargo_watches();
r2r_common::print_cargo_link_search();
let mut builder = r2r_common::setup_bindgen_builder();

View File

@ -3,6 +3,7 @@ use std::path::PathBuf;
fn main() {
r2r_common::print_cargo_watches();
r2r_common::print_cargo_link_search();
let mut builder = r2r_common::setup_bindgen_builder();
builder = builder.header("src/rcl_wrapper.h");