Skip to content

Commit 23343a9

Browse files
barracelmeta-codesync[bot]
authored andcommitted
Elide stats_facebook from the stats crate in pure-glue
Summary: Drop the C++ `stats_facebook` backend from `common/rust/shed/stats` in a pure-`glue` build, so a `glue_mode[glue]` ancestor (clippy's `:clippy-glue` / `:clippy_cli`) sheds the fb303 `ServiceData` C++ closure — the runtime-closure win motivating the migration. Glue routing comes from the `stats_glue_backend` factory the consumer registers; this diff is what lets that build link no C++. Backward-compatible and opt-in: with no `glue_mode` modifier (every existing consumer) the `select()`s resolve to `DEFAULT` — `stats_facebook` stays and no `--cfg` is set — so behavior is unchanged. - `BUCK`: a `glue_mode[glue]` `select()` sets `--cfg=glue_mode="glue"`, and a second drops `//common/rust/shed/stats/facebook:stats_facebook` from `deps` (kept via `DEFAULT`). No `--check-cfg` is needed — the buck toolchain doesn't run strict cfg-checking, so the cfg is set without a declaration (verified: both modes build warning-free). - `src/lib.rs`: the only two `stats_facebook` references (`get_default_stats_manager_factory`, `create_singleton_counter`) get a `glue_mode = "glue"` arm routing to the existing no-op, mirroring the `not(fbcode_build)` path. - `Cargo.toml` (+ autocargo manifest): declare `glue_mode` in the OSS `unexpected_cfgs` check-cfg so the cargo build doesn't warn on the new arms (cargo, unlike buck, runs that lint). Pure-`glue` clippy (`:clippy-glue`) builds green with this; `inproc` / `inproc_and_glue` are untouched. Reviewed By: mzlee Differential Revision: D109851332 fbshipit-source-id: 337fee736173f694e6690ab2751ed312a491bbe6
1 parent 8de131b commit 23343a9

3 files changed

Lines changed: 22 additions & 8 deletions

File tree

common/rust/shed/stats/BUCK

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ load("@fbsource//tools/build_defs:rust_library.bzl", "rust_library")
22

33
oncall("autocargo")
44

5+
# Taken only when a binary opts into the `glue_mode[glue]` modifier.
6+
_GLUE_ONLY = "fbcode//hub_infra/build_defs/glue_mode:glue_mode[glue]"
7+
58
rust_library(
69
name = "stats",
710
srcs = glob([
@@ -12,7 +15,10 @@ rust_library(
1215
"lints": {
1316
"rust": {
1417
"unexpected_cfgs": {
15-
"check-cfg": ["cfg(fbcode_build)"],
18+
"check-cfg": [
19+
"cfg(fbcode_build)",
20+
'cfg(stats_backend, values("noop"))',
21+
],
1622
"level": "warn",
1723
},
1824
},
@@ -22,15 +28,23 @@ rust_library(
2228
},
2329
},
2430
},
31+
# Pure-`glue` drops the C++ backend (sets the neutral `stats_backend="noop"`
32+
# cfg the source reads); no modifier = unchanged.
33+
rustc_flags = select({
34+
"DEFAULT": [],
35+
_GLUE_ONLY: ['--cfg=stats_backend="noop"'],
36+
}),
2537
deps = [
2638
"fbsource//third-party/rust:futures",
2739
"fbsource//third-party/rust:tokio",
2840
"fbsource//third-party/rust:tokio-stream",
2941
":stats_traits",
3042
"//common/rust/shed/fbinit:fbinit",
3143
"//common/rust/shed/perthread:perthread",
32-
"//common/rust/shed/stats/facebook:stats_facebook",
33-
],
44+
] + select({
45+
"DEFAULT": ["//common/rust/shed/stats/facebook:stats_facebook"],
46+
_GLUE_ONLY: [],
47+
}),
3448
)
3549

3650
rust_library(

common/rust/shed/stats/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ tokio = { version = "1.52.3", features = ["full", "test-util", "tracing"] }
1919
tokio-stream = { version = "0.1.18", features = ["fs", "io-util", "net", "signal", "sync", "time"] }
2020

2121
[lints.rust]
22-
unexpected_cfgs = { level = "warn", check-cfg = ["cfg(fbcode_build)"]}
22+
unexpected_cfgs = { level = "warn", check-cfg = ["cfg(fbcode_build)", 'cfg(stats_backend, values("noop"))']}

common/rust/shed/stats/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ pub fn create_stats_manager() -> BoxStatsManager {
9090
}
9191

9292
fn get_default_stats_manager_factory() -> Box<dyn StatsManagerFactory + Send + Sync> {
93-
#[cfg(fbcode_build)]
93+
#[cfg(all(fbcode_build, not(stats_backend = "noop")))]
9494
{
9595
Box::new(::stats_facebook::ThreadLocalStatsFactory)
9696
}
97-
#[cfg(not(fbcode_build))]
97+
#[cfg(any(not(fbcode_build), stats_backend = "noop"))]
9898
{
9999
Box::new(crate::noop_stats::NoopStatsFactory)
100100
}
@@ -104,12 +104,12 @@ fn get_default_stats_manager_factory() -> Box<dyn StatsManagerFactory + Send + S
104104
/// You probably don't have to use this function, it is made public so that it
105105
/// might be used by the macros in this crate. It creates a new SingletonCounter.
106106
pub fn create_singleton_counter(name: String) -> BoxSingletonCounter {
107-
#[cfg(fbcode_build)]
107+
#[cfg(all(fbcode_build, not(stats_backend = "noop")))]
108108
{
109109
Box::new(::stats_facebook::singleton_counter::ServiceDataSingletonCounter::new(name))
110110
}
111111

112-
#[cfg(not(fbcode_build))]
112+
#[cfg(any(not(fbcode_build), stats_backend = "noop"))]
113113
{
114114
let _ = name;
115115
Box::new(crate::noop_stats::Noop)

0 commit comments

Comments
 (0)