Skip to content

Commit eb9c470

Browse files
committed
fix cargo doc
Introduce a dummy feature to hack around `cargo doc --all-features` always hitting the compile_error!(...) in vhost/src/lib.rs about incompatible features. This is happening because when documenting vhost-user-backend, cargo does not pass --cfg doc to dependencies, meaning the cfg(not(doc)) attribute that is supposed to eliminate this compile_error!() invokation when building docs does not actually trigger. Hence cargo doc fails. Introduce a custom cfg, which we tell docs.rs to set during documentation build, which disables the compile_error!(). Our CI also sets this flag for the rustdoc step (via an ugly `sed` in the pipeline definition). Note that we need both cfg(not(doc)) and cfg(not(RUSTDOC_disable_compile_error)), because lib.rs gets processed twice, onces by rustc (where the --cfg is passed via RUSTFLAGS), and once by rustdoc itself, where RUSTFLAGS are ignored, and instead the cfg(doc) macro comes into play (but rustdoc is only ran on the crate for which we are actually generating docs, not the dependencies). Signed-off-by: Patrick Roy <[email protected]>
1 parent 94b86c6 commit eb9c470

File tree

4 files changed

+28
-9
lines changed

4 files changed

+28
-9
lines changed

vhost-user-backend/Cargo.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ repository = "https://github.com/rust-vmm/vhost"
88
edition = "2021"
99
license = "Apache-2.0"
1010

11+
[package.metadata.docs.rs]
12+
all-features = true
13+
1114
[features]
1215
xen = ["vm-memory/xen", "vhost/xen"]
1316
postcopy = ["vhost/postcopy", "userfaultfd"]
@@ -29,7 +32,10 @@ vhost = { path = "../vhost", version = "0.14.0", features = ["test-utils", "vhos
2932
vm-memory = { workspace = true, features = ["backend-mmap", "backend-atomic"] }
3033
tempfile = "3.2.0"
3134

35+
[lints.rust]
36+
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(RUSTDOC_disable_compile_error)'] }
37+
3238
[package.metadata.cargo-all-features]
3339
skip_feature_sets = [
3440
["xen", "postcopy"]
35-
]
41+
]

vhost-user-backend/src/lib.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,15 @@ pub use self::vring::{
3636
VringMutex, VringRwLock, VringState, VringStateGuard, VringStateMutGuard, VringT,
3737
};
3838

39-
/// Due to the way `xen` handles memory mappings we can not combine it with
40-
/// `postcopy` feature which relies on persistent memory mappings. Thus we
41-
/// disallow enabling both features at the same time.
42-
#[cfg(all(feature = "postcopy", feature = "xen"))]
39+
// Due to the way `xen` handles memory mappings we can not combine it with
40+
// `postcopy` feature which relies on persistent memory mappings. Thus we
41+
// disallow enabling both features at the same time.
42+
#[cfg(all(
43+
not(RUSTDOC_disable_compile_error),
44+
not(doc),
45+
feature = "postcopy",
46+
feature = "xen"
47+
))]
4348
compile_error!("Both `postcopy` and `xen` features can not be enabled at the same time.");
4449

4550
/// An alias for `GuestMemoryAtomic<GuestMemoryMmap<B>>` to simplify code.

vhost/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ vm-memory = { workspace = true, features=["backend-mmap"] }
3838
tempfile = "3.2.0"
3939
serial_test = "3.0"
4040

41+
[lints.rust]
42+
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(RUSTDOC_disable_compile_error)'] }
43+
4144
[package.metadata.cargo-all-features]
4245
skip_feature_sets = [
4346
["xen", "postcopy"]

vhost/src/lib.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,15 @@ pub mod vhost_user;
5151
#[cfg(feature = "vhost-vsock")]
5252
pub mod vsock;
5353

54-
/// Due to the way `xen` handles memory mappings we can not combine it with
55-
/// `postcopy` feature which relies on persistent memory mappings. Thus we
56-
/// disallow enabling both features at the same time.
57-
#[cfg(all(not(doc), feature = "postcopy", feature = "xen"))]
54+
// Due to the way `xen` handles memory mappings we can not combine it with
55+
// `postcopy` feature which relies on persistent memory mappings. Thus we
56+
// disallow enabling both features at the same time.
57+
#[cfg(all(
58+
not(RUSTDOC_disable_compile_error),
59+
not(doc),
60+
feature = "postcopy",
61+
feature = "xen"
62+
))]
5863
compile_error!("Both `postcopy` and `xen` features can not be enabled at the same time.");
5964

6065
/// Error codes for vhost operations

0 commit comments

Comments
 (0)