diff --git a/Cargo.lock b/Cargo.lock index 0fe53d1dc3..af56b38b7f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5083,6 +5083,7 @@ dependencies = [ "rand 0.8.5", "rustc_version 0.4.0", "zenoh", + "zenoh_backend_traits", ] [[package]] diff --git a/plugins/zenoh-backend-traits/Cargo.toml b/plugins/zenoh-backend-traits/Cargo.toml index 8c13247c5e..f2b8a4a1eb 100644 --- a/plugins/zenoh-backend-traits/Cargo.toml +++ b/plugins/zenoh-backend-traits/Cargo.toml @@ -36,4 +36,7 @@ zenoh-result = { workspace = true } zenoh-util = { workspace = true } schemars = { workspace = true } zenoh-plugin-trait = { workspace = true } -const_format = { workspace = true } \ No newline at end of file +const_format = { workspace = true } + +[features] +default = [] diff --git a/plugins/zenoh-backend-traits/src/config.rs b/plugins/zenoh-backend-traits/src/config.rs index d705adb0ed..8587993a7c 100644 --- a/plugins/zenoh-backend-traits/src/config.rs +++ b/plugins/zenoh-backend-traits/src/config.rs @@ -1,3 +1,4 @@ +use const_format::concatcp; // // Copyright (c) 2023 ZettaScale Technology // @@ -17,7 +18,7 @@ use serde_json::{Map, Value}; use std::convert::TryFrom; use std::time::Duration; use zenoh::{key_expr::keyexpr, prelude::OwnedKeyExpr, Result as ZResult}; -use zenoh_plugin_trait::{concat_enabled_features, CompatibilityVersion}; +use zenoh_plugin_trait::CompatibilityVersion; use zenoh_result::{bail, zerror, Error}; #[derive(JsonSchema, Debug, Clone, AsMut, AsRef)] @@ -73,24 +74,7 @@ impl CompatibilityVersion for VolumeConfig { 1 } fn features() -> &'static str { - concat_enabled_features!( - "auth_pubkey", - "auth_usrpwd", - "complete_n", - "shared-memory", - "stats", - "transport_multilink", - "transport_quic", - "transport_serial", - "transport_unixpipe", - "transport_tcp", - "transport_tls", - "transport_udp", - "transport_unixsock-stream", - "transport_ws", - "unstable", - "default" - ) + concatcp!(zenoh::FEATURES, crate::FEATURES) } } diff --git a/plugins/zenoh-backend-traits/src/lib.rs b/plugins/zenoh-backend-traits/src/lib.rs index cec49188e3..bd4730119f 100644 --- a/plugins/zenoh-backend-traits/src/lib.rs +++ b/plugins/zenoh-backend-traits/src/lib.rs @@ -132,6 +132,7 @@ //! ``` use async_trait::async_trait; +use const_format::concatcp; use std::sync::Arc; use zenoh::prelude::{KeyExpr, OwnedKeyExpr, Sample, Selector}; use zenoh::queryable::ReplyBuilder; @@ -143,6 +144,11 @@ use zenoh_plugin_trait::{concat_enabled_features, CompatibilityVersion}; pub mod config; use config::{StorageConfig, VolumeConfig}; +// No features are actually used in this crate, but this dummy list allows to demonstrate how to combine feature lists +// from multiple crates. See implementation of `CompatibilityVersion::features()` for more `VolumePlugin` and `VolumeConfig` types +const FEATURES: &str = + concat_enabled_features!(prefix = "zenoh-backend-traits", features = ["default"]); + /// Capability of a storage indicates the guarantees of the storage /// It is used by the storage manager to take decisions on the trade-offs to ensure correct performance pub struct Capability { @@ -222,24 +228,7 @@ impl CompatibilityVersion for VolumePlugin { 1 } fn features() -> &'static str { - concat_enabled_features!( - "auth_pubkey", - "auth_usrpwd", - "complete_n", - "shared-memory", - "stats", - "transport_multilink", - "transport_quic", - "transport_serial", - "transport_unixpipe", - "transport_tcp", - "transport_tls", - "transport_udp", - "transport_unixsock-stream", - "transport_ws", - "unstable", - "default" - ) + concatcp!(zenoh::FEATURES, crate::FEATURES) } } diff --git a/plugins/zenoh-plugin-trait/src/lib.rs b/plugins/zenoh-plugin-trait/src/lib.rs index ec1625f49b..eb71a5f36c 100644 --- a/plugins/zenoh-plugin-trait/src/lib.rs +++ b/plugins/zenoh-plugin-trait/src/lib.rs @@ -29,11 +29,11 @@ pub mod prelude { #[macro_export] macro_rules! concat_enabled_features { - ($($feature:literal),*) => { + (prefix = $prefix:literal, features = [$($feature:literal),*]) => { { use const_format::concatcp; - const_format::concatcp!("" $(, - if cfg!(feature = $feature) { concatcp!(" ", $feature) } else { "" } + concatcp!("" $(, + if cfg!(feature = $feature) { concatcp!(" ", concatcp!($prefix, "/", $feature)) } else { "" } )*) } }; @@ -43,9 +43,9 @@ pub trait CompatibilityVersion { /// The version of the structure implementing this trait. After any channge in the structure or it's dependencies /// whcich may affect the ABI, this version should be incremented. fn version() -> u64; - /// The features enabled when the structure implementing this trait was compiled. + /// The features enabled during comiplation of the structure implementing this trait. /// Different features between the plugin and the host may cuase ABI incompatibility even if the structure version is the same. - /// Use `concat_enabled_features!` to generate this string. + /// Use `concat_enabled_features!` to generate this string fn features() -> &'static str; } diff --git a/plugins/zenoh-plugin-trait/src/vtable.rs b/plugins/zenoh-plugin-trait/src/vtable.rs index 8c03283b2a..e1da1a579f 100644 --- a/plugins/zenoh-plugin-trait/src/vtable.rs +++ b/plugins/zenoh-plugin-trait/src/vtable.rs @@ -19,6 +19,8 @@ use zenoh_result::ZResult; pub type PluginLoaderVersion = u64; pub const PLUGIN_LOADER_VERSION: PluginLoaderVersion = 1; +pub const FEATURES: &str = + concat_enabled_features!(prefix = "zenoh-plugin-trait", features = ["default"]); type StartFn = fn(&str, &StartArgs) -> ZResult; @@ -31,24 +33,7 @@ impl CompatibilityVersion for PluginVTable &'static str { - concat_enabled_features!( - "auth_pubkey", - "auth_usrpwd", - "complete_n", - "shared-memory", - "stats", - "transport_multilink", - "transport_quic", - "transport_serial", - "transport_unixpipe", - "transport_tcp", - "transport_tls", - "transport_udp", - "transport_unixsock-stream", - "transport_ws", - "unstable", - "default" - ) + FEATURES } } diff --git a/zenoh/build.rs b/zenoh/build.rs index 85d3c2d187..5be8828dfc 100644 --- a/zenoh/build.rs +++ b/zenoh/build.rs @@ -10,6 +10,7 @@ // Contributors: // ZettaScale Zenoh Team, // + fn main() { // Add rustc version to zenohd let version_meta = rustc_version::version_meta().unwrap(); diff --git a/zenoh/src/lib.rs b/zenoh/src/lib.rs index dbcc3b5827..37e01f8680 100644 --- a/zenoh/src/lib.rs +++ b/zenoh/src/lib.rs @@ -88,6 +88,7 @@ use scouting::ScoutBuilder; use std::future::Ready; use zenoh_core::{AsyncResolve, Resolvable, SyncResolve}; pub use zenoh_macros::{kedefine, keformat, kewrite}; +use zenoh_plugin_trait::concat_enabled_features; use zenoh_protocol::core::WhatAmIMatcher; use zenoh_result::{zerror, ZResult}; @@ -98,6 +99,28 @@ pub use zenoh_result::ZResult as Result; const GIT_VERSION: &str = git_version!(prefix = "v", cargo_prefix = "v"); +pub const FEATURES: &str = concat_enabled_features!( + prefix = "zenoh", + features = [ + "auth_pubkey", + "auth_usrpwd", + "complete_n", + "shared-memory", + "stats", + "transport_multilink", + "transport_quic", + "transport_serial", + "transport_unixpipe", + "transport_tcp", + "transport_tls", + "transport_udp", + "transport_unixsock-stream", + "transport_ws", + "unstable", + "default" + ] +); + mod admin; #[macro_use] mod session; diff --git a/zenoh/src/net/runtime/mod.rs b/zenoh/src/net/runtime/mod.rs index c320f538d2..ef9db31862 100644 --- a/zenoh/src/net/runtime/mod.rs +++ b/zenoh/src/net/runtime/mod.rs @@ -28,7 +28,6 @@ use crate::config::{unwrap_or_default, Config, ModeDependent, Notifier}; use crate::GIT_VERSION; pub use adminspace::AdminSpace; use async_std::task::JoinHandle; -use const_format::concatcp; use futures::stream::StreamExt; use futures::Future; use std::any::Any; @@ -38,7 +37,7 @@ use stop_token::future::FutureExt; use stop_token::{StopSource, TimedOutError}; use uhlc::{HLCBuilder, HLC}; use zenoh_link::{EndPoint, Link}; -use zenoh_plugin_trait::{concat_enabled_features, CompatibilityVersion}; +use zenoh_plugin_trait::CompatibilityVersion; use zenoh_protocol::core::{whatami::WhatAmIMatcher, Locator, WhatAmI, ZenohId}; use zenoh_protocol::network::{NetworkBody, NetworkMessage}; use zenoh_result::{bail, ZResult}; @@ -71,24 +70,7 @@ impl CompatibilityVersion for Runtime { 1 } fn features() -> &'static str { - concat_enabled_features!( - "auth_pubkey", - "auth_usrpwd", - "complete_n", - "shared-memory", - "stats", - "transport_multilink", - "transport_quic", - "transport_serial", - "transport_unixpipe", - "transport_tcp", - "transport_tls", - "transport_udp", - "transport_unixsock-stream", - "transport_ws", - "unstable", - "default" - ) + crate::FEATURES } } diff --git a/zenoh/src/plugins/sealed.rs b/zenoh/src/plugins/sealed.rs index b68dd30253..02768cd9b7 100644 --- a/zenoh/src/plugins/sealed.rs +++ b/zenoh/src/plugins/sealed.rs @@ -36,24 +36,7 @@ impl CompatibilityVersion for RunningPlugin { 1 } fn features() -> &'static str { - concat_enabled_features!( - "auth_pubkey", - "auth_usrpwd", - "complete_n", - "shared-memory", - "stats", - "transport_multilink", - "transport_quic", - "transport_serial", - "transport_unixpipe", - "transport_tcp", - "transport_tls", - "transport_udp", - "transport_unixsock-stream", - "transport_ws", - "unstable", - "default" - ) + crate::FEATURES } } @@ -101,6 +84,5 @@ pub trait RunningPluginTrait: Send + Sync { /// The zenoh plugins manager. It handles the full lifetime of plugins, from loading to destruction. pub type PluginsManager = zenoh_plugin_trait::loading::PluginsManager; -use zenoh_plugin_trait::concat_enabled_features; pub use zenoh_plugin_trait::CompatibilityVersion; pub use zenoh_plugin_trait::Plugin; diff --git a/zenohd/Cargo.toml b/zenohd/Cargo.toml index e589d1a888..c1c6f432e7 100644 --- a/zenohd/Cargo.toml +++ b/zenohd/Cargo.toml @@ -38,6 +38,7 @@ json5 = { workspace = true } lazy_static = { workspace = true } log = { workspace = true } zenoh = { workspace = true, features = ["unstable"] } +zenoh_backend_traits = { workspace = true } [dev-dependencies] rand = { workspace = true, features = ["default"] }