Re: [PATCH v4 1/2] rust: support overriding crate_name
From: Alice Ryhl
Date: Thu Apr 02 2026 - 08:35:49 EST
On Thu, Apr 2, 2026 at 2:23 PM Jesung Yang <y.j3ms.n@xxxxxxxxx> wrote:
>
> On Thu, Apr 2, 2026 at 10:55 AM Alice Ryhl <aliceryhl@xxxxxxxxxx> wrote:
> [...]
> > diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_analyzer.py
> > index b4a55344688d..de6ebf14e2b8 100755
> > --- a/scripts/generate_rust_analyzer.py
> > +++ b/scripts/generate_rust_analyzer.py
> > @@ -12,6 +12,12 @@ import subprocess
> > import sys
> > from typing import Dict, Iterable, List, Literal, Optional, TypedDict
> >
> > +def invoke_rustc(args):
> > + return subprocess.check_output(
> > + [os.environ["RUSTC"]] + args,
> > + stdin=subprocess.DEVNULL,
> > + ).decode('utf-8').strip()
> > +
> > def args_crates_cfgs(cfgs: List[str]) -> Dict[str, List[str]]:
> > crates_cfgs = {}
> > for cfg in cfgs:
> > @@ -69,6 +75,9 @@ def generate_crates(
> > crates: List[Crate] = []
> > crates_cfgs = args_crates_cfgs(cfgs)
> >
> > + def get_crate_name(path):
> > + return invoke_rustc(["--print", "crate-name", path])
> > +
>
> Could you add type hints to `invoke_rustc` and `get_crate_name`? You can
> run the following command to verify if it's all good:
>
> mypy --strict scripts/generate_rust_analyzer.py --python-version 3.9
This seems to work.
def invoke_rustc(args: List[str]) -> str:
return subprocess.check_output(
[os.environ["RUSTC"]] + args,
stdin=subprocess.DEVNULL,
).decode('utf-8').strip()
and
def get_crate_name(path: pathlib.Path) -> str:
return invoke_rustc(["--print", "crate-name", str(path)])
Does that look ok to you? If so, perhaps Miguel can use these on apply?
> Once that's done, for the script part:
>
> Reviewed-by: Jesung Yang <y.jems.n@xxxxxxxxx>
Thanks!
Alice