fix cargo doc CI step

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 <patrick.roy@linux.dev>
This commit is contained in:
Patrick Roy 2025-10-01 14:32:43 +01:00 committed by Stefano Garzarella
parent b222aac3b9
commit f979631610
4 changed files with 25 additions and 9 deletions

View file

@ -29,7 +29,10 @@ vhost = { path = "../vhost", version = "0.14.0", features = ["test-utils", "vhos
vm-memory = { workspace = true, features = ["backend-mmap", "backend-atomic"] } vm-memory = { workspace = true, features = ["backend-mmap", "backend-atomic"] }
tempfile = "3.2.0" tempfile = "3.2.0"
[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(RUSTDOC_disable_feature_compat_errors)'] }
[package.metadata.cargo-all-features] [package.metadata.cargo-all-features]
skip_feature_sets = [ skip_feature_sets = [
["xen", "postcopy"] ["xen", "postcopy"]
] ]

View file

@ -36,10 +36,15 @@ pub use self::vring::{
VringMutex, VringRwLock, VringState, VringStateGuard, VringStateMutGuard, VringT, VringMutex, VringRwLock, VringState, VringStateGuard, VringStateMutGuard, VringT,
}; };
/// Due to the way `xen` handles memory mappings we can not combine it with // Due to the way `xen` handles memory mappings we can not combine it with
/// `postcopy` feature which relies on persistent memory mappings. Thus we // `postcopy` feature which relies on persistent memory mappings. Thus we
/// disallow enabling both features at the same time. // disallow enabling both features at the same time.
#[cfg(all(feature = "postcopy", feature = "xen"))] #[cfg(all(
not(RUSTDOC_disable_feature_compat_errors),
not(doc),
feature = "postcopy",
feature = "xen"
))]
compile_error!("Both `postcopy` and `xen` features can not be enabled at the same time."); compile_error!("Both `postcopy` and `xen` features can not be enabled at the same time.");
/// An alias for `GuestMemoryAtomic<GuestMemoryMmap<B>>` to simplify code. /// An alias for `GuestMemoryAtomic<GuestMemoryMmap<B>>` to simplify code.

View file

@ -38,6 +38,9 @@ vm-memory = { workspace = true, features=["backend-mmap"] }
tempfile = "3.2.0" tempfile = "3.2.0"
serial_test = "3.0" serial_test = "3.0"
[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(RUSTDOC_disable_feature_compat_errors)'] }
[package.metadata.cargo-all-features] [package.metadata.cargo-all-features]
skip_feature_sets = [ skip_feature_sets = [
["xen", "postcopy"] ["xen", "postcopy"]

View file

@ -51,10 +51,15 @@ pub mod vhost_user;
#[cfg(feature = "vhost-vsock")] #[cfg(feature = "vhost-vsock")]
pub mod vsock; pub mod vsock;
/// Due to the way `xen` handles memory mappings we can not combine it with // Due to the way `xen` handles memory mappings we can not combine it with
/// `postcopy` feature which relies on persistent memory mappings. Thus we // `postcopy` feature which relies on persistent memory mappings. Thus we
/// disallow enabling both features at the same time. // disallow enabling both features at the same time.
#[cfg(all(not(doc), feature = "postcopy", feature = "xen"))] #[cfg(all(
not(RUSTDOC_disable_feature_compat_errors),
not(doc),
feature = "postcopy",
feature = "xen"
))]
compile_error!("Both `postcopy` and `xen` features can not be enabled at the same time."); compile_error!("Both `postcopy` and `xen` features can not be enabled at the same time.");
/// Error codes for vhost operations /// Error codes for vhost operations