Skip to content

Commit

Permalink
concat_enabled_features
Browse files Browse the repository at this point in the history
  • Loading branch information
milyin committed Oct 16, 2023
1 parent b1780e1 commit 63346f0
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 11 deletions.
15 changes: 9 additions & 6 deletions plugins/zenoh-plugin-trait/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,18 @@ pub mod vtable;
use zenoh_result::ZResult;

pub mod prelude {
pub use crate::{loading::*, vtable::*, Plugin, CompatibilityVersion};
pub use crate::{loading::*, vtable::*, CompatibilityVersion, Plugin};
}

#[macro_export]
macro_rules! version_with_features {
($version:literal, $($feature:literal),*) => {
concatcp!($version $(,
if cfg!(feature = $feature) { concatcp!(" ", $feature) } else { "" }
)*)
macro_rules! concat_enabled_features {
($version:ident, $($feature:literal),*) => {
{
use const_format::concatcp;
const_format::concatcp!($version $(,
if cfg!(feature = $feature) { concatcp!(" ", $feature) } else { "" }
)*)
}
};
}
pub trait CompatibilityVersion {
Expand Down
8 changes: 5 additions & 3 deletions zenoh/src/net/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use stop_token::future::FutureExt;
use stop_token::{StopSource, TimedOutError};
use uhlc::{HLCBuilder, HLC};
use zenoh_link::{EndPoint, Link};
use zenoh_plugin_trait::{CompatibilityVersion, version_with_features};
use zenoh_plugin_trait::{CompatibilityVersion, concat_enabled_features};
use zenoh_protocol::core::{whatami::WhatAmIMatcher, Locator, WhatAmI, ZenohId};
use zenoh_protocol::network::{NetworkBody, NetworkMessage};
use zenoh_result::{bail, ZResult};
Expand Down Expand Up @@ -66,10 +66,12 @@ pub struct Runtime {
state: Arc<RuntimeState>,
}

const RUNTIME_VERSION: &str = "1";

impl CompatibilityVersion for Runtime {
fn version() -> &'static str {
version_with_features!(
"1",
concat_enabled_features!(
RUNTIME_VERSION,
"auth_pubkey",
"auth_usrpwd",
"complete_n",
Expand Down
23 changes: 22 additions & 1 deletion zenoh/src/plugins/sealed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,29 @@ pub type StartArgs = Runtime;
/// A zenoh plugin, when started, must return this type.
pub type RunningPlugin = Box<dyn RunningPluginTrait + 'static>;

const RUNNING_PLUGIN_VERSION: &str = "1";

impl CompatibilityVersion for RunningPlugin {
fn version() -> &'static str {
"1"
concat_enabled_features!(
RUNNING_PLUGIN_VERSION,
"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"
)
}
}

Expand Down Expand Up @@ -81,5 +101,6 @@ 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<StartArgs, RunningPlugin>;

use zenoh_plugin_trait::concat_enabled_features;
pub use zenoh_plugin_trait::CompatibilityVersion;
pub use zenoh_plugin_trait::Plugin;
1 change: 0 additions & 1 deletion zenohd/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use zenoh::config::{Config, ModeDependentValue, PermissionsConf, PluginLoad, Val
use zenoh::plugins::PluginsManager;
use zenoh::prelude::{EndPoint, WhatAmI};
use zenoh::runtime::{AdminSpace, Runtime};
use zenoh::plugins::CompatibilityVersion;

const GIT_VERSION: &str = git_version!(prefix = "v", cargo_prefix = "v");

Expand Down

0 comments on commit 63346f0

Please sign in to comment.