Skip to content

Commit

Permalink
featue leak fixed, test added (#604)
Browse files Browse the repository at this point in the history
  • Loading branch information
milyin authored Nov 29, 2023
1 parent fa02cf0 commit 7fa7d6c
Show file tree
Hide file tree
Showing 11 changed files with 116 additions and 14 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ jobs:
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
ASYNC_STD_THREAD_COUNT: 4

- name: Check for feature leaks
if: ${{ matrix.os == 'ubuntu-latest' }}
uses: actions-rs/cargo@v1
with:
command: nextest
args: run -p zenohd --no-default-features

- name: Run doctests
uses: actions-rs/cargo@v1
with:
Expand Down
2 changes: 2 additions & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ zenoh-link-unixpipe = { version = "0.11.0-dev", path = "io/zenoh-links/zenoh-lin
zenoh-link-serial = { version = "0.11.0-dev", path = "io/zenoh-links/zenoh-link-serial" }
zenoh-link = { version = "0.11.0-dev", path = "io/zenoh-link" }
zenoh-link-commons = { version = "0.11.0-dev", path = "io/zenoh-link-commons" }
zenoh = { version = "0.11.0-dev", path = "zenoh" }
zenoh = { version = "0.11.0-dev", path = "zenoh", default-features = false }

[profile.dev]
debug = true
Expand Down
1 change: 1 addition & 0 deletions commons/zenoh-util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ default = ["std"]
async-std = { workspace = true, features = ["default", "unstable"] }
async-trait = { workspace = true }
clap = { workspace = true }
const_format = { workspace = true }
flume = { workspace = true }
futures = { workspace = true }
hex = { workspace = true, features = ["default"] }
Expand Down
12 changes: 12 additions & 0 deletions commons/zenoh-util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ extern crate alloc;
#[cfg_attr(feature = "std", macro_use)]
extern crate lazy_static;

#[macro_export]
macro_rules! concat_enabled_features {
(prefix = $prefix:literal, features = [$($feature:literal),*]) => {
{
use const_format::concatcp;
concatcp!("" $(,
if cfg!(feature = $feature) { concatcp!(" ", concatcp!($prefix, "/", $feature)) } else { "" }
)*)
}
};
}

#[deprecated = "This module is now a separate crate. Use the `zenoh_core` crate directly for shorter compile-times. You may disable this re-export by disabling `zenoh-util`'s default features."]
pub use zenoh_core as core;

Expand Down
27 changes: 15 additions & 12 deletions io/zenoh-link/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
//!
//! [Click here for Zenoh's documentation](../zenoh/index.html)
use std::collections::HashMap;
use std::sync::Arc;
use zenoh_config::Config;
use zenoh_result::{bail, ZResult};

Expand Down Expand Up @@ -206,23 +205,27 @@ impl LinkManagerBuilderUnicast {
pub fn make(_manager: NewLinkChannelSender, protocol: &str) -> ZResult<LinkManagerUnicast> {
match protocol {
#[cfg(feature = "transport_tcp")]
TCP_LOCATOR_PREFIX => Ok(Arc::new(LinkManagerUnicastTcp::new(_manager))),
TCP_LOCATOR_PREFIX => Ok(std::sync::Arc::new(LinkManagerUnicastTcp::new(_manager))),
#[cfg(feature = "transport_udp")]
UDP_LOCATOR_PREFIX => Ok(Arc::new(LinkManagerUnicastUdp::new(_manager))),
UDP_LOCATOR_PREFIX => Ok(std::sync::Arc::new(LinkManagerUnicastUdp::new(_manager))),
#[cfg(feature = "transport_tls")]
TLS_LOCATOR_PREFIX => Ok(Arc::new(LinkManagerUnicastTls::new(_manager))),
TLS_LOCATOR_PREFIX => Ok(std::sync::Arc::new(LinkManagerUnicastTls::new(_manager))),
#[cfg(feature = "transport_quic")]
QUIC_LOCATOR_PREFIX => Ok(Arc::new(LinkManagerUnicastQuic::new(_manager))),
QUIC_LOCATOR_PREFIX => Ok(std::sync::Arc::new(LinkManagerUnicastQuic::new(_manager))),
#[cfg(all(feature = "transport_unixsock-stream", target_family = "unix"))]
UNIXSOCKSTREAM_LOCATOR_PREFIX => {
Ok(Arc::new(LinkManagerUnicastUnixSocketStream::new(_manager)))
}
UNIXSOCKSTREAM_LOCATOR_PREFIX => Ok(std::sync::Arc::new(
LinkManagerUnicastUnixSocketStream::new(_manager),
)),
#[cfg(feature = "transport_ws")]
WS_LOCATOR_PREFIX => Ok(Arc::new(LinkManagerUnicastWs::new(_manager))),
WS_LOCATOR_PREFIX => Ok(std::sync::Arc::new(LinkManagerUnicastWs::new(_manager))),
#[cfg(feature = "transport_serial")]
SERIAL_LOCATOR_PREFIX => Ok(Arc::new(LinkManagerUnicastSerial::new(_manager))),
SERIAL_LOCATOR_PREFIX => {
Ok(std::sync::Arc::new(LinkManagerUnicastSerial::new(_manager)))
}
#[cfg(feature = "transport_unixpipe")]
UNIXPIPE_LOCATOR_PREFIX => Ok(Arc::new(LinkManagerUnicastPipe::new(_manager))),
UNIXPIPE_LOCATOR_PREFIX => {
Ok(std::sync::Arc::new(LinkManagerUnicastPipe::new(_manager)))
}
_ => bail!("Unicast not supported for {} protocol", protocol),
}
}
Expand All @@ -238,7 +241,7 @@ impl LinkManagerBuilderMulticast {
pub fn make(protocol: &str) -> ZResult<LinkManagerMulticast> {
match protocol {
#[cfg(feature = "transport_udp")]
UDP_LOCATOR_PREFIX => Ok(Arc::new(LinkManagerMulticastUdp)),
UDP_LOCATOR_PREFIX => Ok(std::sync::Arc::new(LinkManagerMulticastUdp)),
_ => bail!("Multicast not supported for {} protocol", protocol),
}
}
Expand Down
2 changes: 1 addition & 1 deletion zenoh-ext/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ flume = { workspace = true }
futures = { workspace = true }
log = { workspace = true }
serde = { workspace = true, features = ["default"] }
zenoh = { workspace = true, features = ["unstable"] }
zenoh = { workspace = true, features = ["unstable"], default-features = false }
zenoh-core = { workspace = true }
zenoh-macros = { workspace = true }
zenoh-result = { workspace = true }
Expand Down
1 change: 1 addition & 0 deletions zenoh/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ async-global-executor = { workspace = true }
async-std = { workspace = true, features = ["attributes"] }
async-trait = { workspace = true }
base64 = { workspace = true }
const_format = { workspace = true }
env_logger = { workspace = true }
event-listener = { workspace = true }
flume = { workspace = true }
Expand Down
23 changes: 23 additions & 0 deletions zenoh/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ use zenoh_core::{AsyncResolve, Resolvable, SyncResolve};
pub use zenoh_macros::{kedefine, keformat, kewrite};
use zenoh_protocol::core::WhatAmIMatcher;
use zenoh_result::{zerror, ZResult};
use zenoh_util::concat_enabled_features;

/// A zenoh error.
pub use zenoh_result::Error;
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
1 change: 1 addition & 0 deletions zenohd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ readme = "README.md"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
default = ["zenoh/default"]
shared-memory = ["zenoh/shared-memory"]

[dependencies]
Expand Down
52 changes: 52 additions & 0 deletions zenohd/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,3 +307,55 @@ fn config_from_args(args: &ArgMatches) -> Config {
log::debug!("Config: {:?}", &config);
config
}

#[test]
#[cfg(feature = "default")]
fn test_default_features() {
assert_eq!(
zenoh::FEATURES,
concat!(
" zenoh/auth_pubkey",
" zenoh/auth_usrpwd",
// " zenoh/complete_n",
// " zenoh/shared-memory",
// " zenoh/stats",
" zenoh/transport_multilink",
" zenoh/transport_quic",
// " zenoh/transport_serial",
// " zenoh/transport_unixpipe",
" zenoh/transport_tcp",
" zenoh/transport_tls",
" zenoh/transport_udp",
" zenoh/transport_unixsock-stream",
" zenoh/transport_ws",
" zenoh/unstable",
" zenoh/default",
)
);
}

#[test]
#[cfg(not(feature = "default"))]
fn test_no_default_features() {
assert_eq!(
zenoh::FEATURES,
concat!(
// " zenoh/auth_pubkey",
// " zenoh/auth_usrpwd",
// " zenoh/complete_n",
// " zenoh/shared-memory",
// " zenoh/stats",
// " zenoh/transport_multilink",
// " zenoh/transport_quic",
// " zenoh/transport_serial",
// " zenoh/transport_unixpipe",
// " zenoh/transport_tcp",
// " zenoh/transport_tls",
// " zenoh/transport_udp",
// " zenoh/transport_unixsock-stream",
// " zenoh/transport_ws",
" zenoh/unstable",
// " zenoh/default",
)
);
}

0 comments on commit 7fa7d6c

Please sign in to comment.