From nobody Sat Feb 7 11:30:51 2026 Received: from mail-qv1-f52.google.com (mail-qv1-f52.google.com [209.85.219.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D716A241C85; Sun, 9 Feb 2025 21:05:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739135106; cv=none; b=RPc2HUOnDQ/uNKzXI5UmbTaaiYMToJ1atRkS8kibJST/bGlhWpRDUs1s2LSAnMJuQeGw2nnrR+tXp6UgD3JKE9sN9BJ8Iok0Jhde+izobUUJbf/AcbLiK2I0EfudV1OkTkfjQhjKCOhim0SoSf7FzNnOdlUUmOU+2SUnNQHzDy4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739135106; c=relaxed/simple; bh=FRjp3B0gA0PKWMi2B4e32Nxjc9e32/N2gbKa+Jjb4xQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=EKWxXIA1nZ+xHH7Bl+8c5i94VuAnlohM6ZvXDFuxixeJnAryPfMpMrnnfswescmPvNaGa22TSyTiDPL+XI1+2+Z38Ur8MQncYyxknkeoIANIbb7KrNgDX9MxsLBx8gIK69NkYlQxdUEc0L/Ec7+PgElct+IsB/0csDjkH1tWJsU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=aGAVSiaz; arc=none smtp.client-ip=209.85.219.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aGAVSiaz" Received: by mail-qv1-f52.google.com with SMTP id 6a1803df08f44-6e43c9c8d08so34749966d6.3; Sun, 09 Feb 2025 13:05:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739135104; x=1739739904; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=RFQ0ho6VbBrY2Rzr+NCGRpkume1oxn7BRMZvKM8hxxc=; b=aGAVSiazUaGbPE2IHJ4AFsZ3AfOafZe2lXPXUEqDl2KmReLHArbC5E2EbGY+82xxpV 6azaTdsvmQfDeQMyyaSm5awRG4l3fdpAQze0z4PaMs74jz9+K08qUDleu/nm5K2uRlYd a48yT+ORrur+ZnFQGPkAcI2ImXh2fi+68yHblleH/uKA4gfYAHBm+1Q8o4lNvvgxd105 +n1RaR4ymCchcq6Il30s6sgH6djo9RIdkc8/YX9h7kBZYgSeAN+Qb4d7ZUENnxBzLAqS 3pj+KWLvsS2lpqt/PVPHWlhL7V1HoQOlLIaSXB7+VC+A/plAHe9F9aF2H9882L2bei5N VhLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739135104; x=1739739904; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RFQ0ho6VbBrY2Rzr+NCGRpkume1oxn7BRMZvKM8hxxc=; b=jH+Ssan7E/wj2dsPQX4dqCdqXKA3AuQgX3kKF1azNd5vrIiFU/+jCLb5aexbfdqfFX SG8BdpiuUg/+Xb02pmeBGBjHIVNLDZY/mDj7e7x9THnKfjoSgVJA9L22/L+TQ2dF4WM6 bBj2yZXA7Sa/8BxE/Q7GJ6iw/QIMuzG7RSdWMhiAq7YTYcefWNJWdx1A1NIjdD1fgWnN S3ZmwJO1ZxjxUXoefzsF+kLvjvYg8c9bKTuqVhTxLmwIJovC17K++I2ledGktzKNv4rB cjaozMTgeomZeVve+hpmqgj/8TpEf3OuBYUSOV79WmRqffG5fAL58OcRaHoS+LB3GdU4 nSCQ== X-Forwarded-Encrypted: i=1; AJvYcCUNNKi4PUuiqdVEpMotBFGvCdppNzvYFlwD9Tg5oGnSmlVeOzi2xKiuMcCl6WjZtFQ3ge86oxp/1IaBODo=@vger.kernel.org X-Gm-Message-State: AOJu0YwfFftAfMnEbJ23ldGS6GbmLi8wz9Rlt/O9y76L/IpaAUAFvqYf eq5WPfTkvkOs2AtqGGyFnWIBOn+XAnJrTavI77pnA15SN5K7rGnlvkHT/Ulw X-Gm-Gg: ASbGncuwk0uZG7NLe/jXrIie9oEvi5CSlNkw0lRv0uXXrdY+ZdBqNdi/xtRb14tDYr4 tWA1WO8yrrlqyfwn16epJ0PmmrYcoTo/z8NsUu0OE844ut5piCJXKGpyhUOBbQP5kIDCwRhQ40y 4usWMCehIYmWOysSFQPjYp5rRVYSytWNE+C8uxiOW0Njzeo3jDMRQclNM5ndzElTfFtRr7fu3zw gj/o2F+hAeCHhUsgDLv3TetVYHi9bPceA56fiSbtHeUU8s/ZvJr9AE3Uwjn6Up8f5Mt2xFl1zSU TLwbS6W02SUYvdLNg39aXGtEpxm4pObyNrPUkC0= X-Google-Smtp-Source: AGHT+IEexLu2nwKencVozCQfn+x27EPm3zwA+kxCgIAilxw9gbhWKPm7tYkiYjOA959zEtk+KGf2Ig== X-Received: by 2002:ad4:5f89:0:b0:6e4:3cf1:5621 with SMTP id 6a1803df08f44-6e4455e883emr166987456d6.12.1739135103633; Sun, 09 Feb 2025 13:05:03 -0800 (PST) Received: from tamird-mac.local ([2600:4041:5be7:7c00:15f6:96e9:3308:934a]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6e44d545327sm24915476d6.33.2025.02.09.13.05.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Feb 2025 13:05:02 -0800 (PST) From: Tamir Duberstein Date: Sun, 09 Feb 2025 16:04:46 -0500 Subject: [PATCH 1/3] scripts: generate_rust_analyzer.py: add type hints Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250209-rust-analyzer-host-v1-1-a2286a2a2fa3@gmail.com> References: <20250209-rust-analyzer-host-v1-0-a2286a2a2fa3@gmail.com> In-Reply-To: <20250209-rust-analyzer-host-v1-0-a2286a2a2fa3@gmail.com> To: Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Boris-Chengbiao Zhou , Kees Cook , Fiona Behrens Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Lukas Wirth , Tamir Duberstein X-Mailer: b4 0.15-dev Python type hints allow static analysis tools like mypy to detect type errors during development, improving the developer experience. Python type hints have been present in the kernel since 2019 at the latest; see commit 6ebf5866f2e8 ("kunit: tool: add Python wrappers for running KUnit tests"). Run `uv tool run mypy --strict scripts/generate_rust_analyzer.py` to verify. Signed-off-by: Tamir Duberstein --- scripts/generate_rust_analyzer.py | 83 ++++++++++++++++++++++++++++-------= ---- 1 file changed, 61 insertions(+), 22 deletions(-) diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_anal= yzer.py index aa8ea1a4dbe5..28ab05de52b8 100755 --- a/scripts/generate_rust_analyzer.py +++ b/scripts/generate_rust_analyzer.py @@ -10,8 +10,9 @@ import os import pathlib import subprocess import sys +import typing as T =20 -def args_crates_cfgs(cfgs): +def args_crates_cfgs(cfgs: T.Iterable[str]) -> dict[str, list[str]]: crates_cfgs =3D {} for cfg in cfgs: crate, vals =3D cfg.split("=3D", 1) @@ -19,7 +20,34 @@ def args_crates_cfgs(cfgs): =20 return crates_cfgs =20 -def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs): +class Dependency(T.TypedDict): + crate: int + name: str + +class Source(T.TypedDict): + include_dirs: list[str] + exclude_dirs: list[str] + +class Crate(T.TypedDict): + display_name: str + root_module: str + is_workspace_member: bool + is_proc_macro: bool + deps: list[Dependency] + cfg: list[str] + edition: T.Literal["2021"] + env: dict[str, str] + # `NotRequired` would be better but was added in 3.11. + proc_macro_dylib_path: T.Optional[str] + source: T.Optional[Source] + +def generate_crates( + srctree: pathlib.Path, + objtree: pathlib.Path, + sysroot_src: pathlib.Path, + external_src: pathlib.Path, + cfgs: list[str], +) -> list[Crate]: # Generate the configuration list. cfg =3D [] with open(objtree / "include" / "generated" / "rustc_cfg") as fd: @@ -31,31 +59,40 @@ def generate_crates(srctree, objtree, sysroot_src, exte= rnal_src, cfgs): # Now fill the crates list -- dependencies need to come first. # # Avoid O(n^2) iterations by keeping a map of indexes. - crates =3D [] - crates_indexes =3D {} + crates: list[Crate] =3D [] + crates_indexes: dict[str, int] =3D {} crates_cfgs =3D args_crates_cfgs(cfgs) =20 - def append_crate(display_name, root_module, deps, cfg=3D[], is_workspa= ce_member=3DTrue, is_proc_macro=3DFalse): - crate =3D { - "display_name": display_name, - "root_module": str(root_module), - "is_workspace_member": is_workspace_member, - "is_proc_macro": is_proc_macro, - "deps": [{"crate": crates_indexes[dep], "name": dep} for dep i= n deps], - "cfg": cfg, - "edition": "2021", - "env": { - "RUST_MODFILE": "This is only for rust-analyzer" - } - } + def append_crate( + display_name: str, + root_module: pathlib.Path, + deps: list[str], + cfg: list[str] =3D [], + is_workspace_member: bool =3D True, + is_proc_macro: bool =3D False, + ) -> None: + proc_macro_dylib_path =3D None if is_proc_macro: proc_macro_dylib_name =3D subprocess.check_output( [os.environ["RUSTC"], "--print", "file-names", "--crate-na= me", display_name, "--crate-type", "proc-macro", "-"], stdin=3Dsubprocess.DEVNULL, ).decode('utf-8').strip() - crate["proc_macro_dylib_path"] =3D f"{objtree}/rust/{proc_macr= o_dylib_name}" + proc_macro_dylib_path =3D f"{objtree}/rust/{proc_macro_dylib_n= ame}" crates_indexes[display_name] =3D len(crates) - crates.append(crate) + crates.append( + { + "display_name": display_name, + "root_module": str(root_module), + "is_workspace_member": is_workspace_member, + "is_proc_macro": is_proc_macro, + "deps": [{"crate": crates_indexes[dep], "name": dep} for d= ep in deps], + "cfg": cfg, + "edition": "2021", + "env": {"RUST_MODFILE": "This is only for rust-analyzer"}, + "proc_macro_dylib_path": proc_macro_dylib_path, + "source": None, + } + ) =20 # First, the ones in `rust/` since they are a bit special. append_crate( @@ -107,7 +144,7 @@ def generate_crates(srctree, objtree, sysroot_src, exte= rnal_src, cfgs): "exclude_dirs": [], } =20 - def is_root_crate(build_file, target): + def is_root_crate(build_file: pathlib.Path, target: str) -> bool: try: return f"{target}.o" in open(build_file).read() except FileNotFoundError: @@ -116,7 +153,9 @@ def generate_crates(srctree, objtree, sysroot_src, exte= rnal_src, cfgs): # Then, the rest outside of `rust/`. # # We explicitly mention the top-level folders we want to cover. - extra_dirs =3D map(lambda dir: srctree / dir, ("samples", "drivers")) + extra_dirs: T.Iterable[pathlib.Path] =3D map( + lambda dir: srctree / dir, ("samples", "drivers") + ) if external_src is not None: extra_dirs =3D [external_src] for folder in extra_dirs: @@ -139,7 +178,7 @@ def generate_crates(srctree, objtree, sysroot_src, exte= rnal_src, cfgs): =20 return crates =20 -def main(): +def main() -> None: parser =3D argparse.ArgumentParser() parser.add_argument('--verbose', '-v', action=3D'store_true') parser.add_argument('--cfgs', action=3D'append', default=3D[]) --=20 2.48.1 From nobody Sat Feb 7 11:30:51 2026 Received: from mail-qv1-f52.google.com (mail-qv1-f52.google.com [209.85.219.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A8584241C98; Sun, 9 Feb 2025 21:05:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739135108; cv=none; b=t02fqxN1aUF/9CWE7xOj79F0DQtxv5je7dYYAmnJyYP4kY132OLqQqIBhpjf3OUfipbhUbLSEBwZLQfMQ1YfvuyQMdbHN7qz9bkP/WsJr1032ZYJyXyRhSxukmbOtk4COJE2EwDCX//kOgtWBPWRQwdvdvj8Z2bVcrIaIWXso/4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739135108; c=relaxed/simple; bh=k/a+YYloKs30FYcmJMxVoiBc5880F7AOdupmYFGqHLo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=IJQ4N0Q4GNVf3Gqw51EfUMOdwy2wmP5onkFhyCCfisE2S52AIWngD9QPdLWog02UJBxylwo1Avy5FYXTESuLjeB7Cwjm5fMmowP5IvTw2qdY1PQByn+ZNgx7iDwpgHLf7hPq/B6xWcHZOJa16sMtTqzOry7qrNTTCnc7t6yUOmw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=bmYcaa41; arc=none smtp.client-ip=209.85.219.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bmYcaa41" Received: by mail-qv1-f52.google.com with SMTP id 6a1803df08f44-6dd0d09215aso29233526d6.2; Sun, 09 Feb 2025 13:05:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739135105; x=1739739905; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=l+qHhvOuniI0ncU/zRRxclD9Styu48aqgyVuEXkRMAo=; b=bmYcaa41FXS27xDkfGycp0ZIU/YqIkopXeMG/4K7hE6ihqlcADjBQnwx3GntsF3Lmy ivQtz/+mRZnpKM5iOjsfoa3VlnJ7tlvylO5i1TVxxX3xgDrEoiCs2P6/RTJJJv9IYs6B sDPj7dVHH1qXh+3ecaQ1CtcXJ7HORS7xBuFgIs2wSp+rmCqXn6SepJBM8Tux/ewZQNU5 PTYfXLkY5sPQnLzvuRS7/sTVEaiPXYSAGjmX+ow43cYE8XaXF1Qu8BjJhU7oYpptgi6U JfJBmcJDQH5whA8/YqsL6ZwqNbk9+aplhRmDyPWF5K5P6PkbdbzhrvOIlHubcmTZcCNN u2Qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739135105; x=1739739905; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=l+qHhvOuniI0ncU/zRRxclD9Styu48aqgyVuEXkRMAo=; b=g8/Arfro8cgL917btT7cWZcg4+QePe356z6YLAsTxHRFLJIqZpJnlo6vdahQ4PnnBa uU/NyTqhzSZcr48qCB9Wo5fPI3M3lgVldZ4WFKKeYaMRHpSqNsVe/Ep0NjaBrsA2XZZe +V39301bj/YJXsTXwsQCfjp1+3HTMKVyV48NymznPROOfKn0oOIHwBweUiiRYkCv5HiD 2fA8Z3CDLM0aoysvrwjhqlrqDetGDKY+LJMdIjxyA9omtO9MziHwTQt0d1Te1L8707d9 PCh2QbYZfBWSovzgTrBv0/rhr8Npr7gCQMkJ6s1RUzbYQQ1z51k5bSCAyoIvS/gqchaM n4ZQ== X-Forwarded-Encrypted: i=1; AJvYcCU49JYECY5ICvLi1Zn6auo7G5U3YQ8RpLEJiwlqVKb5RwpbanPM/vSd6JV/Zqj9DdZ7BJTzggwbr89mAbY=@vger.kernel.org X-Gm-Message-State: AOJu0Yw3Jzike/koq56nEZtsg+RWwZFwjAGHA/qbQXNiXBgvqgQ9FIsx CD1BoroebRRAg0/xkEUAkOTNmzjlboQM0Z4XF2Y6Tcutn2BA0/s3 X-Gm-Gg: ASbGnct84S5rMAw7H84NaItRsOm65wb1kDkiZhzNalY60GQFXkBMYvKepacmEarXMYs xp+98Gf6sqjZI6Y6Y3fDc/FtjpFVSnLACEIDafCpomHXlEN2kMz4MaabzqLYi5nvgolP5Il+Tkg 37fTkWABJPT8ba8e9nckXzL3om0Qtv0Cc6wkgkr1ucCxbMtV9ksWTsrHUmpTtda2+pg8irTKPgH e/UkmGrPmCI7/bZG4ajt/4y1NF/SWCBlhscqIrrmJ786PNmffaYhWq0Rb5tdMKjwUXUr6gr8tXy nqSXs5YfLlRp6hXPfpkHxQcfPchURgdF+omxs6I= X-Google-Smtp-Source: AGHT+IGceoNLFzIXI/inRVpNwGNlHGgtVFR8e5CZCcFbHvOHDHCqFbeMCRKxtFqKxvyqFTl6xuW0fg== X-Received: by 2002:a05:6214:1c42:b0:6d8:8b9d:1500 with SMTP id 6a1803df08f44-6e4456e01fbmr238839956d6.36.1739135105502; Sun, 09 Feb 2025 13:05:05 -0800 (PST) Received: from tamird-mac.local ([2600:4041:5be7:7c00:15f6:96e9:3308:934a]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6e44d545327sm24915476d6.33.2025.02.09.13.05.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Feb 2025 13:05:04 -0800 (PST) From: Tamir Duberstein Date: Sun, 09 Feb 2025 16:04:47 -0500 Subject: [PATCH 2/3] scripts: generate_rust_analyzer.py: identify crates explicitly Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250209-rust-analyzer-host-v1-2-a2286a2a2fa3@gmail.com> References: <20250209-rust-analyzer-host-v1-0-a2286a2a2fa3@gmail.com> In-Reply-To: <20250209-rust-analyzer-host-v1-0-a2286a2a2fa3@gmail.com> To: Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Boris-Chengbiao Zhou , Kees Cook , Fiona Behrens Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Lukas Wirth , Tamir Duberstein X-Mailer: b4 0.15-dev Use the return of `append_crate` to declare dependency on that crate. This allows multiple crates with the same display_name be defined, which we'll use to define host crates separately from target crates. Signed-off-by: Tamir Duberstein --- scripts/generate_rust_analyzer.py | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_anal= yzer.py index 28ab05de52b8..cb49f0b07c97 100755 --- a/scripts/generate_rust_analyzer.py +++ b/scripts/generate_rust_analyzer.py @@ -56,21 +56,18 @@ def generate_crates( line =3D line.replace("\n", "") cfg.append(line) =20 - # Now fill the crates list -- dependencies need to come first. - # - # Avoid O(n^2) iterations by keeping a map of indexes. + # Now fill the crates list. crates: list[Crate] =3D [] - crates_indexes: dict[str, int] =3D {} crates_cfgs =3D args_crates_cfgs(cfgs) =20 def append_crate( display_name: str, root_module: pathlib.Path, - deps: list[str], + deps: list[Dependency], cfg: list[str] =3D [], is_workspace_member: bool =3D True, is_proc_macro: bool =3D False, - ) -> None: + ) -> Dependency: proc_macro_dylib_path =3D None if is_proc_macro: proc_macro_dylib_name =3D subprocess.check_output( @@ -78,14 +75,14 @@ def generate_crates( stdin=3Dsubprocess.DEVNULL, ).decode('utf-8').strip() proc_macro_dylib_path =3D f"{objtree}/rust/{proc_macro_dylib_n= ame}" - crates_indexes[display_name] =3D len(crates) + index =3D len(crates) crates.append( { "display_name": display_name, "root_module": str(root_module), "is_workspace_member": is_workspace_member, "is_proc_macro": is_proc_macro, - "deps": [{"crate": crates_indexes[dep], "name": dep} for d= ep in deps], + "deps": deps, "cfg": cfg, "edition": "2021", "env": {"RUST_MODFILE": "This is only for rust-analyzer"}, @@ -93,9 +90,10 @@ def generate_crates( "source": None, } ) + return {"crate": index, "name": display_name} =20 # First, the ones in `rust/` since they are a bit special. - append_crate( + core =3D append_crate( "core", sysroot_src / "core" / "src" / "lib.rs", [], @@ -103,37 +101,37 @@ def generate_crates( is_workspace_member=3DFalse, ) =20 - append_crate( + compiler_builtins =3D append_crate( "compiler_builtins", srctree / "rust" / "compiler_builtins.rs", [], ) =20 - append_crate( + macros =3D append_crate( "macros", srctree / "rust" / "macros" / "lib.rs", [], is_proc_macro=3DTrue, ) =20 - append_crate( + build_error =3D append_crate( "build_error", srctree / "rust" / "build_error.rs", - ["core", "compiler_builtins"], + [core, compiler_builtins], ) =20 - append_crate( + bindings =3D append_crate( "bindings", srctree / "rust"/ "bindings" / "lib.rs", - ["core"], + [core], cfg=3Dcfg, ) crates[-1]["env"]["OBJTREE"] =3D str(objtree.resolve(True)) =20 - append_crate( + kernel =3D append_crate( "kernel", srctree / "rust" / "kernel" / "lib.rs", - ["core", "macros", "build_error", "bindings"], + [core, macros, build_error, bindings], cfg=3Dcfg, ) crates[-1]["source"] =3D { @@ -172,7 +170,7 @@ def generate_crates( append_crate( name, path, - ["core", "kernel"], + [core, kernel], cfg=3Dcfg, ) =20 --=20 2.48.1 From nobody Sat Feb 7 11:30:51 2026 Received: from mail-qk1-f171.google.com (mail-qk1-f171.google.com [209.85.222.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D4AEF241CBC; Sun, 9 Feb 2025 21:05:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739135109; cv=none; b=afKcQ86/sH7IZfiF6Fhg0O5aDIxbpJSjCIkKzbs55XJbW/CVMRABNKxUev9TFtMjhMBIK8vy4le0VZX5fLpN4I2V2nvUKoyZF9oEsyw4zLixyDycOb3uUnjGZudJkXb65uWcSaXIwAF7f5fB8HkL7tuTyhqg6EkFF4ne/eVJfF0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739135109; c=relaxed/simple; bh=tpp+HhS5c1vQqIa3l51GIBBumfDFTVTs8A9zUQaecZA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=OYy8Y+fTm0bvhBOH0NnVd2qpMdMVVdSq7+skl/MaOQLtrxp/CcuwCpqG0KCxXa9wBPjaecdtA3DrfFvH5MK66CsO35U7priqQEUvTwiPNQ6KPPW9G/F+unqcVi2QaGd2ttQaIpIZ8IIg96o/4Dg77ZZR0Pk1T4l0csLYo6ShHys= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=BONfS35r; arc=none smtp.client-ip=209.85.222.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BONfS35r" Received: by mail-qk1-f171.google.com with SMTP id af79cd13be357-7c060568959so11801085a.1; Sun, 09 Feb 2025 13:05:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739135107; x=1739739907; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=ZiWD7eS04IvCFBhTX/2ExyP1h9pWIv3v/MbJ7+UeEI8=; b=BONfS35rnDXWiStHUdSddUHbIWlJFt623O9XEYQNxC1AUqZxTs9nm1nlukMhBvzYqM E5tCJn+ctH/ra86qDKI7hE9bCo0AOt9frOYfOul1DmWVX9qiw2OyYOtmmONktsAE5cqh TpyV8fyCPnrtapqJtHjp5Kq/XPtd1NtvKeZLq3QYPR6jEqsJQednupocbc5dMIQxmQIt 2gKFO2c98wG6a83wUJyAyYA5myA0cOWpRgvGcksEecr6jPvQ8SgDI6A3gbssWfsbZp0T TOqGQwPW6rtN9xejk/7gbVtTeB0kOMYYJ/WcbpMCGAg3p5dFdvHINGcy3CsIjJREpHnA 7dbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739135107; x=1739739907; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZiWD7eS04IvCFBhTX/2ExyP1h9pWIv3v/MbJ7+UeEI8=; b=gcQpohMEYxdUULcF1rpmv2tr5a2ZdiEBXgw1yD+hbeqGjooSidEMvEntWat+/haU6H u5wnNwRg2LDLWi3vbf0BOCPPpcOcoQt1k8uo5AO5Wov+Syi5ShJ0JEZmJ+aCfFF4LSoS uaiBgogacbJw1TSpwJA8OdwdgCUkfl/kd8eDmxQ2d9NPTqrjdEAklM2LVBArNozZLUAF 2Z/9P+1aSGDA1PDCFPbaRQBybncMJUU6kfpbt+buMEy+SEMdUDboJsjr8ln9ZMZQzimM 33AA13Vg5b4Um/eNSJ3evFT69qeiHdBpryDf/e7xA/L+jnOvkjPPQji37f/ysNESrovq UEUw== X-Forwarded-Encrypted: i=1; AJvYcCXf4zEqFg2QCxgbnwTQnfz4/EL6bCG6TxnlBQPv9LXhltcVKkIusLp7THnKbHdttQT5f3ewX9lDrywNLq8=@vger.kernel.org X-Gm-Message-State: AOJu0YwIH3y8p0xOqQDhYjJzjWt47peq+m5/6LgVuCWOAY2eWSXh5yMB UC+cIg7fsL9vyDYfMWv9CiVkQGllUz3vzIX1fehxiTGU+EIBr+76 X-Gm-Gg: ASbGncsUihL+ZIo+OdEDYgARgSGOriu0y1eXAU0d4NFEm7o6fay/znZn30cJpfztmKm mHoSoWAFdSQ2dXeo6ZikIb+JY9gzx6CIgZbkI62HbnhLZpl1tO483segNepk1N4b8JGFdnDR/kv EVkMCV11PMNWCgCbmNby0bfR80slOeZqQSJTg//UqR2ftHKKcUhWeQfX7F1kRr0vEJ5mUBLNJu7 ekdRBdDKR0+06rq9rWIudWrKcjWwhH+34tFbMl2Z/3O4TJRaP64V3XpHT06Z8lz5HzWvgcfARul 8XorA6YU7GTQ/U7AWpffjZSdXXCGctt+X0TFm7U= X-Google-Smtp-Source: AGHT+IGt+X/C9WBSXpxZglWrezYuB9hTMLlOFlOBNt71f5rqAO5uAvkogTiL8EmyWzZ9DwtL6dUTtQ== X-Received: by 2002:a05:6214:e47:b0:6e2:43d1:5fe5 with SMTP id 6a1803df08f44-6e4456c5b23mr187139956d6.34.1739135106648; Sun, 09 Feb 2025 13:05:06 -0800 (PST) Received: from tamird-mac.local ([2600:4041:5be7:7c00:15f6:96e9:3308:934a]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6e44d545327sm24915476d6.33.2025.02.09.13.05.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Feb 2025 13:05:06 -0800 (PST) From: Tamir Duberstein Date: Sun, 09 Feb 2025 16:04:48 -0500 Subject: [PATCH 3/3] scripts: generate_rust_analyzer.py: add missing macros deps Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250209-rust-analyzer-host-v1-3-a2286a2a2fa3@gmail.com> References: <20250209-rust-analyzer-host-v1-0-a2286a2a2fa3@gmail.com> In-Reply-To: <20250209-rust-analyzer-host-v1-0-a2286a2a2fa3@gmail.com> To: Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Boris-Chengbiao Zhou , Kees Cook , Fiona Behrens Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Lukas Wirth , Tamir Duberstein , Chayim Refael Friedman X-Mailer: b4 0.15-dev The macros crate has depended on std and proc_macro since its introduction in commit 1fbde52bde73 ("rust: add `macros` crate"). These dependencies were omitted from commit 8c4555ccc55c ("scripts: add `generate_rust_analyzer.py`") resulting in missing go-to-definition and autocomplete, and false-positive warnings emitted from rust-analyzer such as: [{ "resource": "/Users/tamird/src/linux/rust/macros/module.rs", "owner": "_generated_diagnostic_collection_name_#1", "code": { "value": "non_snake_case", "target": { "$mid": 1, "path": "/rustc/", "scheme": "https", "authority": "doc.rust-lang.org", "query": "search=3Dnon_snake_case" } }, "severity": 4, "message": "Variable `None` should have snake_case name, e.g. `none`", "source": "rust-analyzer", "startLineNumber": 123, "startColumn": 17, "endLineNumber": 123, "endColumn": 21 }] Define and add the missing *host* dependencies to improve the developer experience. Define the *target* `core` crate using the new `append_sysroot_crate` helper. Fixes: 8c4555ccc55c ("scripts: add `generate_rust_analyzer.py`") Suggested-by: Chayim Refael Friedman Suggested-by: Miguel Ojeda Signed-off-by: Tamir Duberstein --- scripts/generate_rust_analyzer.py | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_anal= yzer.py index cb49f0b07c97..124f6b0334db 100755 --- a/scripts/generate_rust_analyzer.py +++ b/scripts/generate_rust_analyzer.py @@ -92,14 +92,28 @@ def generate_crates( ) return {"crate": index, "name": display_name} =20 - # First, the ones in `rust/` since they are a bit special. - core =3D append_crate( - "core", - sysroot_src / "core" / "src" / "lib.rs", - [], - cfg=3Dcrates_cfgs.get("core", []), - is_workspace_member=3DFalse, - ) + def append_sysroot_crate( + display_name: str, + deps: list[Dependency], + cfg: list[str] =3D [], + ) -> Dependency: + return append_crate( + display_name, + sysroot_src / display_name / "src" / "lib.rs", + deps, + cfg, + is_workspace_member=3DFalse, + ) + + # NB: sysroot crates reexport items from one another so setting up our= transitive dependencies + # here is important for ensuring that rust-analyzer can resolve symbol= s. The sources of truth + # for this dependency graph are `(sysroot_src / crate / "Cargo.toml" f= or crate in crates)`. + host_core =3D append_sysroot_crate("core", []) + host_alloc =3D append_sysroot_crate("alloc", [host_core]) + host_std =3D append_sysroot_crate("std", [host_alloc, host_core]) + host_proc_macro =3D append_sysroot_crate("proc_macro", [host_core, hos= t_std]) + + core =3D append_sysroot_crate("core", [], cfg=3Dcrates_cfgs.get("core"= , [])) =20 compiler_builtins =3D append_crate( "compiler_builtins", @@ -110,7 +124,7 @@ def generate_crates( macros =3D append_crate( "macros", srctree / "rust" / "macros" / "lib.rs", - [], + [host_std, host_proc_macro], is_proc_macro=3DTrue, ) =20 --=20 2.48.1