From 28ad2d6959c1223a6bf0921133d1226bbc2ab05c Mon Sep 17 00:00:00 2001 From: Pierre Avital Date: Wed, 4 Oct 2023 11:44:48 +0200 Subject: [PATCH 1/3] fix package-scale compilation for subcrates, make ketrees generic over their hasher --- commons/zenoh-keyexpr/Cargo.toml | 1 + .../src/keyexpr_tree/impls/hashmap_impl.rs | 13 ++++++++----- .../src/keyexpr_tree/impls/keyed_set_impl.rs | 12 ++++++++++-- commons/zenoh-protocol/Cargo.toml | 3 ++- commons/zenoh-protocol/src/network/request.rs | 2 +- 5 files changed, 22 insertions(+), 9 deletions(-) diff --git a/commons/zenoh-keyexpr/Cargo.toml b/commons/zenoh-keyexpr/Cargo.toml index e9d37e9762..920db98696 100644 --- a/commons/zenoh-keyexpr/Cargo.toml +++ b/commons/zenoh-keyexpr/Cargo.toml @@ -42,6 +42,7 @@ hashbrown = { workspace = true } [dev-dependencies] criterion = { workspace = true } lazy_static = { workspace = true } +rand = { workspace = true, features = ["default"] } [[bench]] name = "keyexpr_tree" diff --git a/commons/zenoh-keyexpr/src/keyexpr_tree/impls/hashmap_impl.rs b/commons/zenoh-keyexpr/src/keyexpr_tree/impls/hashmap_impl.rs index e446f82de1..f9bcdf799f 100644 --- a/commons/zenoh-keyexpr/src/keyexpr_tree/impls/hashmap_impl.rs +++ b/commons/zenoh-keyexpr/src/keyexpr_tree/impls/hashmap_impl.rs @@ -12,22 +12,25 @@ // ZettaScale Zenoh Team, // +use core::hash::Hasher; #[cfg(not(feature = "std"))] use hashbrown::{ - hash_map::{Entry, Iter, IterMut, Values, ValuesMut}, + hash_map::{DefaultHasher, Entry, Iter, IterMut, Values, ValuesMut}, HashMap, }; #[cfg(feature = "std")] use std::collections::{ - hash_map::{Entry, Iter, IterMut, Values, ValuesMut}, + hash_map::{DefaultHasher, Entry, Iter, IterMut, Values, ValuesMut}, HashMap, }; use crate::keyexpr_tree::*; -pub struct HashMapProvider; -impl IChildrenProvider for HashMapProvider { - type Assoc = HashMap; +pub struct HashMapProvider( + core::marker::PhantomData, +); +impl IChildrenProvider for HashMapProvider { + type Assoc = HashMap>; } #[cfg(not(feature = "std"))] diff --git a/commons/zenoh-keyexpr/src/keyexpr_tree/impls/keyed_set_impl.rs b/commons/zenoh-keyexpr/src/keyexpr_tree/impls/keyed_set_impl.rs index 3e77a1de76..90fddd45ae 100644 --- a/commons/zenoh-keyexpr/src/keyexpr_tree/impls/keyed_set_impl.rs +++ b/commons/zenoh-keyexpr/src/keyexpr_tree/impls/keyed_set_impl.rs @@ -12,11 +12,19 @@ // ZettaScale Zenoh Team, // +use core::hash::Hasher; +#[cfg(not(feature = "std"))] +use hashbrown::hash_map::DefaultHasher; +#[cfg(feature = "std")] +use std::collections::hash_map::DefaultHasher; + use crate::keyexpr_tree::*; use keyed_set::{KeyExtractor, KeyedSet}; -pub struct KeyedSetProvider; -impl IChildrenProvider for KeyedSetProvider { +pub struct KeyedSetProvider( + core::marker::PhantomData, +); +impl IChildrenProvider for KeyedSetProvider { type Assoc = KeyedSet; } #[derive(Debug, Default, Clone, Copy)] diff --git a/commons/zenoh-protocol/Cargo.toml b/commons/zenoh-protocol/Cargo.toml index 829c275804..07c11cb2fc 100644 --- a/commons/zenoh-protocol/Cargo.toml +++ b/commons/zenoh-protocol/Cargo.toml @@ -47,10 +47,11 @@ rand = { workspace = true, features = ["alloc", "getrandom"], optional = true } serde = { workspace = true, features = ["alloc"] } uhlc = { workspace = true, default-features = false } uuid = { workspace = true } # Needs a getrandom::getrandom() custom implementation on embedded (in root crate) -zenoh-buffers = { workspace = true, default-features = false } +zenoh-buffers = { workspace = true, default-features = false } zenoh-keyexpr = { workspace = true } zenoh-result = { workspace = true } # NOTE: May cause problems when testing no_std stuff. Check this tool: https://docs.rs/crate/cargo-no-dev-deps/0.1.0 [dev-dependencies] lazy_static = { workspace = true } +rand = { workspace = true, features = ["default"] } diff --git a/commons/zenoh-protocol/src/network/request.rs b/commons/zenoh-protocol/src/network/request.rs index 17bab1905d..9e0137ea3a 100644 --- a/commons/zenoh-protocol/src/network/request.rs +++ b/commons/zenoh-protocol/src/network/request.rs @@ -93,7 +93,7 @@ pub mod ext { impl TargetType { #[cfg(feature = "test")] pub fn rand() -> Self { - use rand::prelude::SliceRandom; + use rand::prelude::*; let mut rng = rand::thread_rng(); *[ From 2005568c1e6813386a2c845bb98aec91a6b812c2 Mon Sep 17 00:00:00 2001 From: Pierre Avital Date: Wed, 4 Oct 2023 11:54:59 +0200 Subject: [PATCH 2/3] fix complete_n a bit --- zenoh/src/net/routing/queries.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zenoh/src/net/routing/queries.rs b/zenoh/src/net/routing/queries.rs index 191c0a8071..c55cfc046c 100644 --- a/zenoh/src/net/routing/queries.rs +++ b/zenoh/src/net/routing/queries.rs @@ -2178,7 +2178,7 @@ pub fn route_query( ext_qos: ext::QoSType::request_default(), // TODO ext_tstamp: None, ext_nodeid: ext::NodeIdType { - node_id: context.map(|c| c.tree_id).unwrap_or(0) as u16, + node_id: context.unwrap_or(0), }, ext_target: *t, ext_budget: None, From 60b00f3fa0d688193328ccdd2e6fd5d26d7da67b Mon Sep 17 00:00:00 2001 From: Pierre Avital Date: Wed, 4 Oct 2023 14:11:47 +0200 Subject: [PATCH 3/3] fix no_std and transport_compression feature breaking compilation --- .../zenoh-keyexpr/src/keyexpr_tree/impls/hashmap_impl.rs | 6 +++++- .../zenoh-keyexpr/src/keyexpr_tree/impls/keyed_set_impl.rs | 4 +++- io/zenoh-transport/src/unicast/manager.rs | 4 ++++ io/zenoh-transport/src/unicast/universal/link.rs | 2 +- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/commons/zenoh-keyexpr/src/keyexpr_tree/impls/hashmap_impl.rs b/commons/zenoh-keyexpr/src/keyexpr_tree/impls/hashmap_impl.rs index f9bcdf799f..04a5d24201 100644 --- a/commons/zenoh-keyexpr/src/keyexpr_tree/impls/hashmap_impl.rs +++ b/commons/zenoh-keyexpr/src/keyexpr_tree/impls/hashmap_impl.rs @@ -14,8 +14,12 @@ use core::hash::Hasher; #[cfg(not(feature = "std"))] +// `SipHasher` is deprecated in favour of a symbol that only exists in `std` +#[allow(deprecated)] +use core::hash::SipHasher as DefaultHasher; +#[cfg(not(feature = "std"))] use hashbrown::{ - hash_map::{DefaultHasher, Entry, Iter, IterMut, Values, ValuesMut}, + hash_map::{Entry, Iter, IterMut, Values, ValuesMut}, HashMap, }; #[cfg(feature = "std")] diff --git a/commons/zenoh-keyexpr/src/keyexpr_tree/impls/keyed_set_impl.rs b/commons/zenoh-keyexpr/src/keyexpr_tree/impls/keyed_set_impl.rs index 90fddd45ae..0a4ce4f4b4 100644 --- a/commons/zenoh-keyexpr/src/keyexpr_tree/impls/keyed_set_impl.rs +++ b/commons/zenoh-keyexpr/src/keyexpr_tree/impls/keyed_set_impl.rs @@ -14,7 +14,9 @@ use core::hash::Hasher; #[cfg(not(feature = "std"))] -use hashbrown::hash_map::DefaultHasher; +// `SipHasher` is deprecated in favour of a symbol that only exists in `std` +#[allow(deprecated)] +use core::hash::SipHasher as DefaultHasher; #[cfg(feature = "std")] use std::collections::hash_map::DefaultHasher; diff --git a/io/zenoh-transport/src/unicast/manager.rs b/io/zenoh-transport/src/unicast/manager.rs index 384b992401..d7d79d5387 100644 --- a/io/zenoh-transport/src/unicast/manager.rs +++ b/io/zenoh-transport/src/unicast/manager.rs @@ -96,6 +96,8 @@ pub struct TransportManagerBuilderUnicast { pub(super) max_links: usize, #[cfg(feature = "shared-memory")] pub(super) is_shm: bool, + #[cfg(feature = "transport_compression")] + pub(super) is_compressed: bool, #[cfg(feature = "transport_auth")] pub(super) authenticator: Auth, pub(super) is_lowlatency: bool, @@ -251,6 +253,8 @@ impl Default for TransportManagerBuilderUnicast { max_links: *transport.max_links(), #[cfg(feature = "shared-memory")] is_shm: *shm.enabled(), + #[cfg(feature = "transport_compression")] + is_compressed: false, #[cfg(feature = "transport_auth")] authenticator: Auth::default(), is_lowlatency: *transport.lowlatency(), diff --git a/io/zenoh-transport/src/unicast/universal/link.rs b/io/zenoh-transport/src/unicast/universal/link.rs index 1128e8c2f9..8facc9b7b2 100644 --- a/io/zenoh-transport/src/unicast/universal/link.rs +++ b/io/zenoh-transport/src/unicast/universal/link.rs @@ -106,7 +106,7 @@ impl TransportLinkUnicast { }; #[cfg(all(feature = "unstable", feature = "transport_compression"))] - let is_compressed = self.transport.config.manager.config.unicast.is_compressed; + let is_compressed = self.transport.manager.config.unicast.is_compressed; // The pipeline let (producer, consumer) = TransmissionPipeline::make(config, priority_tx);