Re: [PATCH v3 1/2] scripts: generate_rust_analyzer.py: add versioning infrastructure
From: Jesung Yang
Date: Tue Mar 17 2026 - 05:05:40 EST
On Mon Mar 16, 2026 at 11:37 PM KST, Tamir Duberstein wrote:
> 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?
Ah, now I see your point. Yes, this should be in `scripts:
generate_rust_analyzer.py: fix IDE support for primitive types`
(PATCH [2/2]).
>> >> +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.
Sounds good to me.
On second thought, I think we can also take advantage of mypy's static
exhaustiveness check by introducing `assert_never`. I'll send v4 and
let's see if it works for you too.
> Finally, `__init__` should return None, not Self.
Absolutely, I'll make that change.
> Thanks for working on this!
My pleasure!
Best regards,
Jesung