diff --git a/docs/markdown/snippets/cargo_cap_lints.md b/docs/markdown/snippets/cargo_cap_lints.md new file mode 100644 index 000000000000..4f91207f2dd6 --- /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 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..5a0d9bf88aa1 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,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(): @@ -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), @@ -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)