From a88a3fbff4aa2fdb7ebbab0e7c90a9e9a5a5fbb9 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Fri, 20 Dec 2024 13:40:23 +0100 Subject: [PATCH] rust: add warning_level=0 to downloaded Cargo subprojects This adds --cap-lints allow, matching how Cargo builds them. In the case of Cargo, this is only applied to non-path dependencies. Without this change, clippy will complain about dependencies as well. Signed-off-by: Paolo Bonzini --- docs/markdown/snippets/cargo_cap_lints.md | 8 ++++++++ mesonbuild/cargo/interpreter.py | 15 ++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 docs/markdown/snippets/cargo_cap_lints.md diff --git a/docs/markdown/snippets/cargo_cap_lints.md b/docs/markdown/snippets/cargo_cap_lints.md new file mode 100644 index 000000000000..9623ae157209 --- /dev/null +++ b/docs/markdown/snippets/cargo_cap_lints.md @@ -0,0 +1,8 @@ +## `--cap-lints allow` used for Cargo subprojects + +Similar to Cargo itself, all downloaded Cargo subprojects automatically +add the `--cap-lints allow` compiler argument, thus hiding any warnings +from the compiler. + +Related to this, `warning_level=0` now translates into `--cap-lints allow` +for Rust targets instead of `-A warnings`. diff --git a/mesonbuild/cargo/interpreter.py b/mesonbuild/cargo/interpreter.py index 53c0a8095e0a..af272a86fb04 100644 --- a/mesonbuild/cargo/interpreter.py +++ b/mesonbuild/cargo/interpreter.py @@ -459,8 +459,9 @@ def _extra_deps_varname() -> str: class PackageState: - def __init__(self, manifest: Manifest) -> None: + def __init__(self, manifest: Manifest, downloaded: bool) -> None: self.manifest = manifest + self.downloaded = downloaded self.features: T.Set[str] = set() self.required_deps: T.Set[str] = set() self.optional_deps_features: T.Dict[str, T.Set[str]] = collections.defaultdict(set) @@ -520,7 +521,10 @@ def _fetch_package(self, package_name: str, api: str) -> T.Tuple[PackageState, b subprojects_dir = os.path.join(subdir, 'subprojects') self.environment.wrap_resolver.load_and_merge(subprojects_dir, T.cast('SubProject', meson_depname)) manifest = self._load_manifest(subdir) - pkg = PackageState(manifest) + downloaded = \ + meson_depname in self.environment.wrap_resolver.wraps and \ + self.environment.wrap_resolver.wraps[meson_depname].type is not None + pkg = PackageState(manifest, downloaded) self.packages[key] = pkg # Fetch required dependencies recursively. for depname, dep in manifest.dependencies.items(): @@ -602,6 +606,11 @@ def _create_project(self, pkg: PackageState, build: builder.Builder) -> T.List[m :param build: The AST builder :return: a list nodes """ + default_options: T.List[mparser.BaseNode] = [] + default_options.append(build.string(f'rust_std={pkg.manifest.package.edition}')) + if pkg.downloaded: + default_options.append(build.string('warning_level=0')) + args: T.List[mparser.BaseNode] = [] args.extend([ build.string(pkg.manifest.package.name), @@ -613,7 +622,7 @@ def _create_project(self, pkg: PackageState, build: builder.Builder) -> T.List[m # This will warn when when we generate deprecated code, which is helpful # for the upkeep of the module 'meson_version': build.string(f'>= {coredata.stable_version}'), - 'default_options': build.array([build.string(f'rust_std={pkg.manifest.package.edition}')]), + 'default_options': build.array(default_options), } if pkg.manifest.package.license: kwargs['license'] = build.string(pkg.manifest.package.license)