From nobody Fri Apr 3 22:21:05 2026 Received: from mail-ej1-f74.google.com (mail-ej1-f74.google.com [209.85.218.74]) (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 07D1638B145 for ; Mon, 23 Mar 2026 10:33:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774262013; cv=none; b=DLro156sJzLaNqH3jupS6YgoVCHBrYq3cSXO9Vb/xV6nTGYzex6DWlmvk1QGz88wkn+I0i3rdmclhqbJz+GI01HUSAfZp5GXHoJD7sQdTc+g8HB8SwrvwcMIdzExDYiCEi0DgyFri5Ju3DlUfu6ssZ7PJCgWhq1XQ9WT7jQFAf8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774262013; c=relaxed/simple; bh=0NDUGRZwk5uOld6MMOr2tuHSCfP+PEc0iYbeGfdR12A=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=OSR4brNIpCAmkJ4UJ6JksPfKe+s8OkYgrTj7clShbtLLq/6v2Ii3Hp0VYH65IV8Bgt8iaiA7ByaQnv63BkKTY59U1xnDWDZ/VRqi5/2GG349Wvu0PPXQtfAbdQP45VFIQO9WRaOjqA7RseXAaM2nxXzrE3F53UJnh3ZqEgmPrRg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=U7A/fOqD; arc=none smtp.client-ip=209.85.218.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="U7A/fOqD" Received: by mail-ej1-f74.google.com with SMTP id a640c23a62f3a-b97f04b44b9so955566b.0 for ; Mon, 23 Mar 2026 03:33:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1774262007; x=1774866807; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=5Yeiatc+pINFBHwlsxMYopCtRI4xRYV4LjxYmtdeTlM=; b=U7A/fOqDYA5EAJ1U89zftgeZurGwzqRvzVlnsII7yU9TZZcGBtN/d2oarJLYAtLhc1 n/4dute9J4FwazOFb804qZL/AzyHROKDrp0eXCPFdKF5yokhEF94nT+0MsnCmyiTdkX1 QWuBkfnGrJLaXHEQdjfiFJoIQ3Q0WuqG5QRguWj2eaILXCbbOI9EgYIMpCCDNmpwUvJt O3B0K17mfzu5tcnL4M54DVlV4qthMWV1KeY8yIeVyj4QvsxrsU8IAmldsnNbIf3dRCJM nG4RXPT51RzHyLP7cM7dAhd04X+6FCS0Jy2AeEGYktTnkgIleV3NN61jVebMEQ+5ocP/ br3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774262007; x=1774866807; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=5Yeiatc+pINFBHwlsxMYopCtRI4xRYV4LjxYmtdeTlM=; b=SFYU1wm2KxzyZ+joeEec3JN/ayy1kfDmwFJiWLt03C9VYdnjgeK4+TpAbnafKzCIPj KxCB+d075vd+ax4TKWKvVj73J5+24GEEkzmsj6pLBOldNmRFZLrITbjUi5JgrMf2mftQ gGDaedR+FIibHYZYM/tTiK7Xt3raA4P4ynYxCHQtg4qxt4RnHk1LP+JD/ThrwjGCfDqa fJhNSh9mjMehfK+Aq2Xwrdxkcf75jUOC6YGO9o2jpS5ylejNtja3NbBKlMqUGMxZq/HN /0G1t+Vutv9033J7rLeif1O/A0tloMpmPAAvxujhG5eH4TXb5uCRzPtEPm7nppxJy9MO j9fw== X-Forwarded-Encrypted: i=1; AJvYcCVcmMk+z6wEF4vK36esISeKyLzaDoBVo8wNMp5KC8FrkbPxktaOGsLgJ049h4XgbnX4coU6wFm8kbQBDYQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yx4+6QCXjOHGyw8yERDI8AINSJ1xlDa34DCJxK9yf4V0b2bBRTf yEZJI/lQZLFKuXO6/rWU6bUsPeiwGXRZlfHu7hWCtIec7/snyDVc8H5B/HxkfuIxiNWhoCcbrlY bD//zBncamJIBcssWqw== X-Received: from ejcqw5.prod.google.com ([2002:a17:906:6a05:b0:b97:3111:1324]) (user=aliceryhl job=prod-delivery.src-stubby-dispatcher) by 2002:a17:907:c50a:b0:b87:2f29:2060 with SMTP id a640c23a62f3a-b982f399b4fmr773886266b.26.1774262007045; Mon, 23 Mar 2026 03:33:27 -0700 (PDT) Date: Mon, 23 Mar 2026 10:33:10 +0000 In-Reply-To: <20260323-binder-crate-name-v3-0-c6e00f239fb1@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260323-binder-crate-name-v3-0-c6e00f239fb1@google.com> X-Developer-Key: i=aliceryhl@google.com; a=openpgp; fpr=49F6C1FAA74960F43A5B86A1EE7A392FDE96209F X-Developer-Signature: v=1; a=openpgp-sha256; l=5100; i=aliceryhl@google.com; h=from:subject:message-id; bh=0NDUGRZwk5uOld6MMOr2tuHSCfP+PEc0iYbeGfdR12A=; b=owEBbQKS/ZANAwAKAQRYvu5YxjlGAcsmYgBpwRbzNf7H3Ne82WA8r4Tks4qMR/DRP3G+cdtr+ FK5OUUrhXuJAjMEAAEKAB0WIQSDkqKUTWQHCvFIvbIEWL7uWMY5RgUCacEW8wAKCRAEWL7uWMY5 Ri1zD/9P9C5PTvJyRRS6GXNbDiPNI7DF5DqhpHBGagLtaTLUB24cZGnGDyMx1e53QKEKOryEDPq L5FLLIV58DelEQ8GjoA8gG07rDLsY6AcbhUH+yd+/JyPbZBGDdfcLGT1xqVS6/CR7qo0xLAwK4d xG5RnRKR+aCVjRPnRkRwMqfJq4ReW0agBwavxZs6LRpjvmVuVmBM9u3Z/+/z6TeXJDXoFm4NVfY ZwuCFKpW5/3uHuVVzQVgirMLZFwL0GxSagXrQ0wDA9eaMPG1h+L1Sg7Ff0hz/qoAidqLcIgOWWd otdPgEJ8qWOS5FpkHMDDxj6TbPIgIfgyw2U3mGhSeAI1ScHvDzABj4jXUtqaJHtOh+dKNMwLLrW NLyruyoTfukNxbTIuprGS9yT7ktJbtEdrRDSb/xCLAuBbbc2C6yoYu0qoqT3FIFsDWEgNZrkaqa jsmEd8iFCcyOSj8Cyevz3E+wnoOC+S+leRvyd70aKn5UaKn/+8A1VBusQ1T2CQTFnldoSgGkv40 pGnX7RtHKsYMb/BIyfqnaEeIcs03gB69r0tcfxgLFULcwLY7mGFhhYL83DHG0YBYD9OK02iMADE TspbpGAN9eZUp9NJ/lDOVZ3qfdRgQsBcfLg/xorQ5SWCtjfi1IsDsljEBwBJcFnLmTQBcImjSy5 UD7/Gbh2cBMHBXQ== X-Mailer: b4 0.14.3 Message-ID: <20260323-binder-crate-name-v3-1-c6e00f239fb1@google.com> Subject: [PATCH v3 1/2] rust: support overriding crate_name From: Alice Ryhl To: Miguel Ojeda , Tamir Duberstein , Nathan Chancellor , Nicolas Schier Cc: Boqun Feng , Gary Guo , "=?utf-8?q?Bj=C3=B6rn_Roy_Baron?=" , Benno Lossin , Andreas Hindborg , Trevor Gross , Danilo Krummrich , Jesung Yang , Greg Kroah-Hartman , Carlos Llamas , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, Alice Ryhl Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Currently you cannot filter out the crate-name argument RUSTFLAGS_REMOVE_stem.o because the Rust filter-out invocation does not include that particular argument. Since --crate-name is an argument that can't be passed multiple times, this means that it's currently not possible to override the crate name. Thus, remove the --crate-name argument for drivers. This allows them to override the crate name using the #![crate_name] annotation. This affects symbol names, but has no effect on the filenames of object files and other things generated by the build, as we always use --emit with a fixed output filename. The --crate-name argument is kept for the crates under rust/ for simplicity and to avoid changing many of them by adding #![crate_name]. The rust analyzer script is updated to use rustc to obtain the crate name of the driver crates, which picks up the right name whether it is configured via #![crate_name] or not. For readability, the logic to invoke 'rustc' is extracted to its own function. Note that the crate name in the python script is not actually that important - the only place where the name actually affects anything is in the 'deps' array which specifies an index and name for each dependency, and determines what that dependency is called in *this* crate. (The same crate may be called different things in each dependency.) Since driver crates are leaf crates, this doesn't apply and the rustc invocation only affects the 'display_name' parameter. Acked-by: Gary Guo Signed-off-by: Alice Ryhl --- scripts/Makefile.build | 1 - scripts/generate_rust_analyzer.py | 28 +++++++++++++++++++--------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 32e209bc7985..adc3e2d1ac78 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -332,7 +332,6 @@ rust_common_cmd =3D \ -Zcrate-attr=3D'feature($(rust_allowed_features))' \ -Zunstable-options --extern pin_init --extern kernel \ --crate-type rlib -L $(objtree)/rust/ \ - --crate-name $(basename $(notdir $@)) \ --sysroot=3D/dev/null \ --out-dir $(dir $@) --emit=3Ddep-info=3D$(depfile) =20 diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_anal= yzer.py index f9b545104f21..ac7f1677acc3 100755 --- a/scripts/generate_rust_analyzer.py +++ b/scripts/generate_rust_analyzer.py @@ -19,6 +19,12 @@ def args_crates_cfgs(cfgs): =20 return crates_cfgs =20 +def invoke_rustc(args): + return subprocess.check_output( + [os.environ["RUSTC"]] + args, + stdin=3Dsubprocess.DEVNULL, + ).decode('utf-8').strip() + def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, cor= e_edition): # Generate the configuration list. cfg =3D [] @@ -49,10 +55,9 @@ def generate_crates(srctree, objtree, sysroot_src, exter= nal_src, cfgs, core_edit } } if is_proc_macro: - proc_macro_dylib_name =3D subprocess.check_output( - [os.environ["RUSTC"], "--print", "file-names", "--crate-na= me", display_name, "--crate-type", "proc-macro", "-"], - stdin=3Dsubprocess.DEVNULL, - ).decode('utf-8').strip() + proc_macro_dylib_name =3D invoke_rustc( + ["--print", "file-names", "--crate-name", display_name, "-= -crate-type", "proc-macro", "-"] + ) crate["proc_macro_dylib_path"] =3D f"{objtree}/rust/{proc_macr= o_dylib_name}" crates_indexes[display_name] =3D len(crates) crates.append(crate) @@ -194,6 +199,9 @@ def generate_crates(srctree, objtree, sysroot_src, exte= rnal_src, cfgs, core_edit except FileNotFoundError: return False =20 + def get_crate_name(path): + return invoke_rustc(["--print", "crate-name", path]) + # Then, the rest outside of `rust/`. # # We explicitly mention the top-level folders we want to cover. @@ -203,16 +211,18 @@ def generate_crates(srctree, objtree, sysroot_src, ex= ternal_src, cfgs, core_edit for folder in extra_dirs: for path in folder.rglob("*.rs"): logging.info("Checking %s", path) - name =3D path.name.replace(".rs", "") + file_name =3D path.name.replace(".rs", "") =20 # Skip those that are not crate roots. - if not is_root_crate(path.parent / "Makefile", name) and \ - not is_root_crate(path.parent / "Kbuild", name): + if not is_root_crate(path.parent / "Makefile", file_name) and \ + not is_root_crate(path.parent / "Kbuild", file_name): continue =20 - logging.info("Adding %s", name) + crate_name =3D get_crate_name(path) + + logging.info("Adding %s", crate_name) append_crate( - name, + crate_name, path, ["core", "kernel", "pin_init"], cfg=3Dcfg, --=20 2.53.0.959.g497ff81fa9-goog