Re: [PATCH v3 1/2] scripts: generate_rust_analyzer.py: add versioning infrastructure
From: Tamir Duberstein
Date: Mon Mar 16 2026 - 10:39:49 EST
On 2026-03-15 16:01 +0900, Jesung Yang wrote:
> On Tue Mar 10, 2026 at 3:34 AM KST, Tamir Duberstein wrote:
> > On Sun, 08 Mar 2026 08:30:34 +0900, Jesung Yang <y.j3ms.n@xxxxxxxxx> wrote:
> [...]
> >> @@ -335,12 +390,90 @@ def generate_crates(
> >> append_crate(
> >> name,
> >> path,
> >> - [core, kernel, pin_init],
> >> + sysroot_deps(core) + [kernel, pin_init],
> >> cfg=generated_cfg,
> >> + crate_attrs=["no_std"],
> >> )
> >
> > Can you help me understand this addition? It's not mentioned except in the
> > cover letter as a diff from v2.
>
> Assuming you're referring to `crate_attrs=["no_std"]`, this makes
> rust-analyzer treat crates in `driver/` and `samples/` as if
> `#![no_std]` were specified in their crate roots (they don't contain
> `#![no_std]` themselves).
Yes, that's what I was referring to. Still, it's not clear to me why
that is part of this patch. Is it intentional, or incidental?
>
> (Actually, I'm uncertain if this is the part you wanted me to elaborate
> on. Please let me know if you need more context.)
Yes, sorry for the ambiguity.
>
> >> +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:
> >> + assert len(BASELINES) == 1, "Exhaustiveness check: update if branches!"
> >> +
> >> + ctx: RaVersionCtx
> >> +
> >
> > Could we make RaVersionInfo an enum? That would allow mypy to do this check
> > (using `match`) rather than relying on this.
>
> I think you want something like the following?
>
> @enum.unique
> class RaVersionInfo(enum.Enum):
> V20240311 = (
> datetime.strptime("2024-03-11", "%Y-%m-%d"),
> ra_version=(0, 3, 1877),
> rust_version=(1, 78, 0),
> )
> V20251222 = ( ... )
>
> def __init__(
> self,
> release_date: date,
> ra_version: Version,
> rust_version: Version,
> ) -> "RaVersionInfo":
> self.release_date = release_date
> self.ra_version = ra_version
> self.rust_version = rust_version
>
> @staticmethod
> def default() -> "RaVersionInfo":
> return RaVersionInfo.V20240311
>
> At the call site, we can access each field via the dot operator. This
> not only removes `BASELINES` and `DEFAULT_BASELINE` but also ensures
> that we only match against valid variants, which helps reduce the chance
> of human error. But unfortunately, `match` was introduced in Python
> 3.10, whereas the kernel only requires Python 3.9 [1]. This means we
> cannot leverage mypy's exhaushtiveness check yet. Perhaps I could leave
> a TODO to remove the assertion and switch to `match` once Python 3.10 is
> adopted.
That sounds reasonable to me. You can also name the variants in a more
semantically meaningful way like DEFAULT, SUPPORTS_XXX, etc.
Finally, `__init__` should return None, not Self.
>
> The rest of the feedback sounds reasonable to me.
>
> [1] https://docs.kernel.org/process/changes.html#kernel-documentation
>
> Best regards,
> Jesung
>
Thanks for working on this!