Skip to content

Commit 02cae1b

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). This cfg is also set by rust-vmm-ci for the cargo doc step. Note that we need both cfg(not(doc)) and cfg(not(RUTSDOC_disable_feature_compat_errors)), 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 f22cc23 commit 02cae1b

File tree

4 files changed

+30
-9
lines changed

4 files changed

+30
-9
lines changed

vhost-user-backend/Cargo.toml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ 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+
rustc-args = ['--cfg RUTSDOC_disable_feature_compat_errors']
14+
1115
[features]
1216
xen = ["vm-memory/xen", "vhost/xen"]
1317
postcopy = ["vhost/postcopy", "userfaultfd"]
@@ -29,7 +33,10 @@ vhost = { path = "../vhost", version = "0.14.0", features = ["test-utils", "vhos
2933
vm-memory = { workspace = true, features = ["backend-mmap", "backend-atomic"] }
3034
tempfile = "3.2.0"
3135

36+
[lints.rust]
37+
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(RUTSDOC_disable_feature_compat_errors)'] }
38+
3239
[package.metadata.cargo-all-features]
3340
skip_feature_sets = [
3441
["xen", "postcopy"]
35-
]
42+
]

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(RUTSDOC_disable_feature_compat_errors),
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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ edition = "2021"
1212

1313
[package.metadata.docs.rs]
1414
all-features = true
15+
rustc-args = ['--cfg RUTSDOC_disable_feature_compat_errors']
1516

1617
[features]
1718
default = []
@@ -38,6 +39,9 @@ vm-memory = { workspace = true, features=["backend-mmap"] }
3839
tempfile = "3.2.0"
3940
serial_test = "3.0"
4041

42+
[lints.rust]
43+
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(RUTSDOC_disable_feature_compat_errors)'] }
44+
4145
[package.metadata.cargo-all-features]
4246
skip_feature_sets = [
4347
["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(RUTSDOC_disable_feature_compat_errors),
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)