From nobody Fri Dec 19 04:15:06 2025 Received: from mail-qv1-f49.google.com (mail-qv1-f49.google.com [209.85.219.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 99C0C244679; Thu, 24 Apr 2025 10:38:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745491135; cv=none; b=CMSOq5kXVNkegQSyIIk8kfjgnpXmpHU3c84fU+u2ue1/EA/iLbrIT7zc/PsVRXJ6vRvB53Ov7oCmIywfvQUM4WWmvRRAP3nennj4BxlFU73tIdT8k/rQb0cHnCpAnARCq0a3147Lei4UZVcGJUJ/uPgfFWd+am7SEdIFpHhY6ZY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745491135; c=relaxed/simple; bh=fspxg+uNYQg/0xMHqz7C9hQnM6mWytkwf+DymD/SJHY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Ya2ddGuwAJKoHebURguDG8QWPWhpjFDyA3W30+3bWjG+x12ohjBPd0/Q8d49TMd5Uwmnajv68zZcZ2Oqrp4pzkub1dvuj1QiERQQP2O0k8tra007fTXOh1brXxqpHh/Zr1/t7Bk+XZabZu3U6OurRTVN7IkLPaUvy6R4Tk7MPDQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=iv3KbTy0; arc=none smtp.client-ip=209.85.219.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="iv3KbTy0" Received: by mail-qv1-f49.google.com with SMTP id 6a1803df08f44-6eaf1b6ce9aso10734966d6.2; Thu, 24 Apr 2025 03:38:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1745491132; x=1746095932; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=OCGT2JlziqqiSztKJ7xnMu1WkpausWLoKCYcx1OKs3U=; b=iv3KbTy03eFTzhIix5MprYPgYmIJuQZVBd3USpPAOzCo0XBkMNh60FNWXvNu/AL6Mk wHxUFebDofsssQxdz5e5KZOOMPv+W5prYyk0hbRlHiFG6nqXrdnv7VsCNTtrvT+QoVPr oGnmsYfbMoZIKVQgONYtwqwpJs7UrZL0OIiHWd4RQV3QZ+zJqGtiGhYec2vYMd48ARho mUd8gg0nOluCgfb0RZA6FKdljrktOST3Ahfc3ACOkrkzcDpuBmWAv32tCnmRU3Dk6RPf eeSvuueURbF8OWs4G/PUWsLLnS9U/NrC5XEFZp1lnq5i1F3CK1tAiH33ykM08cGbWZA5 ivhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745491132; x=1746095932; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OCGT2JlziqqiSztKJ7xnMu1WkpausWLoKCYcx1OKs3U=; b=TIuFnSBsTCZNx8/duiJLQ+0C6r9yJx8Ybzb22MP7nVBSUZtHnkDYeofogon7TAZm01 Gxh+3nFfxwBz/cbR/PSJqD9gnjWBaOq3WwhVmAGLXvnVTLDjqvvZAsMmLNtY6nvJq/PD e751HDeBwHmsvvRcD7t4NqO/13BuN6t9dV/wAeQRgT7IAsDAPUx+Vihk5cEmH6KfMq8u A2zSN74NWoWCeWnyyNAM2uvCbJQifvGNStX3g55S4T5nVlS7sb98gDGq5t7roCzx4py2 BgXI2e25cDYx+BSy/R7oHh7/nTHa5ukFZ1VUULSgBEGq8Xv11UDzd3XS4PgejLVnWNRl CzIQ== X-Forwarded-Encrypted: i=1; AJvYcCWBidwe8AAQB2ZlNIUHWZJsuegEWLmskUYGbnHkDIRVreEl+npxaCuwr3/RNOjDf1dkSeNCLqzpo0QKj2o=@vger.kernel.org X-Gm-Message-State: AOJu0YwJ1fCp2XNjwlFJPve8/ZY8Is8CVZX6S7P29vPcFkZzVPyJXEXJ QJjAyvWW9HnKWSxi8YBNlM8WY0uEoaKhnGp8rFQAahs8mNY70Lal X-Gm-Gg: ASbGnctoy6sC/SMp8DoAL7WCVAT4W0EYShm/+QRu/v5Fc/x1fd7CSehmi9WL2HD97oG zbKRddlg5HEELtpRKTdk/V4NCLwJ58WJSCq8ttpYZ/WR7aTcmk39SaAUlMx7u2Dfdq9rMl2wHAn Bd0WcG88jYlA1IXBDinwBFrAS73iRBFaZ74rPLgz1b8Sj1xFjojzc011Sr74J3ZN3NzeRM9c0fs TLygkP/wdksu1L42HQ8EpGKKF3bLq/iZBE6TIuM2bMrsA+wQ8axr1hGcWFFV/q/kHswUC04isMM QTJspDkcsSkDcIbOCIRzXB28kX+tqQb6glsrLaIq9kzl2JLKfvhBBuLd4DPArc7nHkDZIiJLEvu Yqqs= X-Google-Smtp-Source: AGHT+IFtbTUg/NlHp+xGGR8hhVqM+3uqW4XpfmIRTs3e+e1XwqiOWrT05niehzviMiK9ZEWlb8+M4A== X-Received: by 2002:a0c:cdc2:0:b0:6f4:c63e:4cdc with SMTP id 6a1803df08f44-6f4c63e4e4emr3337556d6.0.1745491132296; Thu, 24 Apr 2025 03:38:52 -0700 (PDT) Received: from [192.168.1.159] ([2600:4041:5be7:7c00:4047:3830:186a:1bb1]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6f4c0a73b63sm7839096d6.70.2025.04.24.03.38.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Apr 2025 03:38:51 -0700 (PDT) From: Tamir Duberstein Date: Thu, 24 Apr 2025 06:38:37 -0400 Subject: [PATCH v6 09/13] scripts: generate_rust_analyzer.py: identify crates explicitly Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250424-rust-analyzer-host-v6-9-40e67fe5c38a@gmail.com> References: <20250424-rust-analyzer-host-v6-0-40e67fe5c38a@gmail.com> In-Reply-To: <20250424-rust-analyzer-host-v6-0-40e67fe5c38a@gmail.com> To: Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Boris-Chengbiao Zhou , Kees Cook , Fiona Behrens Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Lukas Wirth , Tamir Duberstein , Daniel Almeida X-Mailer: b4 0.15-dev Use the return of `append_crate` to declare dependency on that crate. This allows multiple crates with the same display_name be defined, which we'll use to define host crates separately from target crates. Reviewed-by: Fiona Behrens Reviewed-by: Daniel Almeida Tested-by: Daniel Almeida Reviewed-by: Trevor Gross Signed-off-by: Tamir Duberstein --- scripts/generate_rust_analyzer.py | 88 +++++++++++++++++++----------------= ---- 1 file changed, 43 insertions(+), 45 deletions(-) diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_anal= yzer.py index bc23cf58e7a1..b281e87cfa30 100755 --- a/scripts/generate_rust_analyzer.py +++ b/scripts/generate_rust_analyzer.py @@ -60,17 +60,14 @@ def generate_crates( line =3D line.replace("\n", "") cfg.append(line) =20 - # Now fill the crates list -- dependencies need to come first. - # - # Avoid O(n^2) iterations by keeping a map of indexes. + # Now fill the crates list. crates: List[Crate] =3D [] - crates_indexes: Dict[str, int] =3D {} =20 def build_crate( display_name: str, root_module: pathlib.Path, *, - deps: List[str], + deps: List[Dependency], cfg: List[str], is_workspace_member: bool, ) -> Crate: @@ -78,7 +75,7 @@ def generate_crates( "display_name": display_name, "root_module": str(root_module), "is_workspace_member": is_workspace_member, - "deps": [{"crate": crates_indexes[dep], "name": dep} for dep i= n deps], + "deps": deps, "cfg": cfg, "edition": "2021", "env": { @@ -86,18 +83,19 @@ def generate_crates( }, } =20 - def register_crate(crate: Crate) -> None: - crates_indexes[crate["display_name"]] =3D len(crates) + def register_crate(crate: Crate) -> Dependency: + index =3D len(crates) crates.append(crate) + return {"crate": index, "name": crate["display_name"]} =20 def append_crate( display_name: str, root_module: pathlib.Path, *, - deps: List[str], + deps: List[Dependency], cfg: List[str], - ) -> None: - register_crate( + ) -> Dependency: + return register_crate( build_crate( display_name, root_module, @@ -111,9 +109,9 @@ def generate_crates( display_name: str, root_module: pathlib.Path, *, - deps: List[str], + deps: List[Dependency], cfg: List[str], - ) -> None: + ) -> Dependency: crate =3D build_crate( display_name, root_module, @@ -143,15 +141,15 @@ def generate_crates( "is_proc_macro": True, "proc_macro_dylib_path": str(objtree / "rust" / proc_macro_dyl= ib_name), } - register_crate(proc_macro_crate) + return register_crate(proc_macro_crate) =20 def append_sysroot_crate( display_name: str, *, - deps: List[str], + deps: List[Dependency], cfg: List[str], - ) -> None: - register_crate( + ) -> Dependency: + return register_crate( build_crate( display_name, sysroot_src / display_name / "src" / "lib.rs", @@ -164,59 +162,59 @@ def generate_crates( # NB: sysroot crates reexport items from one another so setting up our= transitive dependencies # here is important for ensuring that rust-analyzer can resolve symbol= s. The sources of truth # for this dependency graph are `(sysroot_src / crate / "Cargo.toml" f= or crate in crates)`. - append_sysroot_crate("core", deps=3D[], cfg=3Dcrates_cfgs["core"]) - append_sysroot_crate("alloc", deps=3D["core"], cfg=3D[]) - append_sysroot_crate("std", deps=3D["alloc", "core"], cfg=3D[]) - append_sysroot_crate("proc_macro", deps=3D["core", "std"], cfg=3D[]) + core =3D append_sysroot_crate("core", deps=3D[], cfg=3Dcrates_cfgs["co= re"]) + alloc =3D append_sysroot_crate("alloc", deps=3D[core], cfg=3D[]) + std =3D append_sysroot_crate("std", deps=3D[alloc, core], cfg=3D[]) + proc_macro =3D append_sysroot_crate("proc_macro", deps=3D[core, std], = cfg=3D[]) =20 - append_crate( + compiler_builtins =3D append_crate( "compiler_builtins", srctree / "rust" / "compiler_builtins.rs", deps=3D[], cfg=3D[], ) =20 - append_proc_macro_crate( + macros =3D append_proc_macro_crate( "macros", srctree / "rust" / "macros" / "lib.rs", - deps=3D["std", "proc_macro"], + deps=3D[std, proc_macro], cfg=3D[], ) =20 - append_crate( + build_error =3D append_crate( "build_error", srctree / "rust" / "build_error.rs", - deps=3D["core", "compiler_builtins"], + deps=3D[core, compiler_builtins], cfg=3D[], ) =20 - append_proc_macro_crate( + pin_init_internal =3D append_proc_macro_crate( "pin_init_internal", srctree / "rust" / "pin-init" / "internal" / "src" / "lib.rs", deps=3D[], cfg=3D["kernel"], ) =20 - append_crate( + pin_init =3D append_crate( "pin_init", srctree / "rust" / "pin-init" / "src" / "lib.rs", - deps=3D["core", "pin_init_internal", "macros"], + deps=3D[core, pin_init_internal, macros], cfg=3D["kernel"], ) =20 - append_crate( + ffi =3D append_crate( "ffi", srctree / "rust" / "ffi.rs", - deps=3D["core", "compiler_builtins"], + deps=3D[core, compiler_builtins], cfg=3D[], ) =20 def append_crate_with_generated( display_name: str, *, - deps: List[str], + deps: List[Dependency], cfg: List[str], - ) -> None: + ) -> Dependency: crate =3D build_crate( display_name, srctree / "rust" / display_name / "lib.rs", @@ -235,20 +233,20 @@ def generate_crates( "exclude_dirs": [], } } - register_crate(crate_with_generated) + return register_crate(crate_with_generated) =20 - append_crate_with_generated("bindings", deps=3D["core", "ffi"], cfg=3D= []) - append_crate_with_generated("uapi", deps=3D["core", "ffi"], cfg=3D[]) - append_crate_with_generated( + bindings =3D append_crate_with_generated("bindings", deps=3D[core, ffi= ], cfg=3D[]) + uapi =3D append_crate_with_generated("uapi", deps=3D[core, ffi], cfg= =3D[]) + kernel =3D append_crate_with_generated( "kernel", deps=3D[ - "core", - "macros", - "build_error", - "pin_init", - "ffi", - "bindings", - "uapi", + core, + macros, + build_error, + pin_init, + ffi, + bindings, + uapi, ], cfg=3D[], ) @@ -279,7 +277,7 @@ def generate_crates( append_crate( name, path, - deps=3D["core", "kernel"], + deps=3D[core, kernel], cfg=3Dcfg, ) =20 --=20 2.49.0