mirror of
https://github.com/torvalds/linux.git
synced 2026-07-27 17:47:41 +02:00
scripts: generate_rust_analyzer: support passing env vars
A future commit adding `zerocopy` support will need to pass an environment variable during its build. Thus add support for an `--envs` parameter, similar to `--cfgs`, that allows to pass a map of variables to set for a given crate. This allows us to keep a single source of truth for those values. No change intended in the generated `rust-project.json`. Acked-by: Tamir Duberstein <tamird@kernel.org> Link: https://patch.msgid.link/20260608141439.182634-2-ojeda@kernel.org Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
This commit is contained in:
parent
759da9e0fa
commit
8b1549eee9
|
|
@ -26,6 +26,14 @@ def args_crates_cfgs(cfgs: List[str]) -> Dict[str, List[str]]:
|
|||
|
||||
return crates_cfgs
|
||||
|
||||
def args_crates_envs(envs: List[str]) -> Dict[str, Dict[str, str]]:
|
||||
crates_envs = {}
|
||||
for env in envs:
|
||||
crate, vals = env.split("=", 1)
|
||||
crates_envs[crate] = dict(v.split("=", 1) for v in vals.split())
|
||||
|
||||
return crates_envs
|
||||
|
||||
class Dependency(TypedDict):
|
||||
crate: int
|
||||
name: str
|
||||
|
|
@ -61,6 +69,7 @@ def generate_crates(
|
|||
sysroot_src: pathlib.Path,
|
||||
external_src: Optional[pathlib.Path],
|
||||
cfgs: List[str],
|
||||
envs: List[str],
|
||||
core_edition: str,
|
||||
) -> List[Crate]:
|
||||
# Generate the configuration list.
|
||||
|
|
@ -74,6 +83,7 @@ def generate_crates(
|
|||
# Now fill the crates list.
|
||||
crates: List[Crate] = []
|
||||
crates_cfgs = args_crates_cfgs(cfgs)
|
||||
crates_envs = args_crates_envs(envs)
|
||||
|
||||
def get_crate_name(path: pathlib.Path) -> str:
|
||||
return invoke_rustc(["--print", "crate-name", str(path)])
|
||||
|
|
@ -92,6 +102,10 @@ def generate_crates(
|
|||
is_workspace_member if is_workspace_member is not None else True
|
||||
)
|
||||
edition = edition if edition is not None else "2021"
|
||||
crate_env = {
|
||||
"RUST_MODFILE": "This is only for rust-analyzer",
|
||||
**crates_envs.get(display_name, {}),
|
||||
}
|
||||
return {
|
||||
"display_name": display_name,
|
||||
"root_module": str(root_module),
|
||||
|
|
@ -99,9 +113,7 @@ def generate_crates(
|
|||
"deps": deps,
|
||||
"cfg": cfg,
|
||||
"edition": edition,
|
||||
"env": {
|
||||
"RUST_MODFILE": "This is only for rust-analyzer"
|
||||
}
|
||||
"env": crate_env,
|
||||
}
|
||||
|
||||
def append_proc_macro_crate(
|
||||
|
|
@ -347,6 +359,7 @@ def main() -> None:
|
|||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--verbose', '-v', action='store_true')
|
||||
parser.add_argument('--cfgs', action='append', default=[])
|
||||
parser.add_argument('--envs', action='append', default=[])
|
||||
parser.add_argument("core_edition")
|
||||
parser.add_argument("srctree", type=pathlib.Path)
|
||||
parser.add_argument("objtree", type=pathlib.Path)
|
||||
|
|
@ -357,6 +370,7 @@ def main() -> None:
|
|||
class Args(argparse.Namespace):
|
||||
verbose: bool
|
||||
cfgs: List[str]
|
||||
envs: List[str]
|
||||
srctree: pathlib.Path
|
||||
objtree: pathlib.Path
|
||||
sysroot: pathlib.Path
|
||||
|
|
@ -372,7 +386,7 @@ def main() -> None:
|
|||
)
|
||||
|
||||
rust_project = {
|
||||
"crates": generate_crates(args.srctree, args.objtree, args.sysroot_src, args.exttree, args.cfgs, args.core_edition),
|
||||
"crates": generate_crates(args.srctree, args.objtree, args.sysroot_src, args.exttree, args.cfgs, args.envs, args.core_edition),
|
||||
"sysroot": str(args.sysroot),
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user