Re: [PATCH v3 1/2] scripts: generate_rust_analyzer.py: add versioning infrastructure
From: Jesung Yang
Date: Sun Mar 15 2026 - 03:01:55 EST
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).
(Actually, I'm uncertain if this is the part you wanted me to elaborate
on. Please let me know if you need more context.)
>> +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.
The rest of the feedback sounds reasonable to me.
[1] https://docs.kernel.org/process/changes.html#kernel-documentation
Best regards,
Jesung