Skip to content

Commit 5adc9e8

Browse files
authored
Merge pull request #2995 from dtolnay/rustdocflags
Workaround for RUSTDOCFLAGS='--cfg=docsrs'
2 parents 415d9fc + ab58178 commit 5adc9e8

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

serde/build.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ use serde_core::__private$$ as serde_core_private;
1919
fn main() {
2020
println!("cargo:rerun-if-changed=build.rs");
2121

22-
if env::var_os("DOCS_RS").is_some() {
23-
println!("cargo:rustc-cfg=no_serde_core");
24-
}
22+
println!("cargo:rustc-cfg=if_docsrs_then_no_serde_core");
2523

2624
let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());
2725
let patch_version = env::var("CARGO_PKG_VERSION_PATCH").unwrap();
@@ -35,12 +33,12 @@ fn main() {
3533

3634
if minor >= 77 {
3735
println!("cargo:rustc-check-cfg=cfg(feature, values(\"result\"))");
36+
println!("cargo:rustc-check-cfg=cfg(if_docsrs_then_no_serde_core)");
3837
println!("cargo:rustc-check-cfg=cfg(no_core_cstr)");
3938
println!("cargo:rustc-check-cfg=cfg(no_core_error)");
4039
println!("cargo:rustc-check-cfg=cfg(no_core_net)");
4140
println!("cargo:rustc-check-cfg=cfg(no_core_num_saturating)");
4241
println!("cargo:rustc-check-cfg=cfg(no_diagnostic_namespace)");
43-
println!("cargo:rustc-check-cfg=cfg(no_serde_core)");
4442
println!("cargo:rustc-check-cfg=cfg(no_serde_derive)");
4543
println!("cargo:rustc-check-cfg=cfg(no_std_atomic)");
4644
println!("cargo:rustc-check-cfg=cfg(no_std_atomic64)");

serde_core/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ fn main() {
2929
};
3030

3131
if minor >= 77 {
32+
println!("cargo:rustc-check-cfg=cfg(if_docsrs_then_no_serde_core)");
3233
println!("cargo:rustc-check-cfg=cfg(no_core_cstr)");
3334
println!("cargo:rustc-check-cfg=cfg(no_core_error)");
3435
println!("cargo:rustc-check-cfg=cfg(no_core_net)");
3536
println!("cargo:rustc-check-cfg=cfg(no_core_num_saturating)");
3637
println!("cargo:rustc-check-cfg=cfg(no_diagnostic_namespace)");
37-
println!("cargo:rustc-check-cfg=cfg(no_serde_core)");
3838
println!("cargo:rustc-check-cfg=cfg(no_serde_derive)");
3939
println!("cargo:rustc-check-cfg=cfg(no_std_atomic)");
4040
println!("cargo:rustc-check-cfg=cfg(no_std_atomic64)");

serde_core/src/crate_root.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,12 @@ macro_rules! crate_root {
132132
};
133133
}
134134

135-
#[cfg_attr(no_serde_core, path = "core/de/mod.rs")]
135+
#[cfg_attr(all(docsrs, if_docsrs_then_no_serde_core), path = "core/de/mod.rs")]
136136
pub mod de;
137-
#[cfg_attr(no_serde_core, path = "core/ser/mod.rs")]
137+
#[cfg_attr(all(docsrs, if_docsrs_then_no_serde_core), path = "core/ser/mod.rs")]
138138
pub mod ser;
139139

140-
#[cfg_attr(no_serde_core, path = "core/format.rs")]
140+
#[cfg_attr(all(docsrs, if_docsrs_then_no_serde_core), path = "core/format.rs")]
141141
mod format;
142142

143143
#[doc(inline)]
@@ -147,7 +147,10 @@ macro_rules! crate_root {
147147

148148
// Used by generated code. Not public API.
149149
#[doc(hidden)]
150-
#[cfg_attr(no_serde_core, path = "core/private/mod.rs")]
150+
#[cfg_attr(
151+
all(docsrs, if_docsrs_then_no_serde_core),
152+
path = "core/private/mod.rs"
153+
)]
151154
mod private;
152155

153156
// Used by declarative macro generated code. Not public API.
@@ -162,7 +165,7 @@ macro_rules! crate_root {
162165
include!(concat!(env!("OUT_DIR"), "/private.rs"));
163166

164167
#[cfg(all(not(feature = "std"), no_core_error))]
165-
#[cfg_attr(no_serde_core, path = "core/std_error.rs")]
168+
#[cfg_attr(all(docsrs, if_docsrs_then_no_serde_core), path = "core/std_error.rs")]
166169
mod std_error;
167170
};
168171
}

0 commit comments

Comments
 (0)