From a602125d97271c0eb860a1d3b6f1b2a434ae4626 Mon Sep 17 00:00:00 2001 From: fanyang89 Date: Wed, 1 Jul 2026 23:54:50 +0800 Subject: [PATCH] chore(easytier): gate hotpath-rs 0.19 dependency and off-mode shim Re-enable the hotpath profiler as an optional dependency gated behind the feature (default off). In off builds the crate stays out of the dependency graph entirely: plus a local module provide no-op // macros so call sites compile unchanged. Also add a guarding the mutual exclusivity of with the / global allocators. --- easytier/Cargo.toml | 17 ++++++++++------ easytier/src/hotpath_off.rs | 40 +++++++++++++++++++++++++++++++++++++ easytier/src/lib.rs | 14 +++++++++++++ 3 files changed, 65 insertions(+), 6 deletions(-) create mode 100644 easytier/src/hotpath_off.rs diff --git a/easytier/Cargo.toml b/easytier/Cargo.toml index ed003b1f..0cfafad9 100644 --- a/easytier/Cargo.toml +++ b/easytier/Cargo.toml @@ -58,6 +58,8 @@ chrono = { version = "0.4.37", features = ["serde"] } guarden = "0.2" quanta = "0.12" +hotpath = { version = "0.19", default-features = false, optional = true } + delegate = "0.13.5" itertools = "0.14.0" @@ -410,11 +412,14 @@ tracing = ["tokio/tracing", "dep:console-subscriber"] magic-dns = ["dep:hickory-client", "dep:hickory-server"] faketcp = ["dep:flume"] zstd = ["dep:zstd"] -# Deprecated: hotpath profiling has been removed. These feature aliases are -# retained as no-ops so existing build scripts using `--features hotpath*` -# continue to work without pulling in any dependencies. -hotpath = [] -hotpath-cpu = ["hotpath"] -hotpath-alloc = ["hotpath"] +hotpath = [ + "dep:hotpath", + "hotpath/hotpath", + "hotpath/tokio", + "hotpath/parking_lot", + "hotpath/flume", +] +hotpath-cpu = ["hotpath", "hotpath/hotpath-cpu"] +hotpath-alloc = ["hotpath", "hotpath/hotpath-alloc"] # For Network Extension on macOS macos-ne = [] diff --git a/easytier/src/hotpath_off.rs b/easytier/src/hotpath_off.rs new file mode 100644 index 00000000..0ad97020 --- /dev/null +++ b/easytier/src/hotpath_off.rs @@ -0,0 +1,40 @@ +//! No-op stand-in for the `hotpath` macros used by this crate, selected when +//! the `hotpath` feature is disabled. +//! +//! Keeping `hotpath` as an optional dependency means default builds do not pull +//! the profiler (or any of its transitive dependencies) into the dependency +//! graph. These macros expand to their input unchanged, mirroring `hotpath`'s +//! own disabled mode so call sites compile identically with or without the +//! feature. +//! +//! The macros are `#[macro_export]`-ed so that `lib.rs`' `extern crate self as +//! hotpath` alias exposes them through the same `hotpath::...` paths used when +//! the feature is enabled. + +/// No-op mirroring `hotpath::channel!`: returns the channel expression +/// unchanged (dropping any optional trailing `label`/`log`/`capacity` args). +#[doc(hidden)] +#[macro_export] +macro_rules! channel { + ($expr:expr $(, $($rest:tt)*)?) => { + $expr + }; +} + +/// No-op mirroring `hotpath::mutex!`: returns the expression unchanged. +#[doc(hidden)] +#[macro_export] +macro_rules! mutex { + ($expr:expr $(, $($rest:tt)*)?) => { + $expr + }; +} + +/// No-op mirroring `hotpath::rw_lock!`: returns the expression unchanged. +#[doc(hidden)] +#[macro_export] +macro_rules! rw_lock { + ($expr:expr $(, $($rest:tt)*)?) => { + $expr + }; +} diff --git a/easytier/src/lib.rs b/easytier/src/lib.rs index 91c0a042..f2a814dd 100644 --- a/easytier/src/lib.rs +++ b/easytier/src/lib.rs @@ -5,6 +5,20 @@ use std::io; use clap::Command; use clap_complete::{Generator, Shell}; +// When the `hotpath` feature is off, alias the current crate as `hotpath` so +// call sites keep using `hotpath::...` paths, and provide a local no-op shim +// for the profiling macros. This keeps `hotpath` an optional dependency: the +// profiler is absent from the dependency graph entirely in default builds. +#[cfg(not(feature = "hotpath"))] +extern crate self as hotpath; +#[cfg(not(feature = "hotpath"))] +mod hotpath_off; + +// `hotpath-alloc` registers a global profiling allocator, which is mutually +// exclusive with the `jemalloc`/`mimalloc` global allocators. +#[cfg(all(feature = "hotpath-alloc", any(feature = "jemalloc", feature = "mimalloc")))] +compile_error!("feature `hotpath-alloc` cannot be enabled together with `jemalloc` or `mimalloc`"); + // Re-export `Instant` at the crate root so public APIs that expose it // (e.g. `Route::get_peer_info_last_update_time`) reference a deliberate // public type rather than leaking an inaccessible one.