diff --git a/.gitignore b/.gitignore index ee7721b..18785fc 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,6 @@ .vscode +# cmake default build directory +build + diff --git a/Cargo.lock b/Cargo.lock index 6105b5d..4ecf6eb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4139,7 +4139,7 @@ dependencies = [ [[package]] name = "zenoh" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#b669489bc814a758741f09c671ecc3a0683697a0" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#8cd786f2192fd2aa7387432ae93cdd78f5db1df2" dependencies = [ "async-global-executor", "async-std", @@ -4205,7 +4205,7 @@ dependencies = [ [[package]] name = "zenoh-buffers" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#b669489bc814a758741f09c671ecc3a0683697a0" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#8cd786f2192fd2aa7387432ae93cdd78f5db1df2" dependencies = [ "zenoh-collections", ] @@ -4213,7 +4213,7 @@ dependencies = [ [[package]] name = "zenoh-codec" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#b669489bc814a758741f09c671ecc3a0683697a0" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#8cd786f2192fd2aa7387432ae93cdd78f5db1df2" dependencies = [ "log", "serde", @@ -4225,12 +4225,12 @@ dependencies = [ [[package]] name = "zenoh-collections" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#b669489bc814a758741f09c671ecc3a0683697a0" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#8cd786f2192fd2aa7387432ae93cdd78f5db1df2" [[package]] name = "zenoh-config" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#b669489bc814a758741f09c671ecc3a0683697a0" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#8cd786f2192fd2aa7387432ae93cdd78f5db1df2" dependencies = [ "flume", "json5", @@ -4249,7 +4249,7 @@ dependencies = [ [[package]] name = "zenoh-core" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#b669489bc814a758741f09c671ecc3a0683697a0" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#8cd786f2192fd2aa7387432ae93cdd78f5db1df2" dependencies = [ "async-std", "lazy_static", @@ -4259,7 +4259,7 @@ dependencies = [ [[package]] name = "zenoh-crypto" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#b669489bc814a758741f09c671ecc3a0683697a0" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#8cd786f2192fd2aa7387432ae93cdd78f5db1df2" dependencies = [ "aes 0.8.3", "hmac 0.12.1", @@ -4272,7 +4272,7 @@ dependencies = [ [[package]] name = "zenoh-ext" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#b669489bc814a758741f09c671ecc3a0683697a0" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#8cd786f2192fd2aa7387432ae93cdd78f5db1df2" dependencies = [ "async-std", "bincode", @@ -4292,7 +4292,7 @@ dependencies = [ [[package]] name = "zenoh-keyexpr" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#b669489bc814a758741f09c671ecc3a0683697a0" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#8cd786f2192fd2aa7387432ae93cdd78f5db1df2" dependencies = [ "hashbrown 0.14.0", "keyed-set", @@ -4306,7 +4306,7 @@ dependencies = [ [[package]] name = "zenoh-link" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#b669489bc814a758741f09c671ecc3a0683697a0" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#8cd786f2192fd2aa7387432ae93cdd78f5db1df2" dependencies = [ "async-std", "async-trait", @@ -4325,7 +4325,7 @@ dependencies = [ [[package]] name = "zenoh-link-commons" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#b669489bc814a758741f09c671ecc3a0683697a0" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#8cd786f2192fd2aa7387432ae93cdd78f5db1df2" dependencies = [ "async-std", "async-trait", @@ -4342,7 +4342,7 @@ dependencies = [ [[package]] name = "zenoh-link-quic" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#b669489bc814a758741f09c671ecc3a0683697a0" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#8cd786f2192fd2aa7387432ae93cdd78f5db1df2" dependencies = [ "async-rustls", "async-std", @@ -4368,7 +4368,7 @@ dependencies = [ [[package]] name = "zenoh-link-tcp" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#b669489bc814a758741f09c671ecc3a0683697a0" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#8cd786f2192fd2aa7387432ae93cdd78f5db1df2" dependencies = [ "async-std", "async-trait", @@ -4384,7 +4384,7 @@ dependencies = [ [[package]] name = "zenoh-link-tls" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#b669489bc814a758741f09c671ecc3a0683697a0" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#8cd786f2192fd2aa7387432ae93cdd78f5db1df2" dependencies = [ "async-rustls", "async-std", @@ -4409,7 +4409,7 @@ dependencies = [ [[package]] name = "zenoh-link-udp" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#b669489bc814a758741f09c671ecc3a0683697a0" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#8cd786f2192fd2aa7387432ae93cdd78f5db1df2" dependencies = [ "async-std", "async-trait", @@ -4428,7 +4428,7 @@ dependencies = [ [[package]] name = "zenoh-link-unixsock_stream" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#b669489bc814a758741f09c671ecc3a0683697a0" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#8cd786f2192fd2aa7387432ae93cdd78f5db1df2" dependencies = [ "async-std", "async-trait", @@ -4446,7 +4446,7 @@ dependencies = [ [[package]] name = "zenoh-link-ws" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#b669489bc814a758741f09c671ecc3a0683697a0" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#8cd786f2192fd2aa7387432ae93cdd78f5db1df2" dependencies = [ "async-std", "async-trait", @@ -4466,7 +4466,7 @@ dependencies = [ [[package]] name = "zenoh-macros" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#b669489bc814a758741f09c671ecc3a0683697a0" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#8cd786f2192fd2aa7387432ae93cdd78f5db1df2" dependencies = [ "proc-macro2", "quote", @@ -4479,12 +4479,13 @@ dependencies = [ [[package]] name = "zenoh-plugin-rest" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#b669489bc814a758741f09c671ecc3a0683697a0" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#8cd786f2192fd2aa7387432ae93cdd78f5db1df2" dependencies = [ "anyhow", "async-std", "base64 0.21.4", "clap", + "const_format", "env_logger", "flume", "futures", @@ -4536,11 +4537,14 @@ dependencies = [ [[package]] name = "zenoh-plugin-trait" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#b669489bc814a758741f09c671ecc3a0683697a0" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#8cd786f2192fd2aa7387432ae93cdd78f5db1df2" dependencies = [ + "const_format", "libloading", "log", + "serde", "serde_json", + "zenoh-keyexpr", "zenoh-macros", "zenoh-result", "zenoh-util", @@ -4549,7 +4553,7 @@ dependencies = [ [[package]] name = "zenoh-protocol" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#b669489bc814a758741f09c671ecc3a0683697a0" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#8cd786f2192fd2aa7387432ae93cdd78f5db1df2" dependencies = [ "const_format", "hex", @@ -4565,7 +4569,7 @@ dependencies = [ [[package]] name = "zenoh-result" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#b669489bc814a758741f09c671ecc3a0683697a0" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#8cd786f2192fd2aa7387432ae93cdd78f5db1df2" dependencies = [ "anyhow", ] @@ -4573,7 +4577,7 @@ dependencies = [ [[package]] name = "zenoh-sync" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#b669489bc814a758741f09c671ecc3a0683697a0" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#8cd786f2192fd2aa7387432ae93cdd78f5db1df2" dependencies = [ "async-std", "event-listener 4.0.0", @@ -4588,7 +4592,7 @@ dependencies = [ [[package]] name = "zenoh-transport" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#b669489bc814a758741f09c671ecc3a0683697a0" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#8cd786f2192fd2aa7387432ae93cdd78f5db1df2" dependencies = [ "async-executor", "async-global-executor", @@ -4619,7 +4623,7 @@ dependencies = [ [[package]] name = "zenoh-util" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#b669489bc814a758741f09c671ecc3a0683697a0" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#8cd786f2192fd2aa7387432ae93cdd78f5db1df2" dependencies = [ "async-std", "async-trait", diff --git a/README.md b/README.md index a020780..82340a0 100644 --- a/README.md +++ b/README.md @@ -105,21 +105,12 @@ Once these dependencies are in place, you may clone the repository on your machi ```bash $ git clone https://github.com/eclipse-zenoh/zenoh-plugin-ros2dds.git $ cd zenoh-plugin-ros2dds +$ cargo build --release ``` -> :warning: **WARNING** :warning: : On Linux, don't use `cargo build` command without specifying a package with `-p`. Building both `zenoh-plugin-ros2dds` (plugin library) and `zenoh-bridge-ros2dds` (standalone executable) together will lead to a `multiple definition of `load_plugin'` error at link time. See [#117](https://github.com/eclipse-zenoh/zenoh-plugin-dds/issues/117#issuecomment-1439694331) for explanations. -You can then choose between building the zenoh bridge for DDS: -- as a plugin library that can be dynamically loaded by the zenoh router (`zenohd`): -```bash -$ cargo build --release -p zenoh-plugin-ros2dds -``` -The plugin shared library (`*.so` on Linux, `*.dylib` on Mac OS, `*.dll` on Windows) will be generated in the `target/release` subdirectory. +The standalone executable binary `zenoh-bridge-ros2dds` and a plugin shared library (`*.so` on Linux, `*.dylib` on Mac OS, `*.dll` on Windows) to be dynamically +loaded by the zenoh router `zenohd` will be generated in the `target/release` subdirectory. -- or as a standalone executable binary: -```bash -$ cargo build --release -p zenoh-bridge-ros2dds -``` -The **`zenoh-bridge-ros2dds`** binary will be generated in the `target/release` sub-directory. ## ROS 2 package You can also build `zenoh-bridge-ros2dds` as a ROS package running: diff --git a/zenoh-bridge-ros2dds/src/bridge_args.rs b/zenoh-bridge-ros2dds/src/bridge_args.rs index bcbcbb6..d4f3bb9 100644 --- a/zenoh-bridge-ros2dds/src/bridge_args.rs +++ b/zenoh-bridge-ros2dds/src/bridge_args.rs @@ -15,13 +15,14 @@ use crate::zenoh_args::CommonArgs; use clap::builder::FalseyValueParser; use zenoh::config::Config; use zenoh::prelude::*; +use zenoh_plugin_trait::Plugin; // // All Bridge arguments // #[derive(clap::Parser, Clone, Debug)] -#[command(version=zenoh_plugin_ros2dds::GIT_VERSION, - long_version=zenoh_plugin_ros2dds::LONG_VERSION.as_str(), +#[command(version=zenoh_plugin_ros2dds::ROS2Plugin::PLUGIN_VERSION, + long_version=zenoh_plugin_ros2dds::ROS2Plugin::PLUGIN_LONG_VERSION, about="Zenoh bridge for ROS 2 with a DDS RMW", )] pub struct BridgeArgs { diff --git a/zenoh-bridge-ros2dds/src/main.rs b/zenoh-bridge-ros2dds/src/main.rs index 7be9326..d3998bc 100644 --- a/zenoh-bridge-ros2dds/src/main.rs +++ b/zenoh-bridge-ros2dds/src/main.rs @@ -63,7 +63,7 @@ async fn main() { env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("z=info")).init(); log::info!( "zenoh-bridge-ros2dds {}", - *zenoh_plugin_ros2dds::LONG_VERSION + zenoh_plugin_ros2dds::ROS2Plugin::PLUGIN_LONG_VERSION ); let (watchdog_period, config) = parse_args(); diff --git a/zenoh-plugin-ros2dds/Cargo.toml b/zenoh-plugin-ros2dds/Cargo.toml index 3ea90d9..32637df 100644 --- a/zenoh-plugin-ros2dds/Cargo.toml +++ b/zenoh-plugin-ros2dds/Cargo.toml @@ -29,7 +29,7 @@ crate-type = ["cdylib", "rlib"] [features] default = ["no_mangle"] stats = ["zenoh/stats"] -no_mangle = ["zenoh-plugin-trait/no_mangle"] +no_mangle = [] dds_shm = ["cyclors/iceoryx"] [dependencies] diff --git a/zenoh-plugin-ros2dds/src/lib.rs b/zenoh-plugin-ros2dds/src/lib.rs index 32e6456..20ae2d3 100644 --- a/zenoh-plugin-ros2dds/src/lib.rs +++ b/zenoh-plugin-ros2dds/src/lib.rs @@ -16,21 +16,22 @@ use cyclors::*; use events::ROS2AnnouncementEvent; use flume::{unbounded, Receiver, Sender}; use futures::select; -use git_version::git_version; use serde::Serializer; use std::collections::HashMap; use std::env; use std::mem::ManuallyDrop; use std::sync::Arc; use zenoh::liveliness::LivelinessToken; -use zenoh::plugins::{Plugin, RunningPluginTrait, Runtime, ZenohPlugin}; +use zenoh::plugins::{RunningPlugin, RunningPluginTrait, ZenohPlugin}; use zenoh::prelude::r#async::AsyncResolve; use zenoh::prelude::*; use zenoh::queryable::Query; +use zenoh::runtime::Runtime; use zenoh::Result as ZResult; use zenoh::Session; -use zenoh_core::{bail, zerror}; +use zenoh_core::zerror; use zenoh_ext::SubscriberBuilderExt; +use zenoh_plugin_trait::{plugin_long_version, plugin_version, Plugin, PluginControl}; use zenoh_util::Timed; pub mod config; @@ -62,8 +63,6 @@ use crate::liveliness_mgt::*; use crate::ros_discovery::RosDiscoveryInfoMgr; use crate::routes_mgr::RoutesMgr; -pub const GIT_VERSION: &str = git_version!(prefix = "v", cargo_prefix = "v"); - #[macro_export] macro_rules! ke_for_sure { ($val:expr) => { @@ -72,9 +71,9 @@ macro_rules! ke_for_sure { } lazy_static::lazy_static!( - pub static ref LONG_VERSION: String = format!("{} built with {}", GIT_VERSION, env!("RUSTC_VERSION")); pub static ref VERSION_JSON_VALUE: Value = - serde_json::Value::String(LONG_VERSION.clone()).into(); + serde_json::Value::String(ROS2Plugin::PLUGIN_LONG_VERSION.to_owned()).into(); + static ref LOG_PAYLOAD: bool = std::env::var("Z_LOG_PAYLOAD").is_ok(); static ref KE_ANY_1_SEGMENT: &'static keyexpr = ke_for_sure!("*"); @@ -104,6 +103,7 @@ const CYCLONEDDS_CONFIG_ENABLE_SHM: &str = r#" const ROS_DISCOVERY_INFO_POLL_INTERVAL_MS: u64 = 100; const ROS_DISCOVERY_INFO_PUSH_INTERVAL_MS: u64 = 100; +#[cfg(feature = "no_mangle")] zenoh_plugin_trait::declare_plugin!(ROS2Plugin); #[allow(clippy::upper_case_acronyms)] @@ -112,9 +112,11 @@ pub struct ROS2Plugin; impl ZenohPlugin for ROS2Plugin {} impl Plugin for ROS2Plugin { type StartArgs = Runtime; - type RunningPlugin = zenoh::plugins::RunningPlugin; + type Instance = RunningPlugin; - const STATIC_NAME: &'static str = "zenoh-plugin-ros2dds"; + const PLUGIN_VERSION: &'static str = plugin_version!(); + const PLUGIN_LONG_VERSION: &'static str = plugin_long_version!(); + const DEFAULT_NAME: &'static str = "zenoh-plugin-ros2dds"; fn start(name: &str, runtime: &Self::StartArgs) -> ZResult { // Try to initiate login. @@ -122,7 +124,7 @@ impl Plugin for ROS2Plugin { // But cannot be done twice in case of static link. let _ = env_logger::try_init(); - let runtime_conf = runtime.config.lock(); + let runtime_conf = runtime.config().lock(); let plugin_conf = runtime_conf .plugin(name) .ok_or_else(|| zerror!("Plugin `{}`: missing config", name))?; @@ -132,35 +134,15 @@ impl Plugin for ROS2Plugin { Ok(Box::new(ROS2Plugin)) } } - -impl RunningPluginTrait for ROS2Plugin { - fn config_checker(&self) -> zenoh::plugins::ValidationFunction { - Arc::new(|_, _, _| bail!("ROS2Plugin does not support hot configuration changes.")) - } - - fn adminspace_getter<'a>( - &'a self, - selector: &'a Selector<'a>, - plugin_status_key: &str, - ) -> ZResult> { - let mut responses = Vec::new(); - let version_key = [plugin_status_key, "/__version__"].concat(); - if selector.key_expr.intersects(ke_for_sure!(&version_key)) { - responses.push(zenoh::plugins::Response::new( - version_key, - GIT_VERSION.into(), - )); - } - Ok(responses) - } -} +impl PluginControl for ROS2Plugin {} +impl RunningPluginTrait for ROS2Plugin {} pub async fn run(runtime: Runtime, config: Config) { // Try to initiate login. // Required in case of dynamic lib, otherwise no logs. // But cannot be done twice in case of static link. let _ = env_logger::try_init(); - log::debug!("ROS2 plugin {}", LONG_VERSION.as_str()); + log::debug!("ROS2 plugin {}", ROS2Plugin::PLUGIN_VERSION); log::info!("ROS2 plugin {:?}", config); // Check config validity