Skip to content

Commit

Permalink
rust: add warning_level=0 to downloaded Cargo subprojects
Browse files Browse the repository at this point in the history
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 <pbonzini@redhat.com>
  • Loading branch information
bonzini committed Dec 20, 2024
1 parent 94966d5 commit b1d9e29
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
8 changes: 8 additions & 0 deletions docs/markdown/snippets/cargo_cap_lints.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## `--cap-lints allow` used for Cargo subprojects

Similar to Cargo itself, all 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`.
13 changes: 10 additions & 3 deletions mesonbuild/cargo/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -520,7 +521,8 @@ 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 = 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():
Expand Down Expand Up @@ -602,6 +604,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),
Expand All @@ -613,7 +620,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)
Expand Down

0 comments on commit b1d9e29

Please sign in to comment.