Skip to content

Commit

Permalink
Define expected cfgs for Cargo builds
Browse files Browse the repository at this point in the history
Summary:
Context: see https://blog.rust-lang.org/2024/07/25/Rust-1.80.0.html#checked-cfg-names-and-values

Warnings from `#[cfg(fbcode_build)]` was one of the common issues causing Cargo-based CI jobs to fail in {D60317004}. From **sapling-oss-unix**:

```lang=text,counterexample
warning: unexpected `cfg` condition name: `fbcode_build`
  --> /data/sandcastle/boxes/eden-trunk-hg-fbcode-fbsource/fbcode/common/rust/shed/hostcaps/src/lib.rs:12:7
   |
12 | #[cfg(fbcode_build)]
   |       ^^^^^^^^^^^^
   |
   = help: expected names are: `clippy`, `debug_assertions`, `doc`, `docsrs`, `doctest`, `feature`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `rustfmt`, `sanitize`, `sanitizer_cfi_generalize_pointers`, `sanitizer_cfi_normalize_integers`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `ub_checks`, `unix`, and `windows`
   = help: consider using a Cargo feature instead
   = help: or consider adding in `Cargo.toml` the `check-cfg` lint config for the lint:
            [lints.rust]
            unexpected_cfgs = { level = "warn", check-cfg = ['cfg(fbcode_build)'] }
   = help: or consider adding `println!("cargo::rustc-check-cfg=cfg(fbcode_build)");` to the top of the `build.rs`
   = note: see <https://doc.rust-lang.org/.../check-cfg/cargo-specifics.html> for more information about checking conditional configuration
   = note: `#[warn(unexpected_cfgs)]` on by default
