From nobody Sun Feb 8 06:05:18 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 22E823002D8; Fri, 9 Jan 2026 22:10:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767996620; cv=none; b=JPXze441ta+4pSm/uFK6i3KVwilZjFHoAC3v8jXL7a+19yNNCK3uCnanhZcE+Xy039qTFp0/yTHVKjDbWaFfW17lrE05Lm0n/bNdJv/w6s7enshBB14qv0FJs6Ej05V2m8qg6Aj9MOIj/99RXUnWwmJO+Q0ZrdUWRAcQMP2t2DE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767996620; c=relaxed/simple; bh=6p5MA3d89Sg5gZpEe7ephACF026Y6huVVMrgpV+spfI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=oub4x580ISEhwa8pidGJGSOCbT7OOelxouJgTjeFFbTYEYMf+QAKeeNJhT0YQ/824CATqX8xWj5qaqnNsyv2+zoZVH6uFHpDmashkPXgyJLMRHBhKlr5IsxCpwptycJ3zaxSxChZRQQoDFYwnPAgnLe3FN+tLxVhcsWAurcdMc4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jBpdDiqv; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jBpdDiqv" Received: by smtp.kernel.org (Postfix) with ESMTPS id BA7CAC16AAE; Fri, 9 Jan 2026 22:10:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1767996619; bh=6p5MA3d89Sg5gZpEe7ephACF026Y6huVVMrgpV+spfI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=jBpdDiqvlLg45DTPvquuJAK9n5v59+4E5kKJD9XAKiuX9XgPXRi1Emtx6XSK4LhLJ Fv0O/S6qDcF0AdoG8wZwD4m6vlIyGKb+DtBf6HqdHixgak/8y6xWIP/C1+IjgGP+z3 SPazzYHLMT0yLg5jgEf0vXXbkv/tnexgZvrF0JY4dRd2ZTtoAGUycXdjYIU4UAnUaM Q3JCHvxEdKmsXi84vSNRMef7lS+1Z5Zgb5czR+zE6jlioWswZCEZJ5LOvhYpIMoivj xzeNCkIuTz6EJpKfyZUP/domKEIh1MnbeW1muhO/fqZv9gCE7jNm4ct9M66LmkPOpA WxqjllkjD5g0Q== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id AAD1BD26D9B; Fri, 9 Jan 2026 22:10:19 +0000 (UTC) From: Jesung Yang via B4 Relay Date: Fri, 09 Jan 2026 22:09:00 +0000 Subject: [PATCH v2 1/2] scripts: generate_rust_analyzer: add versioning infrastructure 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: <20260109-ra-fix-primitive-v2-1-249852a4145a@gmail.com> References: <20260109-ra-fix-primitive-v2-0-249852a4145a@gmail.com> In-Reply-To: <20260109-ra-fix-primitive-v2-0-249852a4145a@gmail.com> To: Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Tamir Duberstein Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Jesung Yang X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1767996618; l=12537; i=y.j3ms.n@gmail.com; s=20251225; h=from:subject:message-id; bh=JWm8UAfLC1ns7QSTpKBpu5bO5YwhtDcjTNcOdRHiGqo=; b=HM3QI/KHxq8ZehXyGmdn5mv0OuBo3uPpmwbcxYy2lLpkXlkmGzY/GcHAu0j011w+/+tGc3S3j dD4JblSEHvVAZpz9eygoUoqhNmV8jKi4pEAs9MgDtdUNTCZRDs8AaUr X-Developer-Key: i=y.j3ms.n@gmail.com; a=ed25519; pk=2yVgO1I+y7kkFSF2Dc/Dckj4L2FgRnvmERHFt4bspbI= X-Endpoint-Received: by B4 Relay for y.j3ms.n@gmail.com/20251225 with auth_id=586 X-Original-From: Jesung Yang Reply-To: y.j3ms.n@gmail.com From: Jesung Yang Introduce multi-version support for rust-analyzer. The script now executes `rust-analyzer --version` to query the version string and generates a `rust-project.json` file compatible with the detected version. This is a preparatory patch to address inherent method resolution failures for primitive types occurring in rust-analyzer v0.3.2693 (2025-11-24) or later when used with our current `rust-project.json` generation logic. Since the actual fix requires a feature only available in rust-analyzer v0.3.2727 (2025-12-22) or later, this infrastructure is necessary to avoid breaking compatibility with rust-analyzer v0.3.1940 (2024-04-29), which corresponds to our MSRV of 1.78. Signed-off-by: Jesung Yang --- scripts/generate_rust_analyzer.py | 181 +++++++++++++++++++++++++++++++++-= ---- 1 file changed, 157 insertions(+), 24 deletions(-) diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_anal= yzer.py index 147d0cc940681426771db865bc2462e7029a6d7d..32b0da99f17549ecc83e9a68911= 373310a2c9617 100755 --- a/scripts/generate_rust_analyzer.py +++ b/scripts/generate_rust_analyzer.py @@ -4,10 +4,13 @@ """ =20 import argparse +from datetime import datetime +import enum import json import logging import os import pathlib +import re import subprocess import sys =20 @@ -19,7 +22,7 @@ def args_crates_cfgs(cfgs): =20 return crates_cfgs =20 -def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, cor= e_edition): +def generate_crates(ctx, srctree, objtree, sysroot_src, external_src, cfgs= , core_edition): # Generate the configuration list. cfg =3D [] with open(objtree / "include" / "generated" / "rustc_cfg") as fd: @@ -35,7 +38,7 @@ def generate_crates(srctree, objtree, sysroot_src, extern= al_src, cfgs, core_edit crates_indexes =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, edition=3D"2021"): + def append_crate(display_name, root_module, deps, cfg=3D[], crate_attr= s=3D[], is_workspace_member=3DTrue, is_proc_macro=3DFalse, edition=3D"2021"= ): crate =3D { "display_name": display_name, "root_module": str(root_module), @@ -48,6 +51,8 @@ def generate_crates(srctree, objtree, sysroot_src, extern= al_src, cfgs, core_edit "RUST_MODFILE": "This is only for rust-analyzer" } } + if ctx["use_crate_attrs"] and len(crate_attrs) > 0: + crate["crate_attrs"] =3D crate_attrs 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", "-"], @@ -72,52 +77,58 @@ def generate_crates(srctree, objtree, sysroot_src, exte= rnal_src, cfgs, core_edit edition=3Dedition, ) =20 - # 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)`. - append_sysroot_crate("core", [], cfg=3Dcrates_cfgs.get("core", []), ed= ition=3Dcore_edition) - append_sysroot_crate("alloc", ["core"]) - append_sysroot_crate("std", ["alloc", "core"]) - append_sysroot_crate("proc_macro", ["core", "std"]) + def sysroot_deps(*deps): + return list(deps) if ctx["add_sysroot_crates"] else [] + + if ctx["add_sysroot_crates"]: + # NB: sysroot crates reexport items from one another so setting up= our transitive dependencies + # here is important for ensuring that rust-analyzer can resolve sy= mbols. The sources of truth + # for this dependency graph are `(sysroot_src / crate / "Cargo.tom= l" for crate in crates)`. + append_sysroot_crate("core", [], cfg=3Dcrates_cfgs.get("core", [])= , edition=3Dcore_edition) + append_sysroot_crate("alloc", ["core"]) + append_sysroot_crate("std", ["alloc", "core"]) + append_sysroot_crate("proc_macro", ["core", "std"]) =20 append_crate( "compiler_builtins", srctree / "rust" / "compiler_builtins.rs", [], + crate_attrs=3D["no_std"], ) =20 append_crate( "proc_macro2", srctree / "rust" / "proc-macro2" / "lib.rs", - ["core", "alloc", "std", "proc_macro"], + sysroot_deps("core", "alloc", "std", "proc_macro"), cfg=3Dcrates_cfgs["proc_macro2"], ) =20 append_crate( "quote", srctree / "rust" / "quote" / "lib.rs", - ["alloc", "proc_macro", "proc_macro2"], + sysroot_deps("alloc", "proc_macro") + ["proc_macro2"], cfg=3Dcrates_cfgs["quote"], ) =20 append_crate( "syn", srctree / "rust" / "syn" / "lib.rs", - ["proc_macro", "proc_macro2", "quote"], + sysroot_deps("proc_macro") + ["proc_macro2", "quote"], cfg=3Dcrates_cfgs["syn"], ) =20 append_crate( "macros", srctree / "rust" / "macros" / "lib.rs", - ["std", "proc_macro", "proc_macro2", "quote", "syn"], + sysroot_deps("std", "proc_macro") + ["proc_macro2", "quote", "syn"= ], is_proc_macro=3DTrue, ) =20 append_crate( "build_error", srctree / "rust" / "build_error.rs", - ["core", "compiler_builtins"], + sysroot_deps("core") + ["compiler_builtins"], + crate_attrs=3D["no_std"], ) =20 append_crate( @@ -125,31 +136,36 @@ def generate_crates(srctree, objtree, sysroot_src, ex= ternal_src, cfgs, core_edit srctree / "rust" / "pin-init" / "internal" / "src" / "lib.rs", [], cfg=3D["kernel"], + crate_attrs=3D["no_std"], is_proc_macro=3DTrue, ) =20 append_crate( "pin_init", srctree / "rust" / "pin-init" / "src" / "lib.rs", - ["core", "pin_init_internal", "macros"], + sysroot_deps("core") + ["pin_init_internal", "macros"], cfg=3D["kernel"], + crate_attrs=3D["no_std"], ) =20 append_crate( "ffi", srctree / "rust" / "ffi.rs", - ["core", "compiler_builtins"], + sysroot_deps("core") + ["compiler_builtins"], + crate_attrs=3D["no_std"], ) =20 def append_crate_with_generated( display_name, deps, + crate_attrs=3D[] ): append_crate( display_name, srctree / "rust"/ display_name / "lib.rs", deps, cfg=3Dcfg, + crate_attrs=3Dcrate_attrs ) crates[-1]["env"]["OBJTREE"] =3D str(objtree.resolve(True)) crates[-1]["source"] =3D { @@ -160,9 +176,21 @@ def generate_crates(srctree, objtree, sysroot_src, ext= ernal_src, cfgs, core_edit "exclude_dirs": [], } =20 - append_crate_with_generated("bindings", ["core", "ffi", "pin_init"]) - append_crate_with_generated("uapi", ["core", "ffi", "pin_init"]) - append_crate_with_generated("kernel", ["core", "macros", "build_error"= , "pin_init", "ffi", "bindings", "uapi"]) + append_crate_with_generated( + "bindings", + sysroot_deps("core") + ["ffi", "pin_init"], + crate_attrs=3D["no_std"], + ) + append_crate_with_generated( + "uapi", + sysroot_deps("core") + ["ffi", "pin_init"], + crate_attrs=3D["no_std"], + ) + append_crate_with_generated( + "kernel", + sysroot_deps("core") + ["macros", "build_error", "pin_init", "ffi"= , "bindings", "uapi"], + crate_attrs=3D["no_std"], + ) =20 def is_root_crate(build_file, target): try: @@ -190,12 +218,103 @@ def generate_crates(srctree, objtree, sysroot_src, e= xternal_src, cfgs, core_edit append_crate( name, path, - ["core", "kernel"], + sysroot_deps("core") + ["kernel"], cfg=3Dcfg, + crate_attrs=3D["no_std"] ) =20 return crates =20 +@enum.unique +class RaVersion(enum.Enum): + """ + Represents rust-analyzer compatibility baselines. Concrete versions ar= e mapped to the most + recent baseline they have reached. Must be in release order. + """ + + # v0.3.1940, released on 2024-04-29; bundled with the rustup 1.78 tool= chain. + V20240429 =3D 0 + + @staticmethod + def baselines(): + assert len(RaVersion) =3D=3D 1, "Exhaustiveness check: update base= line list!" + + return [ + (datetime.strptime("2024-04-29", "%Y-%m-%d"), (0, 3, 1940), Ra= Version.V20240429), + ] + + @staticmethod + def default(): + # The default is the 2024-04-29 release, aligning with our MSRV po= licy. + return RaVersion.V20240429 + + def __str__(self): + assert len(RaVersion) =3D=3D 1, "Exhaustiveness check: update if b= ranches!" + + if self =3D=3D RaVersion.V20240429: + return "v0.3.1940 (2024-04-29)" + else: + assert False, "Unreachable" + +def generate_rust_project( + ra_version, + srctree, + objtree, + sysroot, + sysroot_src, + external_src, + cfgs, + core_edition +): + assert len(RaVersion) =3D=3D 1, "Exhaustiveness check: update if branc= hes!" + + if ra_version =3D=3D RaVersion.V20240429: + ctx =3D { + "use_crate_attrs": False, + "add_sysroot_crates": True, + } + return { + "crates": generate_crates(ctx, srctree, objtree, sysroot_src, = external_src, cfgs, core_edition), + "sysroot": str(sysroot), + } + else: + assert False, "Unreachable" + +def query_ra_version(): + try: + # Use the rust-analyzer binary found in $PATH. + ra_version_output =3D subprocess.check_output( + ["rust-analyzer", "--version"], + stdin=3Dsubprocess.DEVNULL, + ).decode('utf-8').strip() + return ra_version_output + except FileNotFoundError: + logging.warning("Failed to find rust-analyzer in $PATH") + return None + +def map_ra_version_baseline(ra_version_output): + checkpoints =3D reversed(RaVersion.baselines()) + + # First, attempt to resolve to our known checkpoint using the release = date. + # This covers patterns like "rust-analyzer 1.78.0 (9b00956e 2024-04-29= )". + date_match =3D re.search(r"\d{4}-\d{2}-\d{2}", ra_version_output) + if date_match: + found_date =3D datetime.strptime(date_match.group(), "%Y-%m-%d") + for date, ver, enum in checkpoints: + if found_date >=3D date: + return enum + + # Otherwise, attempt to resolve to our known checkpoint using the rust= -analyzer version. + # This covers patterns like "rust-analyzer 0.3.2743-standalone". + version_match =3D re.search(r"\d+\.\d+\.\d+", ra_version_output) + if version_match: + found_version =3D tuple(map(int, version_match.group().split("."))) + for date, ver, enum in checkpoints: + if found_version >=3D ver: + return enum + + return RaVersion.default() + def main(): parser =3D argparse.ArgumentParser() parser.add_argument('--verbose', '-v', action=3D'store_true') @@ -216,10 +335,24 @@ def main(): # Making sure that the `sysroot` and `sysroot_src` belong to the same = toolchain. assert args.sysroot in args.sysroot_src.parents =20 - rust_project =3D { - "crates": generate_crates(args.srctree, args.objtree, args.sysroot= _src, args.exttree, args.cfgs, args.core_edition), - "sysroot": str(args.sysroot), - } + output =3D query_ra_version() + if output: + compatible_ra_version =3D map_ra_version_baseline(output) + else: + default =3D RaVersion.default() + logging.warning("Falling back to `rust-project.json` for rust-anal= yzer %s", default) + compatible_ra_version =3D default + + rust_project =3D generate_rust_project( + compatible_ra_version, + args.srctree, + args.objtree, + args.sysroot, + args.sysroot_src, + args.exttree, + args.cfgs, + args.core_edition, + ) =20 json.dump(rust_project, sys.stdout, sort_keys=3DTrue, indent=3D4) =20 --=20 2.47.3 From nobody Sun Feb 8 06:05:18 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 227402FF652; Fri, 9 Jan 2026 22:10:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767996620; cv=none; b=SwH+fl5dbQLoesV5IOT9m6h2knxrtxTZVuNvWoAEj04Nf7bnLRYhp+suALAleUpGKTxpAGNY5eEopXro/E3VP34cNuYn7DVgzoxUU2vxLYnaNf/DziQxvabJ2/qrQvXlc+tyDzstBQxSS4Sq/s68pzrxa4TMSGbAdepPKJG/pYA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767996620; c=relaxed/simple; bh=CNkIo9NsvwV7c6w44T58l4D4P4jABNgqjrmWc/kE7co=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=YeRNXKsmjn2SKoMOgo+hYgulKr5IGopejS1KD0T/EmKsrEy6N6HVgu3BP46aMEov05UiKiqLcwBpZhkLCoM9FRjDKN6oYOwvuoB0e9inp37Nb7fOXNLdp762g4CQrn8034pisqklcMgIO5YKGvahD2CKSslEUEfyA+0hkMt2SXM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tA7nbL5R; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="tA7nbL5R" Received: by smtp.kernel.org (Postfix) with ESMTPS id C8CA7C19423; Fri, 9 Jan 2026 22:10:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1767996619; bh=CNkIo9NsvwV7c6w44T58l4D4P4jABNgqjrmWc/kE7co=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=tA7nbL5R4IpfYInylmeI/6TEhsYFlfKO6PhT+8jzfFd1MqFJeh0U0lLO5DIg3QtGm +zKmhEQ8jzEZe/+TLoCjHVyPR6wsBA0eKFi7mkQGFec1FwcSlTzDyu9HlyNuUxwHzS wow9nBDvs5Rk9gnTmDSqY/1ihyMc/hCFWXxWlOGUdiZNyKadwELfW086p8sqGDHEIo cBTPsW9e4EgEpY0twfKB6yhNTGjqK1KOyE1n45zyb8AmLj0EWsjUjxsF6h0hlOacEI XUp71EzGtnph+mxHwtouwcgC9WHc6+0MaJ0VzpNYzITorT2Rf9deLpyypPspEaE26g 5aea7F6jHMe+g== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id B9AA6D1A63D; Fri, 9 Jan 2026 22:10:19 +0000 (UTC) From: Jesung Yang via B4 Relay Date: Fri, 09 Jan 2026 22:09:01 +0000 Subject: [PATCH v2 2/2] scripts: generate_rust_analyzer: fix IDE support for primitive types 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: <20260109-ra-fix-primitive-v2-2-249852a4145a@gmail.com> References: <20260109-ra-fix-primitive-v2-0-249852a4145a@gmail.com> In-Reply-To: <20260109-ra-fix-primitive-v2-0-249852a4145a@gmail.com> To: Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Tamir Duberstein Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Jesung Yang X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1767996618; l=4187; i=y.j3ms.n@gmail.com; s=20251225; h=from:subject:message-id; bh=+tPQMcCiMZmTEKJEqCQpRQjsZN53zv5hH8iFQTMRB3M=; b=IgKqVR9SLwszTWWbxy+zbxKBzOqNA4a38Jad2lLcsxW08R+o6bcgL8nv9AAVDkYFl2FtyW/hM X85fmL2z//ECto6Zm9xu8knpfTRcn1Uij3wjzGYjRvhP9sCJjpN0ebv X-Developer-Key: i=y.j3ms.n@gmail.com; a=ed25519; pk=2yVgO1I+y7kkFSF2Dc/Dckj4L2FgRnvmERHFt4bspbI= X-Endpoint-Received: by B4 Relay for y.j3ms.n@gmail.com/20251225 with auth_id=586 X-Original-From: Jesung Yang Reply-To: y.j3ms.n@gmail.com From: Jesung Yang Update `generate_rust_analyzer.py` so that the generated `rust-project.json` contains the `sysroot_src` field with `"crate_attrs": ["no_std"]` specified for relevant crates. This ensures that rust-analyzer provides proper IDE support for inherent methods of primitive types. Since commit 50384460c68f ("Rewrite method resolution to follow rustc more closely") to rust-analyzer, it no longer provides language server features like code completion and go-to-definition for inherent methods of primitive types when sysroot crates (e.g., `core`, `std`) are inlined in `rust-project.json` [1]. As `generate_rust_analyzer.py` currently inlines these crates, our setup is affected by this change. Specifying the `sysroot_src` field restores this functionality by allowing rust-analyzer to locate sysroot crates by itself. However, this causes `std` to be treated as a dependency for all local crates by default. To align with our compilation settings, provide the `no_std` attribute via the `crate_attrs` field, as the `-Zcrate-attr=3Dno_std` compiler flag is not visible to rust-analyzer. This combined approach removes manual manipulation of sysroot dependencies while preventing incorrect symbol resolution against the standard library. Note that this configuration requires rust-analyzer release 2025-12-22 (v0.3.2727) or later, which introduced support for the `crate_attrs` field. Link: https://rust-lang.zulipchat.com/#narrow/channel/x/topic/x/near/561607= 963 [1] Link: https://rust-for-linux.zulipchat.com/#narrow/channel/x/topic/x/near/5= 61607753 Signed-off-by: Jesung Yang --- scripts/generate_rust_analyzer.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_anal= yzer.py index 32b0da99f17549ecc83e9a68911373310a2c9617..6c3cb1d65d97e0ec414192f9fb8= 67700a99c3d57 100755 --- a/scripts/generate_rust_analyzer.py +++ b/scripts/generate_rust_analyzer.py @@ -234,13 +234,16 @@ class RaVersion(enum.Enum): =20 # v0.3.1940, released on 2024-04-29; bundled with the rustup 1.78 tool= chain. V20240429 =3D 0 + # v0.3.2727, released on 2025-12-22. + V20251222 =3D 1 =20 @staticmethod def baselines(): - assert len(RaVersion) =3D=3D 1, "Exhaustiveness check: update base= line list!" + assert len(RaVersion) =3D=3D 2, "Exhaustiveness check: update chec= kpoint list!" =20 return [ (datetime.strptime("2024-04-29", "%Y-%m-%d"), (0, 3, 1940), Ra= Version.V20240429), + (datetime.strptime("2025-12-22", "%Y-%m-%d"), (0, 3, 2727), Ra= Version.V20251222), ] =20 @staticmethod @@ -249,10 +252,12 @@ class RaVersion(enum.Enum): return RaVersion.V20240429 =20 def __str__(self): - assert len(RaVersion) =3D=3D 1, "Exhaustiveness check: update if b= ranches!" + assert len(RaVersion) =3D=3D 2, "Exhaustiveness check: update if b= ranches!" =20 if self =3D=3D RaVersion.V20240429: return "v0.3.1940 (2024-04-29)" + elif self =3D=3D RaVersion.V20251222: + return "v0.3.2727 (2025-12-22)" else: assert False, "Unreachable" =20 @@ -266,7 +271,7 @@ def generate_rust_project( cfgs, core_edition ): - assert len(RaVersion) =3D=3D 1, "Exhaustiveness check: update if branc= hes!" + assert len(RaVersion) =3D=3D 2, "Exhaustiveness check: update if branc= hes!" =20 if ra_version =3D=3D RaVersion.V20240429: ctx =3D { @@ -277,6 +282,16 @@ def generate_rust_project( "crates": generate_crates(ctx, srctree, objtree, sysroot_src, = external_src, cfgs, core_edition), "sysroot": str(sysroot), } + elif ra_version =3D=3D RaVersion.V20251222: + ctx =3D { + "use_crate_attrs": True, + "add_sysroot_crates": False, + } + return { + "crates": generate_crates(ctx, srctree, objtree, sysroot_src, = external_src, cfgs, core_edition), + "sysroot": str(sysroot), + "sysroot_src": str(sysroot_src), + } else: assert False, "Unreachable" =20 --=20 2.47.3