Skip to content

Commit 8ed4403

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. Instead, introduce a dummy feature that will automatically be picked up by doing 'cargo doc --all-features` (as docs.rs does), which then definitely kills the compile_error!(). Signed-off-by: Patrick Roy <[email protected]>
1 parent 94b86c6 commit 8ed4403

File tree

4 files changed

+25
-10
lines changed

4 files changed

+25
-10
lines changed

vhost-user-backend/Cargo.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@ 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"]
17+
DUMMY_FEATURE_disable_compile_error = ["vhost/DUMMY_FEATURE_disable_compile_error"]
1418

1519
[dependencies]
1620
libc = "0.2.39"
@@ -32,4 +36,6 @@ tempfile = "3.2.0"
3236
[package.metadata.cargo-all-features]
3337
skip_feature_sets = [
3438
["xen", "postcopy"]
35-
]
39+
]
40+
41+
denylist = ["DUMMY_FEATURE_disable_compile_error"]

vhost-user-backend/src/lib.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,14 @@ 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(feature = "DUMMY_FEATURE_disable_compile_error"),
44+
feature = "postcopy",
45+
feature = "xen"
46+
))]
4347
compile_error!("Both `postcopy` and `xen` features can not be enabled at the same time.");
4448

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

vhost/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ vhost-user-frontend = ["vhost-user"]
2525
vhost-user-backend = ["vhost-user"]
2626
xen = ["vm-memory/xen"]
2727
postcopy = []
28+
DUMMY_FEATURE_disable_compile_error = []
2829

2930
[dependencies]
3031
bitflags = "2.4"
@@ -43,4 +44,4 @@ skip_feature_sets = [
4344
["xen", "postcopy"]
4445
]
4546

46-
denylist = ["test_utils"]
47+
denylist = ["test_utils", "DUMMY_FEATURE_disable_compile_error"]

vhost/src/lib.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,14 @@ 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(feature = "DUMMY_FEATURE_disable_compile_error"),
59+
feature = "postcopy",
60+
feature = "xen"
61+
))]
5862
compile_error!("Both `postcopy` and `xen` features can not be enabled at the same time.");
5963

6064
/// Error codes for vhost operations

0 commit comments

Comments
 (0)