Skip to content

Commit

Permalink
Silence cfg and ffi warnings. Fixes #108.
Browse files Browse the repository at this point in the history
  • Loading branch information
m-dahl committed Oct 13, 2024
1 parent d8fe90b commit 4cb5bd3
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
12 changes: 12 additions & 0 deletions r2r/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ use filenames::*;

fn main() {
r2r_common::print_cargo_watches();
// Declare all the custom cfg directives we use
// to silence cargo warnings.
r2r_common::print_cargo_used_cfgs(&[
"r2r__rosgraph_msgs__msg__Clock",
"r2r__action_msgs__msg__GoalStatus",
"r2r__test_msgs__msg__Defaults",
"r2r__test_msgs__msg__Arrays",
"r2r__test_msgs__msg__WStrings",
"r2r__example_interfaces__srv__AddTwoInts",
"r2r__std_srvs__srv__Empty",
"r2r__example_interfaces__action__Fibonacci",
]);
r2r_common::print_cargo_ros_distro();

let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());
Expand Down
13 changes: 13 additions & 0 deletions r2r_common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,19 @@ pub fn print_cargo_ros_distro() {
}
}

pub fn print_cargo_used_cfgs(message_cfgs: &[&str]) {
// Declare all supported ros distros as cfg directives for cargo
for d in SUPPORTED_ROS_DISTROS {
println!("cargo::rustc-check-cfg=cfg(r2r__ros__distro__{d})");
}

// additionally we have conditional tests and features based on some
// optional ros message packages.
for c in message_cfgs {
println!("cargo::rustc-check-cfg=cfg({c})");
}
}

pub fn print_cargo_link_search() {
let ament_prefix_var_name = "AMENT_PREFIX_PATH";
if let Some(paths) = env::var_os(ament_prefix_var_name) {
Expand Down
4 changes: 4 additions & 0 deletions r2r_rcl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
#![allow(non_snake_case)]
#![allow(improper_ctypes)]
#![allow(dead_code)]
// Silence "`extern` fn uses type `u128`, which is not FFI-safe"
// As of rustc 1.78, this has been fixed.
// It could be good to still warn if building with an older rust version.
#![allow(improper_ctypes)]
include!(concat!(env!("OUT_DIR"), "/rcl_bindings.rs"));

use std::ffi::{CStr, CString};
Expand Down
1 change: 1 addition & 0 deletions tests/build_minimal_node.bash
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash

# Use the local version of r2r when building the minimal node.
rm /r2r/r2r_minimal_node/r2r_minimal_node/Cargo.lock
cat >> /r2r/r2r_minimal_node/r2r_minimal_node/Cargo.toml << EOF
[patch.crates-io]
Expand Down

0 comments on commit 4cb5bd3

Please sign in to comment.