From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f73.google.com (mail-wr1-f73.google.com [209.85.221.73]) (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 B4972305047 for ; Tue, 10 Mar 2026 15:05:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.73 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773155153; cv=none; b=la/OmPFrafl5bedfkaEHd4LvL4G95xrIlsSPF/jkB0ifOBBr2QxhbIn6hfvJNivscBC4h+k+hO3TLgpRbwywUxw/PCq8zqdkZ35KZcfdMMOXSfxH3EAZ7tJazbh7ZP7eE7ly9CyyErg7oWtrO/SsNdyrkYq+HCj4UNpxc/xUfxY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773155153; c=relaxed/simple; bh=kV2wthUv/leJEQaKnb8eax2EBP7m+sPs2WFTinmX030=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=t+Qqs3exJ+qRRERYVFZ/dJzOP/30oe4uRMV4A86YaGmCt2Swi86EFDMUhB1C8xK2uDSQkElz5QHIcCm6PTlWoiKqK9KbFhQblXy7lExAlAL/9xs3NEBKn/eP3eKUB7GkMBzCgRTI244ZdMhl8vGLjSQ8b+tddxC+jm63TtAjm2A= 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=VdVlua1W; arc=none smtp.client-ip=209.85.221.73 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="VdVlua1W" Received: by mail-wr1-f73.google.com with SMTP id ffacd0b85a97d-439c794edd9so7040092f8f.3 for ; Tue, 10 Mar 2026 08:05:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1773155150; x=1773759950; 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=vRxINOztuTcq0M9mN6wXIb/1VY10+tkVrmyaxf8pT10=; b=VdVlua1WwUZ/emAkcovxKyO6hx27+ltbRYk5IA60+je8fbxKZsAm5JfRIdGsxGgEhi JYj7JWd/4tmHspafyUFRH6g/TukgxxqFiWkZjtgPLjMtxN4+TUcUZSYI05+o1Ncz0WMx C+IJS8Cu02MIV3/39501RZjNxF2j+WZ01ADd9dL5wbF/MM/C7XWka1fzLGjP0j2/MmvG N/UiOQZxyBjNe96+FjzMotw7sWbnve/+RkyAxQDu1Nl6taw1MbFkKP1UhN2M7v8Q25eU MScVjL4KE56wLBaSb3qhJXg1MET99r0xSATOlLK2NkvJ08X3xRRd7lzTI+BaGU+iFunT Tl5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773155150; x=1773759950; 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=vRxINOztuTcq0M9mN6wXIb/1VY10+tkVrmyaxf8pT10=; b=kM0TQk4BcwDtAh6rO66JBKnh+70NreYTYvDgqlHzdaDBJHwxX4OO41083/Tcdmr1UT /3fGF4bBmHLRXWuU0824HRBOE2h6L1a7KQoNIahwD1DadIeoeG4ZnLT+ewrnJWveJ4aB 6Y++9TCUuwLgWMT6SdURFIyilztoWoxBnacpWpW7q4aHD4FGGJ2Wu+dP2l7iV2GVZV9i FoWPGlIm2SwUDnT7EZPgVsDNFxbzRaqxYjKbwTDXxeplVNTbR3hET0mxjepyLbMRxzQv OfiujMmSnwy44qnivBJsomlxnUNuzennuFvsKnj74b8vH9jiOjzsIhcLLe1Og3MTEiHr Nqww== X-Forwarded-Encrypted: i=1; AJvYcCVl/aJbeZHzgsbw+UjX+cIQGPru1DooLiCe22JEZr1WC7N2k3wbJsb+qqU3q9iwZ38PxUlLdg7mHoKmJpl8Rg==@vger.kernel.org X-Gm-Message-State: AOJu0Yxilg7DLVJt7WEauEYygNp6vssueSUX9MRHR/Uola+4Fo/weC5Q mJCdH5m4ieczmnGiBqnN17+TZg5MbVY/m3aKhE01slJp2oF5JBoGmLh62mkmr8w3OwgyLA+9VO2 rkDdrzqBoavukE8Nbow== X-Received: from wrol10.prod.google.com ([2002:adf:f48a:0:b0:439:ba70:3167]) (user=aliceryhl job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6000:40dc:b0:439:c9d0:5fc2 with SMTP id ffacd0b85a97d-439da891b2cmr26419385f8f.39.1773155149903; Tue, 10 Mar 2026 08:05:49 -0700 (PDT) Date: Tue, 10 Mar 2026 15:05:48 +0000 In-Reply-To: <20260310-binder-crate-name-v2-1-0f7c97900d36@google.com> Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260310-binder-crate-name-v2-0-0f7c97900d36@google.com> <20260310-binder-crate-name-v2-1-0f7c97900d36@google.com> Message-ID: Subject: Re: [PATCH v2 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?B?QmrDtnJu?= 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 Content-Type: text/plain; charset="utf-8" On Tue, Mar 10, 2026 at 02:53:40PM +0000, Alice Ryhl wrote: > 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. > > 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 when it is > configured via #![crate_name] or not. > > 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. > > Signed-off-by: Alice Ryhl > --- > scripts/Makefile.build | 1 - > scripts/generate_rust_analyzer.py | 8 +++++++- > 2 files changed, 7 insertions(+), 2 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 = \ > -Zcrate-attr='feature($(rust_allowed_features))' \ > -Zunstable-options --extern pin_init --extern kernel \ > --crate-type rlib -L $(objtree)/rust/ \ > - --crate-name $(basename $(notdir $@)) \ > --sysroot=/dev/null \ > --out-dir $(dir $@) --emit=dep-info=$(depfile) > > diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_analyzer.py > index f9b545104f21..d25bc3d7e719 100755 > --- a/scripts/generate_rust_analyzer.py > +++ b/scripts/generate_rust_analyzer.py > @@ -194,6 +194,12 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edit > except FileNotFoundError: > return False > > + def get_crate_name(path): > + return subprocess.check_output( > + [os.environ["RUSTC"], "--print", "crate-name", path], > + stdin=subprocess.DEVNULL, > + ).decode('utf-8').strip() > + > # Then, the rest outside of `rust/`. > # > # We explicitly mention the top-level folders we want to cover. > @@ -212,7 +218,7 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edit > > logging.info("Adding %s", name) Actually I guess we might want get_crate_name(path) here (or just path). But the other uses of 'name' should stay as-is. > append_crate( > - name, > + get_crate_name(path), > path, > ["core", "kernel", "pin_init"], > cfg=cfg, > > -- > 2.53.0.473.g4a7958ca14-goog >