```

I thought about having Autocargo unconditionally emit `check-cfg = ["cfg(fbcode_build)"]` into every generated Cargo.toml, but that's even more noisy and this cfg isn't too widely used to configure one at a time.

Reviewed By: diliop

Differential Revision: D60706859

fbshipit-source-id: f9a533af46ccc27682b9e1702c61f3838a224c05
  • Loading branch information
David Tolnay authored and facebook-github-bot committed Aug 5, 2024
1 parent c26a9d4 commit 9d41d25
Show file tree
Hide file tree
Showing 32 changed files with 191 additions and 0 deletions.
8 changes: 8 additions & 0 deletions shed/cached_config/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ rust_library(
srcs = glob(["src/**/*.rs"]),
autocargo = {
"cargo_toml_config": {
"lints": {
"rust": {
"unexpected_cfgs": {
"check-cfg": ["cfg(fbcode_build)"],
"level": "warn",
},
},
},
"package": {
"description": "Helpers to maintain cached set of configs",
},
Expand Down
3 changes: 3 additions & 0 deletions shed/cached_config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ tokio = { version = "1.37.0", features = ["full", "test-util", "tracing"] }

[dev-dependencies]
serde_derive = "1.0.185"

[lints]
rust = { unexpected_cfgs = { check-cfg = ["cfg(fbcode_build)"], level = "warn" } }
8 changes: 8 additions & 0 deletions shed/cachelib_stub/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ rust_library(
"fbsource//third-party/rust:bytes",
],
},
"lints": {
"rust": {
"unexpected_cfgs": {
"check-cfg": ["cfg(fbcode_build)"],
"level": "warn",
},
},
},
"package": {
"description": "Cache library",
},
Expand Down
3 changes: 3 additions & 0 deletions shed/cachelib_stub/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ license = "MIT OR Apache-2.0"
abomonation = { version = "0.7", features = ["smallvec"] }
anyhow = "1.0.75"
bytes = { version = "1.6.0", features = ["serde"] }

[lints]
rust = { unexpected_cfgs = { check-cfg = ["cfg(fbcode_build)"], level = "warn" } }
8 changes: 8 additions & 0 deletions shed/failure_ext/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ rust_library(
srcs = glob(["src/**/*.rs"]),
autocargo = {
"cargo_toml_config": {
"lints": {
"rust": {
"unexpected_cfgs": {
"check-cfg": ["cfg(fbcode_build)"],
"level": "warn",
},
},
},
"package": {
"description": "Extensions to the anyhow crate",
},
Expand Down
3 changes: 3 additions & 0 deletions shed/failure_ext/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ slog = { version = "2.7", features = ["max_level_trace", "nested-values"] }

[dev-dependencies]
thiserror = "1.0.49"

[lints]
rust = { unexpected_cfgs = { check-cfg = ["cfg(fbcode_build)"], level = "warn" } }
8 changes: 8 additions & 0 deletions shed/fbinit/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ rust_library(
"fbsource//third-party/rust:quickcheck",
],
},
"lints": {
"rust": {
"unexpected_cfgs": {
"check-cfg": ["cfg(fbcode_build)"],
"level": "warn",
},
},
},
"package": {
"description": "Facebook init token",
"version": "0.1.2",
Expand Down
3 changes: 3 additions & 0 deletions shed/fbinit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ quickcheck = "1.0"

[dev-dependencies]
fbinit-tokio = { version = "0.1.2", path = "fbinit-tokio" }

[lints]
rust = { unexpected_cfgs = { check-cfg = ["cfg(fbcode_build)"], level = "warn" } }
12 changes: 12 additions & 0 deletions shed/hostcaps/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ oncall("autocargo")
rust_library(
name = "hostcaps",
srcs = glob(["src/**/*.rs"]),
autocargo = {
"cargo_toml_config": {
"lints": {
"rust": {
"unexpected_cfgs": {
"check-cfg": ["cfg(fbcode_build)"],
"level": "warn",
},
},
},
},
},
crate_root = "src/lib.rs",
deps = [
"fbsource//third-party/rust:once_cell",
Expand Down
3 changes: 3 additions & 0 deletions shed/hostcaps/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ path = "src/bin/test.rs"

[dependencies]
once_cell = "1.12"

[lints]
rust = { unexpected_cfgs = { check-cfg = ["cfg(fbcode_build)"], level = "warn" } }
8 changes: 8 additions & 0 deletions shed/hostname/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ rust_library(
("real_hostname", "fbsource//third-party/rust:hostname"),
],
},
"lints": {
"rust": {
"unexpected_cfgs": {
"check-cfg": ["cfg(fbcode_build)"],
"level": "warn",
},
},
},
"package": {
"description": "Crate for getting hostname",
},
Expand Down
3 changes: 3 additions & 0 deletions shed/hostname/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ license = "MIT OR Apache-2.0"
[dependencies]
anyhow = "1.0.75"
real_hostname = { package = "hostname", version = "0.3" }

[lints]
rust = { unexpected_cfgs = { check-cfg = ["cfg(fbcode_build)"], level = "warn" } }
8 changes: 8 additions & 0 deletions shed/justknobs_stub/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ rust_library(
srcs = glob(["src/*.rs"]),
autocargo = {
"cargo_toml_config": {
"lints": {
"rust": {
"unexpected_cfgs": {
"check-cfg": ["cfg(fbcode_build)"],
"level": "warn",
},
},
},
"package": {
"description": "Client for accessing JustKnobs. Noop crate for now",
},
Expand Down
3 changes: 3 additions & 0 deletions shed/justknobs_stub/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@ tokio = { version = "1.37.0", features = ["full", "test-util", "tracing"] }
fbinit = { version = "0.1.2", path = "../fbinit" }
maplit = "1.0"
slog_glog_fmt = { version = "0.1.0", path = "../slog_glog_fmt" }

[lints]
rust = { unexpected_cfgs = { check-cfg = ["cfg(fbcode_build)"], level = "warn" } }
8 changes: 8 additions & 0 deletions shed/memcache_stub/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ rust_library(
":memcache_common",
],
},
"lints": {
"rust": {
"unexpected_cfgs": {
"check-cfg": ["cfg(fbcode_build)"],
"level": "warn",
},
},
},
"package": {
"description": "Client for accessing Memcache. Noop crate for now",
},
Expand Down
3 changes: 3 additions & 0 deletions shed/memcache_stub/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ license = "MIT OR Apache-2.0"

[dependencies]
memcache_common = { version = "0.1.0", path = "common" }

[lints]
rust = { unexpected_cfgs = { check-cfg = ["cfg(fbcode_build)"], level = "warn" } }
8 changes: 8 additions & 0 deletions shed/ods/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ rust_library(
srcs = glob(["src/**/*.rs"]),
autocargo = {
"cargo_toml_config": {
"lints": {
"rust": {
"unexpected_cfgs": {
"check-cfg": ["cfg(fbcode_build)"],
"level": "warn",
},
},
},
"package": {
"description": "Library that points to meta specific ods for fbcode builds and to the stub for non-fbcode builds",
},
Expand Down
3 changes: 3 additions & 0 deletions shed/ods/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ license = "MIT OR Apache-2.0"
[dependencies]
anyhow = "1.0.75"
fbinit = { version = "0.1.2", path = "../fbinit" }

[lints]
rust = { unexpected_cfgs = { check-cfg = ["cfg(fbcode_build)"], level = "warn" } }
8 changes: 8 additions & 0 deletions shed/panichandler/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ rust_library(
srcs = glob(["src/*.rs"]),
autocargo = {
"cargo_toml_config": {
"lints": {
"rust": {
"unexpected_cfgs": {
"check-cfg": ["cfg(fbcode_build)"],
"level": "warn",
},
},
},
"package": {
"description": "Makes it easier to define a handler for panics",
},
Expand Down
3 changes: 3 additions & 0 deletions shed/panichandler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,6 @@ libc = "0.2.139"

[target.'cfg(target_os = "macos")'.dependencies]
libc = "0.2.139"

[lints]
rust = { unexpected_cfgs = { check-cfg = ["cfg(fbcode_build)"], level = "warn" } }
8 changes: 8 additions & 0 deletions shed/scuba_stub/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ rust_library(
"//common/rust/shed/scuba_sample:scuba_sample",
],
},
"lints": {
"rust": {
"unexpected_cfgs": {
"check-cfg": ["cfg(fbcode_build)"],
"level": "warn",
},
},
},
"package": {
"description": "Stub for scuba client",
},
Expand Down
3 changes: 3 additions & 0 deletions shed/scuba_stub/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ license = "MIT OR Apache-2.0"

[dependencies]
scuba_sample = { version = "0.1.0", path = "../scuba_sample" }

[lints]
rust = { unexpected_cfgs = { check-cfg = ["cfg(fbcode_build)"], level = "warn" } }
8 changes: 8 additions & 0 deletions shed/secure_utils/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ rust_library(
srcs = glob(["src/**/*.rs"]),
autocargo = {
"cargo_toml_config": {
"lints": {
"rust": {
"unexpected_cfgs": {
"check-cfg": ["cfg(fbcode_build)"],
"level": "warn",
},
},
},
"package": {
"description": "Crate with useful security utilities",
},
Expand Down
3 changes: 3 additions & 0 deletions shed/secure_utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ openssl-sys = "0.9.97"
serde = { version = "1.0.185", features = ["derive", "rc"] }
serde_json = { version = "1.0.100", features = ["float_roundtrip", "unbounded_depth"] }
slog = { version = "2.7", features = ["max_level_trace", "nested-values"] }

[lints]
rust = { unexpected_cfgs = { check-cfg = ["cfg(fbcode_build)"], level = "warn" } }
16 changes: 16 additions & 0 deletions shed/services/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ rust_library(
"//common/rust/shed/fbinit:fbinit",
],
},
"lints": {
"rust": {
"unexpected_cfgs": {
"check-cfg": ["cfg(fbcode_build)"],
"level": "warn",
},
},
},
"package": {
"description": "Stubs for facebook services",
},
Expand All @@ -38,6 +46,14 @@ rust_library(
srcs = glob(["common/**/*.rs"]),
autocargo = {
"cargo_toml_config": {
"lints": {
"rust": {
"unexpected_cfgs": {
"check-cfg": ["cfg(fbcode_build)"],
"level": "warn",
},
},
},
"package": {
"description": "Common code for stubbed facebook services",
"homepage": "https://github.com/facebookexperimental/rust-shed/",
Expand Down
3 changes: 3 additions & 0 deletions shed/services/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ license = "MIT OR Apache-2.0"
[dependencies]
fbinit = { version = "0.1.2", path = "../fbinit" }
services_common = { version = "0.1.0", path = "common" }

[lints]
rust = { unexpected_cfgs = { check-cfg = ["cfg(fbcode_build)"], level = "warn" } }
3 changes: 3 additions & 0 deletions shed/services/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ path = "lib.rs"
[dependencies]
cxx = "1.0.119"
thiserror = "1.0.49"

[lints]
rust = { unexpected_cfgs = { check-cfg = ["cfg(fbcode_build)"], level = "warn" } }
16 changes: 16 additions & 0 deletions shed/sql/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ rust_library(
"mysql_common/default",
],
},
"lints": {
"rust": {
"unexpected_cfgs": {
"check-cfg": ["cfg(fbcode_build)"],
"level": "warn",
},
},
},
"package": {
"description": "Crate for accessing sql databases",
},
Expand Down Expand Up @@ -71,6 +79,14 @@ rust_library(
"features": {
"default": ["rusqlite/bundled"],
},
"lints": {
"rust": {
"unexpected_cfgs": {
"check-cfg": ["cfg(fbcode_build)"],
"level": "warn",
},
},
},
"package": {
"description": "Common definitions for sql crate",
"readme": "../../../README.md",
Expand Down
3 changes: 3 additions & 0 deletions shed/sql/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ tokio = { version = "1.37.0", features = ["full", "test-util", "tracing"] }

[features]
default = ["mysql_common/chrono", "mysql_common/default"]

[lints]
rust = { unexpected_cfgs = { check-cfg = ["cfg(fbcode_build)"], level = "warn" } }
3 changes: 3 additions & 0 deletions shed/sql/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,6 @@ sql_tests_lib = { version = "0.1.0", path = "../tests_lib" }

[features]
default = ["rusqlite/bundled"]

[lints]
rust = { unexpected_cfgs = { check-cfg = ["cfg(fbcode_build)"], level = "warn" } }
8 changes: 8 additions & 0 deletions shed/stats/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ rust_library(
]),
autocargo = {
"cargo_toml_config": {
"lints": {
"rust": {
"unexpected_cfgs": {
"check-cfg": ["cfg(fbcode_build)"],
"level": "warn",
},
},
},
"package": {
"description": "Stats library",
},
Expand Down
3 changes: 3 additions & 0 deletions shed/stats/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ perthread = { version = "0.1.0", path = "../perthread" }
stats_traits = { version = "0.1.0", path = "traits" }
tokio = { version = "1.37.0", features = ["full", "test-util", "tracing"] }
tokio-stream = { version = "0.1.14", features = ["fs", "io-util", "net", "signal", "sync", "time"] }

[lints]
rust = { unexpected_cfgs = { check-cfg = ["cfg(fbcode_build)"], level = "warn" } }

0 comments on commit 9d41d25

Please sign in to comment.