Skip to content

Commit

Permalink
Restore old cmake integration functionality on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
m-dahl committed Sep 26, 2023
1 parent 45e862b commit 0a6e0f5
Showing 1 changed file with 30 additions and 21 deletions.
51 changes: 30 additions & 21 deletions r2r_common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,9 @@ pub fn setup_bindgen_builder() -> bindgen::Builder {
.default_enum_style(bindgen::EnumVariation::Rust {
non_exhaustive: false,
});
let split_char = if cfg!(target_os = "windows") {
';'
} else {
':'
};
if let Ok(cmake_includes) = env::var("CMAKE_INCLUDE_DIRS") {
// we are running from cmake, do special thing.
let mut includes = cmake_includes.split(split_char).collect::<Vec<_>>();
let mut includes = cmake_includes.split(':').collect::<Vec<_>>();
includes.sort_unstable();
includes.dedup();

Expand All @@ -78,6 +73,11 @@ pub fn setup_bindgen_builder() -> bindgen::Builder {
}
RawOsString::new(ament_str)
};
let split_char = if cfg!(target_os = "windows") {
';'
} else {
':'
};
for p in ament_prefix_var.split(split_char) {
let path = Path::new(&p.to_os_str()).join("include");

Expand Down Expand Up @@ -150,27 +150,31 @@ pub fn print_cargo_ros_distro() {
}

pub fn print_cargo_link_search() {
let split_char = if cfg!(target_os = "windows") {
';'
} else {
':'
};
if env::var_os("CMAKE_INCLUDE_DIRS").is_some() {
if let Some(paths) = env::var_os("CMAKE_LIBRARIES") {
let paths = RawOsString::new(paths);
paths
.split(split_char)
.split(':')
.filter(|s| {
s.contains(".so")
|| s.contains(".dylib")
|| s.contains(".dll")
|| s.contains(".lib")
})
.filter_map(|l| {
let is_dll = l.contains(".dll");
let l = l.to_os_str();
let parent = Path::new(&l).parent()?;
let parent = parent.to_str()?;
Some(parent.to_string())
let parent = if is_dll {
// Hack to replace /bin with /lib on windows
// (may not work in all cases)
// Should really be fixed in cmake integration
// but annoying to replace that file in all
// repos that use it.
Path::new(&l).parent()?.parent()?.join("lib").to_str()?.to_string()
} else {
Path::new(&l).parent()?.to_str()?.to_string()
};
Some(parent)
})
.unique()
.for_each(|pp| println!("cargo:rustc-link-search=native={}", pp));
Expand All @@ -188,6 +192,11 @@ pub fn print_cargo_link_search() {
} else {
RawOsString::new(paths)
};
let split_char = if cfg!(target_os = "windows") {
';'
} else {
':'
};
for path in paths.split(split_char) {
if cfg!(target_os = "windows") {
let lib_path = Path::new(&path.to_os_str()).join("Lib");
Expand All @@ -209,23 +218,23 @@ pub fn print_cargo_link_search() {
}

pub fn get_wanted_messages() -> Vec<RosMsg> {
let split_char = if cfg!(target_os = "windows") {
';'
} else {
':'
};
let msgs = if let Ok(cmake_package_dirs) = env::var("CMAKE_IDL_PACKAGES") {
// CMAKE_PACKAGE_DIRS should be a (cmake) list of "cmake" dirs
// e.g. For each dir install/r2r_minimal_node_msgs/share/r2r_minimal_node_msgs/cmake
// we can traverse back and then look for .msg files in msg/ srv/ action/
let dirs = cmake_package_dirs
.split(split_char)
.split(':')
.flat_map(|i| Path::new(i).parent())
.collect::<Vec<_>>();

get_ros_msgs_files(&dirs)
} else {
// Else we look for all msgs we can find using the ament prefix path.
let split_char = if cfg!(target_os = "windows") {
';'
} else {
':'
};
if !cfg!(target_os = "windows") {
if let Ok(ament_prefix_var) = env::var("AMENT_PREFIX_PATH") {
let paths = ament_prefix_var
Expand Down

0 comments on commit 0a6e0f5

Please sign in to comment.