Skip to content

Commit

Permalink
moved feature list to crate level
Browse files Browse the repository at this point in the history
  • Loading branch information
milyin committed Oct 29, 2023
1 parent fafb5cd commit f080df6
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 100 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion plugins/zenoh-backend-traits/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,7 @@ zenoh-result = { workspace = true }
zenoh-util = { workspace = true }
schemars = { workspace = true }
zenoh-plugin-trait = { workspace = true }
const_format = { workspace = true }
const_format = { workspace = true }

[features]
default = []
22 changes: 3 additions & 19 deletions plugins/zenoh-backend-traits/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use const_format::concatcp;
//
// Copyright (c) 2023 ZettaScale Technology
//
Expand All @@ -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)]
Expand Down Expand Up @@ -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)
}
}

Expand Down
25 changes: 7 additions & 18 deletions plugins/zenoh-backend-traits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
}
}

Expand Down
10 changes: 5 additions & 5 deletions plugins/zenoh-plugin-trait/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 { "" }
)*)
}
};
Expand All @@ -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;
}

Expand Down
21 changes: 3 additions & 18 deletions plugins/zenoh-plugin-trait/src/vtable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<StartArgs, RunningPlugin> = fn(&str, &StartArgs) -> ZResult<RunningPlugin>;

Expand All @@ -31,24 +33,7 @@ impl<StartArgs, RunningPlugin> CompatibilityVersion for PluginVTable<StartArgs,
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"
)
FEATURES
}
}

Expand Down
1 change: 1 addition & 0 deletions zenoh/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
// Contributors:
// ZettaScale Zenoh Team, <[email protected]>
//

fn main() {
// Add rustc version to zenohd
let version_meta = rustc_version::version_meta().unwrap();
Expand Down
23 changes: 23 additions & 0 deletions zenoh/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand All @@ -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;
Expand Down
22 changes: 2 additions & 20 deletions zenoh/src/net/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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};
Expand Down Expand Up @@ -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
}
}

Expand Down
20 changes: 1 addition & 19 deletions zenoh/src/plugins/sealed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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<StartArgs, RunningPlugin>;

use zenoh_plugin_trait::concat_enabled_features;
pub use zenoh_plugin_trait::CompatibilityVersion;
pub use zenoh_plugin_trait::Plugin;
1 change: 1 addition & 0 deletions zenohd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down

0 comments on commit f080df6

Please sign in to comment.