From: Marc-André Lureau <marcandre.lureau@redhat.com>
Allow to generate all --cfg flags, regardless of Cargo.toml content.
We can't easily list and include all the features used by QAPI types.
Access via #[cfg()] then requires #![allow(unexpected_cfgs)].
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
scripts/rust/rustc_args.py | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/scripts/rust/rustc_args.py b/scripts/rust/rustc_args.py
index 63b0748e0d3..c70b95b8bed 100644
--- a/scripts/rust/rustc_args.py
+++ b/scripts/rust/rustc_args.py
@@ -116,7 +116,7 @@ def generate_lint_flags(cargo_toml: CargoTOML, strict_lints: bool) -> Iterable[s
yield from lint.flags
-def generate_cfg_flags(header: str, cargo_toml: CargoTOML) -> Iterable[str]:
+def generate_cfg_flags(header: str, cargo_toml: Optional[CargoTOML]) -> Iterable[str]:
"""Converts defines from config[..].h headers to rustc --cfg flags."""
with open(header, encoding="utf-8") as cfg:
@@ -125,8 +125,9 @@ def generate_cfg_flags(header: str, cargo_toml: CargoTOML) -> Iterable[str]:
cfg_list = []
for cfg in config:
name = cfg[0]
- if f'cfg({name})' not in cargo_toml.check_cfg:
- continue
+ if cargo_toml:
+ if f'cfg({name})' not in cargo_toml.check_cfg:
+ continue
if len(cfg) >= 2 and cfg[1] != "1":
continue
cfg_list.append("--cfg")
@@ -194,6 +195,13 @@ def main() -> None:
help="apply stricter checks (for nightly Rust)",
default=False,
)
+ parser.add_argument(
+ "--no-strict-cfg",
+ help="only generate expected cfg",
+ action="store_false",
+ dest="strict_cfg",
+ default=True,
+ )
args = parser.parse_args()
if args.verbose:
logging.basicConfig(level=logging.DEBUG)
@@ -224,7 +232,7 @@ def main() -> None:
print(f'cfg(feature,values("{feature}"))')
for header in args.config_headers:
- for tok in generate_cfg_flags(header, cargo_toml):
+ for tok in generate_cfg_flags(header, cargo_toml if args.strict_cfg else None):
print(tok)
--
2.51.0