if have_rust
rustc_args = [find_program('scripts/rust/rustc_args.py'),
- '--rustc-version', rustc.version()]
+ '--rustc-version', rustc.version(),
+ '--workspace', meson.project_source_root() / 'rust']
rustfmt = find_program('rustfmt', required: false)
- # Prohibit code that is forbidden in Rust 2024
- rustc_lint_args = ['-D', 'unsafe_op_in_unsafe_fn']
+ rustc_lint_args = run_command(rustc_args, '--lints',
+ capture: true, check: true).stdout().strip().splitlines()
# Occasionally, we may need to silence warnings and clippy lints that
# were only introduced in newer Rust compiler versions. Do not croak
_qemu_api_cfg = run_command(rustc_args,
- '--config-headers', config_host_h, '--features', '--lints', files('Cargo.toml'),
+ '--config-headers', config_host_h, '--features', files('Cargo.toml'),
capture: true, check: true).stdout().strip().splitlines()
# _qemu_api_cfg += ['--cfg', 'feature="allocator"']
class CargoTOML:
tomldata: Mapping[Any, Any]
+ workspace_data: Mapping[Any, Any]
check_cfg: Set[str]
- def __init__(self, path: str):
- with open(path, 'rb') as f:
- self.tomldata = tomllib.load(f)
+ def __init__(self, path: Optional[str], workspace: Optional[str]):
+ if path is not None:
+ with open(path, 'rb') as f:
+ self.tomldata = tomllib.load(f)
+ else:
+ self.tomldata = {"lints": {"workspace": True}}
+
+ if workspace is not None:
+ with open(workspace, 'rb') as f:
+ self.workspace_data = tomllib.load(f)
+ if "workspace" not in self.workspace_data:
+ self.workspace_data["workspace"] = {}
self.check_cfg = set(self.find_check_cfg())
@property
def lints(self) -> Mapping[Any, Any]:
- return self.get_table("lints")
+ return self.get_table("lints", True)
- def get_table(self, key: str) -> Mapping[Any, Any]:
+ def get_table(self, key: str, can_be_workspace: bool = False) -> Mapping[Any, Any]:
table = self.tomldata.get(key, {})
+ if can_be_workspace and table.get("workspace", False) is True:
+ table = self.workspace_data["workspace"].get(key, {})
return table
action="store",
dest="cargo_toml",
help="path to Cargo.toml file",
+ nargs='?',
+ )
+ parser.add_argument(
+ "--workspace",
+ metavar="DIR",
+ action="store",
+ dest="workspace",
+ help="path to root of the workspace",
+ required=False,
+ default=None,
)
parser.add_argument(
"--features",
logging.debug("args: %s", args)
rustc_version = tuple((int(x) for x in args.rustc_version.split('.')[0:2]))
- cargo_toml = CargoTOML(args.cargo_toml)
+ if args.workspace:
+ workspace_cargo_toml = Path(args.workspace, "Cargo.toml").resolve()
+ cargo_toml = CargoTOML(args.cargo_toml, str(workspace_cargo_toml))
+ else:
+ cargo_toml = CargoTOML(args.cargo_toml, None)
if args.lints:
for tok in generate_lint_flags(cargo_toml):