Browse Source

Include ros2-bridge header files in `dora-node-api-cxx`

tags/v0.3.3-rc1
Philipp Oppermann 2 years ago
parent
commit
b5cbea1a20
Failed to extract signature
6 changed files with 65 additions and 3 deletions
  1. +1
    -0
      Cargo.lock
  2. +2
    -0
      apis/c++/node/Cargo.toml
  3. +58
    -0
      apis/c++/node/build.rs
  4. +1
    -0
      libraries/extensions/ros2-bridge/Cargo.toml
  5. +2
    -2
      libraries/extensions/ros2-bridge/build.rs
  6. +1
    -1
      libraries/extensions/ros2-bridge/src/lib.rs

+ 1
- 0
Cargo.lock View File

@@ -1604,6 +1604,7 @@ dependencies = [
"cxx",
"cxx-build",
"dora-node-api",
"dora-ros2-bridge",
"eyre",
]



+ 2
- 0
apis/c++/node/Cargo.toml View File

@@ -14,11 +14,13 @@ crate-type = ["staticlib"]
[features]
default = ["tracing"]
tracing = ["dora-node-api/tracing"]
ros2-bridge = []

[dependencies]
cxx = "1.0.73"
dora-node-api = { workspace = true }
eyre = "0.6.8"
dora-ros2-bridge = { workspace = true, features = ["cxx-bridge"] }

[build-dependencies]
cxx-build = "1.0.73"

+ 58
- 0
apis/c++/node/build.rs View File

@@ -1,4 +1,62 @@
use std::path::{Component, Path, PathBuf};

fn main() {
let _build = cxx_build::bridge("src/lib.rs");
println!("cargo:rerun-if-changed=src/lib.rs");

if cfg!(feature = "ros2-bridge") {
generate_ros2_message_header();
}
}

fn generate_ros2_message_header() {
let prefix = std::env::var("DEP_DORA_ROS2_BRIDGE_CXXBRIDGE_PREFIX").unwrap();
let include_dir = PathBuf::from(std::env::var("DEP_DORA_ROS2_BRIDGE_CXXBRIDGE_DIR0").unwrap());
let _crate_dir = std::env::var("DEP_DORA_ROS2_BRIDGE_CXXBRIDGE_DIR1").unwrap();

let header_path = include_dir
.join(&prefix)
.join(local_relative_path(&include_dir))
.ancestors()
.nth(2)
.unwrap()
.join("messages.rs.h");
let code_path = include_dir
.parent()
.unwrap()
.join("sources")
.join(&prefix)
.join(local_relative_path(&include_dir))
.ancestors()
.nth(2)
.unwrap()
.join("messages.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")
.join("cxxbridge")
.join("dora-node-api-cxx")
.join("src")
.join("messages.rs.h");

std::fs::copy(header_path, &target_path).unwrap();
std::fs::copy(code_path, target_path.with_file_name("messages.rs.cc")).unwrap();
}

// copy from cxx-build source
fn local_relative_path(path: &Path) -> PathBuf {
let mut rel_path = PathBuf::new();
for component in path.components() {
match component {
Component::Prefix(_) | Component::RootDir | Component::CurDir => {}
Component::ParentDir => drop(rel_path.pop()), // noop if empty
Component::Normal(name) => rel_path.push(name),
}
}
rel_path
}

+ 1
- 0
libraries/extensions/ros2-bridge/Cargo.toml View File

@@ -2,6 +2,7 @@
name = "dora-ros2-bridge"
version = "0.1.0"
edition = "2021"
links = "dora-ros2-bridge"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html



+ 2
- 2
libraries/extensions/ros2-bridge/build.rs View File

@@ -9,9 +9,9 @@ fn main() {
.format_tokens(generated)
.unwrap();
let out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap());
let target_file = out_dir.join("generated.rs");
let target_file = out_dir.join("messages.rs");
std::fs::write(&target_file, generated_string).unwrap();
println!("cargo:rustc-env=GENERATED_PATH={}", target_file.display());
println!("cargo:rustc-env=MESSAGES_PATH={}", target_file.display());

#[cfg(feature = "cxx-bridge")]
let _build = cxx_build::bridge(&target_file);


+ 1
- 1
libraries/extensions/ros2-bridge/src/lib.rs View File

@@ -2,7 +2,7 @@ pub use ros2_client;
pub use rustdds;

pub mod messages {
include!(env!("GENERATED_PATH"));
include!(env!("MESSAGES_PATH"));
}

pub mod _core;

Loading…
Cancel
Save