diff --git a/Cargo.lock b/Cargo.lock index 30161643..9e016a8c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4194,7 +4194,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#e8dca1e0ac7036ee04ab024115d418224492343d" dependencies = [ "async-global-executor", "async-std", @@ -4259,7 +4259,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#e8dca1e0ac7036ee04ab024115d418224492343d" dependencies = [ "zenoh-collections", ] @@ -4267,7 +4267,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#e8dca1e0ac7036ee04ab024115d418224492343d" dependencies = [ "log", "serde", @@ -4279,12 +4279,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#e8dca1e0ac7036ee04ab024115d418224492343d" [[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#e8dca1e0ac7036ee04ab024115d418224492343d" dependencies = [ "flume", "json5", @@ -4303,7 +4303,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#e8dca1e0ac7036ee04ab024115d418224492343d" dependencies = [ "async-std", "lazy_static", @@ -4313,7 +4313,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#e8dca1e0ac7036ee04ab024115d418224492343d" dependencies = [ "aes 0.8.3", "hmac 0.12.1", @@ -4326,7 +4326,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#e8dca1e0ac7036ee04ab024115d418224492343d" dependencies = [ "async-std", "bincode", @@ -4346,7 +4346,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#e8dca1e0ac7036ee04ab024115d418224492343d" dependencies = [ "hashbrown 0.14.0", "keyed-set", @@ -4360,7 +4360,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#e8dca1e0ac7036ee04ab024115d418224492343d" dependencies = [ "async-std", "async-trait", @@ -4379,7 +4379,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#e8dca1e0ac7036ee04ab024115d418224492343d" dependencies = [ "async-std", "async-trait", @@ -4396,7 +4396,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#e8dca1e0ac7036ee04ab024115d418224492343d" dependencies = [ "async-rustls", "async-std", @@ -4422,7 +4422,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#e8dca1e0ac7036ee04ab024115d418224492343d" dependencies = [ "async-std", "async-trait", @@ -4438,7 +4438,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#e8dca1e0ac7036ee04ab024115d418224492343d" dependencies = [ "async-rustls", "async-std", @@ -4463,7 +4463,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#e8dca1e0ac7036ee04ab024115d418224492343d" dependencies = [ "async-std", "async-trait", @@ -4482,7 +4482,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#e8dca1e0ac7036ee04ab024115d418224492343d" dependencies = [ "async-std", "async-trait", @@ -4500,7 +4500,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#e8dca1e0ac7036ee04ab024115d418224492343d" dependencies = [ "async-std", "async-trait", @@ -4520,7 +4520,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#e8dca1e0ac7036ee04ab024115d418224492343d" dependencies = [ "proc-macro2", "quote", @@ -4562,12 +4562,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#e8dca1e0ac7036ee04ab024115d418224492343d" dependencies = [ "anyhow", "async-std", "base64 0.21.4", "clap 4.4.11", + "const_format", "env_logger", "flume", "futures", @@ -4590,11 +4591,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#e8dca1e0ac7036ee04ab024115d418224492343d" dependencies = [ + "const_format", "libloading", "log", + "serde", "serde_json", + "zenoh-keyexpr", "zenoh-macros", "zenoh-result", "zenoh-util", @@ -4603,7 +4607,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#e8dca1e0ac7036ee04ab024115d418224492343d" dependencies = [ "const_format", "hex", @@ -4619,7 +4623,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#e8dca1e0ac7036ee04ab024115d418224492343d" dependencies = [ "anyhow", ] @@ -4627,7 +4631,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#e8dca1e0ac7036ee04ab024115d418224492343d" dependencies = [ "async-std", "event-listener 4.0.0", @@ -4642,7 +4646,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#e8dca1e0ac7036ee04ab024115d418224492343d" dependencies = [ "async-executor", "async-global-executor", @@ -4673,7 +4677,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#e8dca1e0ac7036ee04ab024115d418224492343d" dependencies = [ "async-std", "async-trait", diff --git a/Cargo.toml b/Cargo.toml index aeeb2ab9..e4cde952 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,10 +18,10 @@ members = ["zenoh-bridge-dds", "zenoh-plugin-dds"] [workspace.package] version = "0.11.0-dev" authors = [ - "kydos ", - "Esteve Fernandez ", - "Julien Enoch ", - "Pierre Avital ", + "kydos ", + "Esteve Fernandez ", + "Julien Enoch ", + "Pierre Avital ", ] edition = "2021" repository = "https://github.com/eclipse-zenoh/zenoh-plugin-dds" diff --git a/README.md b/README.md index c956feba..fb61a97e 100644 --- a/README.md +++ b/README.md @@ -107,22 +107,11 @@ Once these dependencies are in place, you may clone the repository on your machi ```bash $ git clone https://github.com/eclipse-zenoh/zenoh-plugin-dds.git $ cd zenoh-plugin-dds +$ cargo build --release ``` -> :warning: **WARNING** :warning: : On Linux, don't use `cargo build` command without specifying a package with `-p`. Building both `zenoh-plugin-dds` (plugin library) and `zenoh-bridge-dds` (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-dds -``` -The plugin shared library (`*.so` on Linux, `*.dylib` on Mac OS, `*.dll` on Windows) will be generated in the `target/release` subdirectory. - -- or as a standalone executable binary: -```bash -$ cargo build --release -p zenoh-bridge-dds -``` -The **`zenoh-bridge-dds`** binary will be generated in the `target/release` sub-directory. +The standalone executable binary `zenoh-bridge-dds` 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. ### Enabling Cyclone DDS Shared Memory Support diff --git a/zenoh-bridge-dds/src/main.rs b/zenoh-bridge-dds/src/main.rs index 0d811a54..b4f692fa 100644 --- a/zenoh-bridge-dds/src/main.rs +++ b/zenoh-bridge-dds/src/main.rs @@ -17,6 +17,8 @@ use std::str::FromStr; use std::time::{Duration, SystemTime}; use zenoh::config::{Config, ModeDependentValue}; use zenoh::prelude::*; +use zenoh_plugin_dds::DDSPlugin; +use zenoh_plugin_trait::Plugin; lazy_static::lazy_static!( pub static ref DEFAULT_DOMAIN_STR: String = zenoh_plugin_dds::config::DEFAULT_DOMAIN.to_string(); @@ -42,8 +44,8 @@ macro_rules! insert_json5 { fn parse_args() -> (Config, Option) { let mut app = App::new("zenoh bridge for DDS") - .version(zenoh_plugin_dds::GIT_VERSION) - .long_version(zenoh_plugin_dds::LONG_VERSION.as_str()) + .version(DDSPlugin::PLUGIN_VERSION) + .long_version(DDSPlugin::PLUGIN_LONG_VERSION) // // zenoh related arguments: // @@ -234,7 +236,7 @@ r#"--watchdog=[PERIOD] 'Experimental!! Run a watchdog thread that monitors the #[async_std::main] async fn main() { env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("z=info")).init(); - log::info!("zenoh-bridge-dds {}", *zenoh_plugin_dds::LONG_VERSION); + log::info!("zenoh-bridge-dds {}", DDSPlugin::PLUGIN_LONG_VERSION); let (config, watchdog_period) = parse_args(); let rest_plugin = config.plugin("rest").is_some(); diff --git a/zenoh-plugin-dds/Cargo.toml b/zenoh-plugin-dds/Cargo.toml index d5bee881..f5bc59f6 100644 --- a/zenoh-plugin-dds/Cargo.toml +++ b/zenoh-plugin-dds/Cargo.toml @@ -28,7 +28,7 @@ crate-type = ["cdylib", "rlib"] [features] default = ["no_mangle"] -no_mangle = ["zenoh-plugin-trait/no_mangle"] +no_mangle = [] dds_shm = ["cyclors/iceoryx"] stats = ["zenoh/stats"] diff --git a/zenoh-plugin-dds/src/lib.rs b/zenoh-plugin-dds/src/lib.rs index 5d18566b..fdef235c 100644 --- a/zenoh-plugin-dds/src/lib.rs +++ b/zenoh-plugin-dds/src/lib.rs @@ -19,7 +19,6 @@ use cyclors::qos::{ use cyclors::*; use flume::{unbounded, Receiver, Sender}; use futures::select; -use git_version::git_version; use log::{debug, error, info, trace, warn}; use route_dds_zenoh::RouteDDSZenoh; use serde::ser::SerializeStruct; @@ -33,17 +32,19 @@ use std::sync::atomic::AtomicBool; use std::sync::Arc; use std::time::Duration; 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::r#sync::SyncResolve; use zenoh::prelude::*; use zenoh::publication::CongestionControl; use zenoh::query::{ConsolidationMode, QueryTarget}; use zenoh::queryable::{Query, Queryable}; +use zenoh::runtime::Runtime; use zenoh::Result as ZResult; use zenoh::Session; -use zenoh_core::{bail, zerror}; +use zenoh_core::zerror; use zenoh_ext::{SessionExt, SubscriberBuilderExt}; +use zenoh_plugin_trait::{plugin_long_version, plugin_version, Plugin, PluginControl}; use zenoh_util::{Timed, TimedEvent, Timer}; pub mod config; @@ -61,8 +62,6 @@ use crate::ros_discovery::{ }; use crate::route_zenoh_dds::RouteZenohDDS; -pub const GIT_VERSION: &str = git_version!(prefix = "v", cargo_prefix = "v"); - macro_rules! ke_for_sure { ($val:expr) => { unsafe { keyexpr::from_str_unchecked($val) } @@ -76,7 +75,6 @@ macro_rules! member_id { } lazy_static::lazy_static!( - pub static ref LONG_VERSION: String = format!("{} built with {}", GIT_VERSION, env!("RUSTC_VERSION")); static ref LOG_PAYLOAD: bool = std::env::var("Z_LOG_PAYLOAD").is_ok(); static ref KE_PREFIX_ADMIN_SPACE: &'static keyexpr = ke_for_sure!("@/service"); @@ -103,6 +101,7 @@ const CYCLONEDDS_CONFIG_ENABLE_SHM: &str = r#" const ROS_DISCOVERY_INFO_POLL_INTERVAL_MS: u64 = 500; +#[cfg(feature = "no_mangle")] zenoh_plugin_trait::declare_plugin!(DDSPlugin); fn log_ros2_deprecation_warning() { @@ -120,20 +119,23 @@ fn log_ros2_deprecation_warning() { #[allow(clippy::upper_case_acronyms)] pub struct DDSPlugin; +impl PluginControl for DDSPlugin {} impl ZenohPlugin for DDSPlugin {} impl Plugin for DDSPlugin { type StartArgs = Runtime; - type RunningPlugin = zenoh::plugins::RunningPlugin; + type Instance = RunningPlugin; - const STATIC_NAME: &'static str = "zenoh-plugin-dds"; + const DEFAULT_NAME: &'static str = "zenoh-plugin-dds"; + const PLUGIN_VERSION: &'static str = plugin_version!(); + const PLUGIN_LONG_VERSION: &'static str = plugin_long_version!(); - fn start(name: &str, runtime: &Self::StartArgs) -> ZResult { + fn start(name: &str, runtime: &Self::StartArgs) -> ZResult { // 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(); - 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))?; @@ -143,34 +145,14 @@ impl Plugin for DDSPlugin { Ok(Box::new(DDSPlugin)) } } -impl RunningPluginTrait for DDSPlugin { - fn config_checker(&self) -> zenoh::plugins::ValidationFunction { - Arc::new(|_, _, _| bail!("DDSPlugin 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 RunningPluginTrait for DDSPlugin {} 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(); - debug!("DDS plugin {}", LONG_VERSION.as_str()); + debug!("DDS plugin {}", DDSPlugin::PLUGIN_LONG_VERSION); debug!("DDS plugin {:?}", config); // open zenoh-net Session @@ -636,7 +618,7 @@ impl<'a> DdsPluginRuntime<'a> { .map(serde_json::to_value) .transpose(), AdminRef::Config => Some(serde_json::to_value(self)).transpose(), - AdminRef::Version => Ok(Some(Value::String(LONG_VERSION.clone()))), + AdminRef::Version => Ok(Some(DDSPlugin::PLUGIN_LONG_VERSION.into())), } }