From nobody Tue Jun 16 15:55:44 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 09CA93FE37C; Thu, 30 Apr 2026 12:15:50 +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=1777551351; cv=none; b=VMTHqNMEtMb8hAsZshmjfHkmq54ClcThZ4HixqmqFLGKSkJ9QTeNZqa76H4pVvpoKPcZ3MIK/1OAhTYCLW3nFFnZTs6PjreV8GKYN+hKGH8giXl4U/w4t3lYGdAo9ldxZLtjzV0zc/nZO9O5THVOcGux1NAAkwkrHlBo+OMkhkQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777551351; c=relaxed/simple; bh=RCNbc1uvpi71j8bIng2IEj+Bs4TkCjn1dKO1Qa+OMRo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=oYuhpDsXyw49Cnjg5Y3lwY7knCvAU6mSPzXh9gOJ4DS4dJaXzw6FyvEZ+pd/iqUwroKPyzchlcVe02sCA04oL/W8qZLZgjZxVBk+zuc8KvSczhO6+BqgtYkUnCDXH4xzjcH14G2tsUQfqeMDN3HgZrxcjZQSk2MN1spgsy1ioSM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FaeLKIUS; 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="FaeLKIUS" Received: by smtp.kernel.org (Postfix) with ESMTPS id BC5C1C2BCC4; Thu, 30 Apr 2026 12:15:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777551350; bh=RCNbc1uvpi71j8bIng2IEj+Bs4TkCjn1dKO1Qa+OMRo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=FaeLKIUSi/B9oZ+ZpGzYb0WOEa02XDTJkTflgNQ2TwnC8gXML1JNEdXun369lAVtp uba7InQjQ+YiQr1vxVJyZvjRnK3vB0MMBdDjvrpOHn4gKlO2kKzxi/tvn9Dx2kX0EN DZO1GosmqqDXS9Lv3nXoNQhLn5b64zrT3K3PjPkRIIdPc9wW0mpKzgKrGVh3KGMaR+ 7JTMZGUBBvBPGUXLxQ8xBrcykoEW0ohD0rzcnjHptykaqh8MVooa/zrmj0yIvGTSuP JLpwiH2xMN9XjIhPM9lJmGNxRXR7QAU6SPDQcoyzdRcR+oxLUM+n42ZzIn4FU8beev WDeqzJUVqihag== 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 AD3A1CCFA13; Thu, 30 Apr 2026 12:15:50 +0000 (UTC) From: Jesung Yang via B4 Relay Date: Thu, 30 Apr 2026 21:15:48 +0900 Subject: [PATCH v5 1/2] scripts: generate_rust_analyzer.py: 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: <20260430-ra-fix-primitive-v5-1-6364d2258e14@gmail.com> References: <20260430-ra-fix-primitive-v5-0-6364d2258e14@gmail.com> In-Reply-To: <20260430-ra-fix-primitive-v5-0-6364d2258e14@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: Eliot Courtney , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Jesung Yang X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1777551349; l=7680; i=y.j3ms.n@gmail.com; s=kernel; h=from:subject:message-id; bh=FawDxUBpo7Rf6mGpoFGMfNonYwDFf7PmnnEfxIP+2dw=; b=UlcVyPuBvN/7Wik3lDyrmxdMv3vSjv+pYjzGqnDw2OfTxA4b7hOwNAmx4BoAjECbxvZKndM2K VY6WHrMGV6+CSbtCtjqSDksHkaeIqvPsaFhf+dtZQklCQYkZumcM9mG X-Developer-Key: i=y.j3ms.n@gmail.com; a=ed25519; pk=4nSlncQuTIIYLyLXkNxS0ssInM3uK0snxLSeQ2tdG/o= X-Endpoint-Received: by B4 Relay for y.j3ms.n@gmail.com/kernel with auth_id=755 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. 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 using the `sysroot_src` field with a feature only available in rust-analyzer v0.3.2727 (2025-12-22) or later, this infrastructure is necessary to maintain compatibility with older rust-analyzer releases. Signed-off-by: Jesung Yang --- scripts/generate_rust_analyzer.py | 171 ++++++++++++++++++++++++++++++++++= +++- 1 file changed, 167 insertions(+), 4 deletions(-) diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_anal= yzer.py index d5f9a0ca742c..f1828620bbbf 100755 --- a/scripts/generate_rust_analyzer.py +++ b/scripts/generate_rust_analyzer.py @@ -4,6 +4,9 @@ """ =20 import argparse +from datetime import datetime, date +import enum +import re import json import logging import os @@ -343,6 +346,148 @@ def generate_crates( =20 return crates =20 + +Version =3D tuple[int, int, int] + + +@enum.unique +class RaVersionInfo(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. + """ + + # NOTE: + # This rust-analyzer release should be kept in sync with our MSRV (cur= rently 1.85.0). + # When the MSRV is bumped, follow the steps below to retrieve the info= rmation needed + # to update this: + # + # 1) Clone both Rust and rust-analyzer repositories. + # ```console + # $ git clone https://github.com/rust-lang/rust.git + # $ git clone https://github.com/rust-lang/rust-analyzer.git + # ``` + # 2) Run the following script, providing the new MSRV as an argument. + # It uses `xdg-open` to open the matching [1] rust-analyzer relea= se page. + # ```bash + # #!/usr/bin/env bash + # + # RUST_VERSION=3D$1 + # LOOKAHEAD=3D50 + # + # subject_string=3D$( + # git -C ./rust log -n "$LOOKAHEAD" --format=3D'%s' "$RUST_VERS= ION" \ + # -- src/tools/rust-analyzer | grep 'Merge pull request #' + # ) + # readarray -t subject_array <<< "$subject_string" + # + # hash=3D$( + # git -C ./rust-analyzer log -n 1 --format=3D'%H' --fixed-strin= gs \ + # "${subject_array[@]/#/--grep=3D}" + # ) + # + # tag_predates=3D$(git -C ./rust-analyzer describe --tags --abbre= v=3D0 "$hash") + # + # link_prefix=3D"https://github.com/rust-lang/rust-analyzer/relea= ses/tag" + # xdg-open "$link_prefix/$tag_predates" + # ``` + # 3) Grab the release date and the version string. + # + # [1] Note that rust-analyzer releases may not perfectly align with th= ose shipped + # in upstream Rust. We take a conservative approach here: use the = tag that + # directly predates the latest merge commit found upstream. + # + # v0.3.2228, released on 2024-12-23; shipped with the rustup 1.85.0 to= olchain. + MSRV =3D ( + datetime.strptime("2024-12-23", "%Y-%m-%d"), + (0, 3, 2228), + (1, 85, 0), + ) + + def __init__( + self, + release_date: date, + ra_version: Version, + rust_version: Version, + ) -> None: + self.release_date =3D release_date + self.ra_version =3D ra_version + self.rust_version =3D rust_version + + +class RustProject(TypedDict): + crates: List[Crate] + sysroot: str + + +def generate_rust_project( + _version_info: RaVersionInfo, + srctree: pathlib.Path, + objtree: pathlib.Path, + sysroot: pathlib.Path, + sysroot_src: pathlib.Path, + external_src: Optional[pathlib.Path], + cfgs: List[str], + core_edition: str, +) -> RustProject: + rust_project: RustProject =3D { + "crates": generate_crates( + srctree, objtree, sysroot_src, external_src, cfgs, core_edition + ), + "sysroot": str(sysroot), + } + + return rust_project + +def query_ra_version() -> Optional[str]: + 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: str) -> RaVersionInfo: + baselines =3D reversed(RaVersionInfo) + + version_match =3D re.search(r"\d+\.\d+\.\d+", ra_version_output) + if version_match: + version_string =3D version_match.group() + found_version =3D tuple(map(int, version_string.split("."))) + + # `rust-analyzer --version` shows a different version string depen= ding on how the binary + # is built: it may print either the Rust version or the rust-analy= zer version itself. + # To distinguish between them, we leverage rust-analyzer's version= ing convention. + # + # See: + # - https://github.com/rust-lang/rust-analyzer/blob/fad5c3d2d642/x= task/src/dist.rs#L19-L21 + is_ra_version =3D version_string.startswith(("0.3", "0.4", "0.5")) + if is_ra_version: + for info in baselines: + if found_version >=3D info.ra_version: + return info + else: + for info in baselines: + if found_version >=3D info.rust_version: + return info + + 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 info in baselines: + if found_date >=3D info.release_date: + return info + + return RaVersionInfo.MSRV + def main() -> None: parser =3D argparse.ArgumentParser() parser.add_argument('--verbose', '-v', action=3D'store_true') @@ -371,10 +516,28 @@ def main() -> None: level=3Dlogging.INFO if args.verbose else logging.WARNING ) =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), - } + ra_version_output =3D query_ra_version() + if ra_version_output: + compatible_ra_version =3D map_ra_version_baseline(ra_version_outpu= t) + else: + logging.warning( + "Falling back to `rust-project.json` for rust-analyzer %s, %s = (shipped with Rust %s)", + ".".join(map(str, RaVersionInfo.MSRV.ra_version)), + datetime.strftime(RaVersionInfo.MSRV.release_date, "%Y-%m-%d"), + ".".join(map(str, RaVersionInfo.MSRV.rust_version)), + ) + compatible_ra_version =3D RaVersionInfo.MSRV + + 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.53.0 From nobody Tue Jun 16 15:55:44 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 1E9234014B6; Thu, 30 Apr 2026 12:15:51 +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=1777551351; cv=none; b=u6M3++WWSFTAozY/z3DWe7A79BIyp3kkjDEUXqmp5WpVfhvHAZZAq59YusOar0s4Ogeip5DoAJc+aKRme+9TBg/6/p0ugpD6btAAMO6DljYo8xpKaNTb7RG7dqUR59iggU08ngT0y/D77ufpNcs+sc9lDo/6KBCe9CB8qlzww8M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777551351; c=relaxed/simple; bh=V6IWnQvMZNHFxIxTl3cHYQg4W3UD3sxfGvHToOPUq1Q=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Llbp26xQLuOBWvqhZVUgjZsL6D/cq1PQ820+IQSGXMbd+rMZhiMZiNeDr8mYksLqmHP1PtMEvMIssGNgTJ3tBSBPOSUmbVPwKWvj+VG8pquSFCV1mGmCWxTXQP6+PdNhsfMSEcHOXscGnrXweXxTxYNY9tomQClDywledLGnrIQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BpxTT0Kk; 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="BpxTT0Kk" Received: by smtp.kernel.org (Postfix) with ESMTPS id CF430C2BCC6; Thu, 30 Apr 2026 12:15:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777551350; bh=V6IWnQvMZNHFxIxTl3cHYQg4W3UD3sxfGvHToOPUq1Q=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=BpxTT0Kkx3mFxOpB22vJFg0ph5YMTQj/xtEjTbKwfD1E0Cm5pHkhymRF7KfuAKjBX A6TieSETws2DNrdouCSzGTSIMLfr/CYTnbQl6K0gZRwI6OMaUe8jCQGjLSYLO4UiSk n9oMnlfXb9MlKzyHu4DG/nrmtJwZt89U/kIfnwOttKlNu/k7TkVFSEIDWkmUyM/wkz px3c5d3qofiGkq3/ZV5jYN3jUHJKjP0voJyDZhmhtXVDz2G73/eTFDssHRm8tFd0Kl DGX8XMEvq1OgT1NUvhfDHrol16PS2dJlmIXUgm6T+rvM3NzTCPpwJt9eyzjqXYt65J l+ynKxFuTmrSw== 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 BDD2FFF8875; Thu, 30 Apr 2026 12:15:50 +0000 (UTC) From: Jesung Yang via B4 Relay Date: Thu, 30 Apr 2026 21:15:49 +0900 Subject: [PATCH v5 2/2] scripts: generate_rust_analyzer.py: 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: <20260430-ra-fix-primitive-v5-2-6364d2258e14@gmail.com> References: <20260430-ra-fix-primitive-v5-0-6364d2258e14@gmail.com> In-Reply-To: <20260430-ra-fix-primitive-v5-0-6364d2258e14@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: Eliot Courtney , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Jesung Yang X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1777551349; l=9491; i=y.j3ms.n@gmail.com; s=kernel; h=from:subject:message-id; bh=Rz+cEco/0hVGRSdqLiVYj+cvw1lt7WQL1eY3hSn48eU=; b=HU04em8HvLLG75G75v5t4zVaJp+6yLyC8Oz48y4Zvk8u59ZYT9/DSdVUBo24eiB3F4+HZsms1 s9Ga9g5IOEoDIKRFyIMxUze6Dc5ovmgWru5+a7VymdLdd06DMeYXHcX X-Developer-Key: i=y.j3ms.n@gmail.com; a=ed25519; pk=4nSlncQuTIIYLyLXkNxS0ssInM3uK0snxLSeQ2tdG/o= X-Endpoint-Received: by B4 Relay for y.j3ms.n@gmail.com/kernel with auth_id=755 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 Reviewed-by: Tamir Duberstein --- scripts/generate_rust_analyzer.py | 107 ++++++++++++++++++++++++++++++----= ---- 1 file changed, 86 insertions(+), 21 deletions(-) diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_anal= yzer.py index f1828620bbbf..f335cbd30fcf 100755 --- a/scripts/generate_rust_analyzer.py +++ b/scripts/generate_rust_analyzer.py @@ -4,6 +4,7 @@ """ =20 import argparse +from dataclasses import dataclass from datetime import datetime, date import enum import re @@ -39,14 +40,28 @@ class Source(TypedDict): exclude_dirs: List[str] =20 =20 -class Crate(TypedDict): - display_name: str - root_module: str - is_workspace_member: bool - deps: List[Dependency] - cfg: List[str] - edition: str - env: Dict[str, str] +# TODO: clean up once Python 3.11 is adopted. +if sys.version_info < (3, 11): + class Crate(TypedDict, total=3DFalse): + display_name: str + root_module: str + is_workspace_member: bool + deps: List[Dependency] + cfg: List[str] + crate_attrs: List[str] + edition: str + env: Dict[str, str] +else: + from typing import NotRequired + class Crate(TypedDict): + display_name: str + root_module: str + is_workspace_member: bool + deps: List[Dependency] + cfg: List[str] + crate_attrs: NotRequired[List[str]] + edition: str + env: Dict[str, str] =20 =20 class ProcMacroCrate(Crate): @@ -58,7 +73,14 @@ class CrateWithGenerated(Crate): source: Source =20 =20 +@dataclass(frozen=3DTrue) +class RaVersionCtx: + manual_sysroot_crates: bool + use_crate_attrs: bool + + def generate_crates( + ctx: RaVersionCtx, srctree: pathlib.Path, objtree: pathlib.Path, sysroot_src: pathlib.Path, @@ -84,22 +106,24 @@ def generate_crates( def build_crate( display_name: str, root_module: pathlib.Path, - deps: List[Dependency], + deps: List[Optional[Dependency]], *, cfg: Optional[List[str]], + crate_attrs: Optional[List[str]], is_workspace_member: Optional[bool], edition: Optional[str], ) -> Crate: + filtered_deps =3D [dep for dep in deps if dep is not None] cfg =3D cfg if cfg is not None else crates_cfgs.get(display_name, = []) is_workspace_member =3D ( is_workspace_member if is_workspace_member is not None else Tr= ue ) edition =3D edition if edition is not None else "2021" - return { + crate: Crate =3D { "display_name": display_name, "root_module": str(root_module), "is_workspace_member": is_workspace_member, - "deps": deps, + "deps": filtered_deps, "cfg": cfg, "edition": edition, "env": { @@ -107,10 +131,15 @@ def generate_crates( } } =20 + if ctx.use_crate_attrs and crate_attrs is not None: + crate["crate_attrs"] =3D crate_attrs + + return crate + def append_proc_macro_crate( display_name: str, root_module: pathlib.Path, - deps: List[Dependency], + deps: List[Optional[Dependency]], *, cfg: Optional[List[str]] =3D None, is_workspace_member: Optional[bool] =3D None, @@ -121,6 +150,7 @@ def generate_crates( root_module, deps, cfg=3Dcfg, + crate_attrs=3DNone, is_workspace_member=3Dis_workspace_member, edition=3Dedition, ) @@ -148,9 +178,10 @@ def generate_crates( def append_crate( display_name: str, root_module: pathlib.Path, - deps: List[Dependency], + deps: List[Optional[Dependency]], *, cfg: Optional[List[str]] =3D None, + crate_attrs: Optional[List[str]] =3D None, is_workspace_member: Optional[bool] =3D None, edition: Optional[str] =3D None, ) -> Dependency: @@ -160,6 +191,7 @@ def generate_crates( root_module, deps, cfg=3Dcfg, + crate_attrs=3Dcrate_attrs, is_workspace_member=3Dis_workspace_member, edition=3Dedition, ) @@ -167,10 +199,12 @@ def generate_crates( =20 def append_sysroot_crate( display_name: str, - deps: List[Dependency], + deps: List[Optional[Dependency]], *, cfg: Optional[List[str]] =3D None, - ) -> Dependency: + ) -> Optional[Dependency]: + if not ctx.manual_sysroot_crates: + return None return append_crate( display_name, sysroot_src / display_name / "src" / "lib.rs", @@ -269,13 +303,14 @@ def generate_crates( =20 def append_crate_with_generated( display_name: str, - deps: List[Dependency], + deps: List[Optional[Dependency]], ) -> Dependency: crate =3D build_crate( display_name, srctree / "rust"/ display_name / "lib.rs", deps, cfg=3Dgenerated_cfg, + crate_attrs=3DNone, is_workspace_member=3DTrue, edition=3DNone, ) @@ -342,6 +377,7 @@ def generate_crates( path, [core, kernel, pin_init], cfg=3Dgenerated_cfg, + crate_attrs=3D["no_std"], ) =20 return crates @@ -402,6 +438,20 @@ class RaVersionInfo(enum.Enum): datetime.strptime("2024-12-23", "%Y-%m-%d"), (0, 3, 2228), (1, 85, 0), + RaVersionCtx( + use_crate_attrs=3DFalse, + manual_sysroot_crates=3DTrue, + ), + ) + # v0.3.2727, released on 2025-12-22; v0.3.2743 is shipped with the rus= tup 1.94.0 toolchain. + SUPPROTS_CRATE_ATTRS =3D ( + datetime.strptime("2025-12-22", "%Y-%m-%d"), + (0, 3, 2727), + (1, 94, 0), + RaVersionCtx( + use_crate_attrs=3DTrue, + manual_sysroot_crates=3DFalse, + ), ) =20 def __init__( @@ -409,19 +459,30 @@ class RaVersionInfo(enum.Enum): release_date: date, ra_version: Version, rust_version: Version, + ctx: RaVersionCtx, ) -> None: self.release_date =3D release_date self.ra_version =3D ra_version self.rust_version =3D rust_version + self.ctx =3D ctx =20 =20 -class RustProject(TypedDict): - crates: List[Crate] - sysroot: str +# TODO: clean up once Python 3.11 is adopted. +if sys.version_info < (3, 11): + class RustProject(TypedDict, total=3DFalse): + crates: List[Crate] + sysroot: str + sysroot_src: str +else: + from typing import NotRequired + class RustProject(TypedDict): + crates: List[Crate] + sysroot: str + sysroot_src: NotRequired[str] =20 =20 def generate_rust_project( - _version_info: RaVersionInfo, + version_info: RaVersionInfo, srctree: pathlib.Path, objtree: pathlib.Path, sysroot: pathlib.Path, @@ -430,13 +491,17 @@ def generate_rust_project( cfgs: List[str], core_edition: str, ) -> RustProject: + ctx =3D version_info.ctx rust_project: RustProject =3D { "crates": generate_crates( - srctree, objtree, sysroot_src, external_src, cfgs, core_edition + ctx, srctree, objtree, sysroot_src, external_src, cfgs, core_e= dition ), "sysroot": str(sysroot), } =20 + if not ctx.manual_sysroot_crates: + rust_project["sysroot_src"] =3D str(sysroot_src) + return rust_project =20 def query_ra_version() -> Optional[str]: --=20 2.53.0