From: "Jesung Yang" <y.j3ms.n@gmail.com>
To: "Tamir Duberstein" <tamird@kernel.org>,
"Jesung Yang" <y.j3ms.n@gmail.com>
Cc: "Miguel Ojeda" <ojeda@kernel.org>, "Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
"Boqun Feng" <boqun@kernel.org>,
"Eliot Courtney" <ecourtney@nvidia.com>,
rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 1/2] scripts: generate_rust_analyzer.py: add versioning infrastructure
Date: Tue, 17 Mar 2026 18:05:27 +0900 [thread overview]
Message-ID: <DH4XREQ17DU8.2V3F4JZ5ZO0UY@gmail.com> (raw)
In-Reply-To: <177367187873.68572.13759534078660151207@1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa>
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@gmail.com> 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
next prev parent reply other threads:[~2026-03-17 9:05 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-07 23:30 [PATCH v3 0/2] rust: take advantage of newer rust-analyzer features Jesung Yang via B4 Relay
2026-03-07 23:30 ` [PATCH v3 1/2] scripts: generate_rust_analyzer.py: add versioning infrastructure Jesung Yang via B4 Relay
2026-03-09 18:34 ` Tamir Duberstein
2026-03-15 7:01 ` Jesung Yang
2026-03-16 14:37 ` Tamir Duberstein
2026-03-17 9:05 ` Jesung Yang [this message]
2026-03-07 23:30 ` [PATCH v3 2/2] scripts: generate_rust_analyzer.py: fix IDE support for primitive types Jesung Yang via B4 Relay
2026-03-09 18:34 ` Tamir Duberstein
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=DH4XREQ17DU8.2V3F4JZ5ZO0UY@gmail.com \
--to=y.j3ms.n@gmail.com \
--cc=a.hindborg@kernel.org \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=ecourtney@nvidia.com \
--cc=gary@garyguo.net \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox