* [PATCH v2 0/2] Change Rust Binder crate name to rust_binder
@ 2026-03-10 14:53 Alice Ryhl
2026-03-10 14:53 ` [PATCH v2 1/2] rust: support overriding crate_name Alice Ryhl
2026-03-10 14:53 ` [PATCH v2 2/2] rust_binder: override crate name to rust_binder Alice Ryhl
0 siblings, 2 replies; 13+ messages in thread
From: Alice Ryhl @ 2026-03-10 14:53 UTC (permalink / raw)
To: Miguel Ojeda, Tamir Duberstein, Nathan Chancellor, Nicolas Schier
Cc: Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Trevor Gross, Danilo Krummrich, Jesung Yang,
Greg Kroah-Hartman, Carlos Llamas, linux-kbuild, linux-kernel,
rust-for-linux, Alice Ryhl
Currently the crate name of the Rust Binder driver is rust_binder_main,
but I'd like it to be called rust_binder instead, matching the .ko file.
This affects e.g. symbol names in stack traces.
Thus, allow use of the #![crate_name] annotation, and set it for Rust
Binder.
I tried just using RUSTFLAGS_stem.o and RUSTFLAGS_REMOVE_stem.o, but
RUSTFLAGS_REMOVE_ is incapable of removing the --crate-name argument.
(Even after changing --crate-name to be passed with = instead of space
as the separator to the name.)
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
---
Changes in v2:
- Do not pass --crate-name and specify crate name using annotation
inside .rs file.
- Link to v1: https://lore.kernel.org/r/20260224-binder-crate-name-v1-0-7dfc1289abbd@google.com
---
Alice Ryhl (2):
rust: support overriding crate_name
rust_binder: override crate name to rust_binder
drivers/android/binder/rust_binder_main.rs | 2 ++
scripts/Makefile.build | 1 -
scripts/generate_rust_analyzer.py | 8 +++++++-
3 files changed, 9 insertions(+), 2 deletions(-)
---
base-commit: 1f318b96cc84d7c2ab792fcc0bfd42a7ca890681
change-id: 20260224-binder-crate-name-15f14e134fca
Best regards,
--
Alice Ryhl <aliceryhl@google.com>
^ permalink raw reply [flat|nested] 13+ messages in thread* [PATCH v2 1/2] rust: support overriding crate_name 2026-03-10 14:53 [PATCH v2 0/2] Change Rust Binder crate name to rust_binder Alice Ryhl @ 2026-03-10 14:53 ` Alice Ryhl 2026-03-10 15:05 ` Alice Ryhl 2026-03-10 22:36 ` Gary Guo 2026-03-10 14:53 ` [PATCH v2 2/2] rust_binder: override crate name to rust_binder Alice Ryhl 1 sibling, 2 replies; 13+ messages in thread From: Alice Ryhl @ 2026-03-10 14:53 UTC (permalink / raw) To: Miguel Ojeda, Tamir Duberstein, Nathan Chancellor, Nicolas Schier Cc: Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg, Trevor Gross, Danilo Krummrich, Jesung Yang, Greg Kroah-Hartman, Carlos Llamas, linux-kbuild, linux-kernel, rust-for-linux, Alice Ryhl 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 <aliceryhl@google.com> --- 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) append_crate( - name, + get_crate_name(path), path, ["core", "kernel", "pin_init"], cfg=cfg, -- 2.53.0.473.g4a7958ca14-goog ^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH v2 1/2] rust: support overriding crate_name 2026-03-10 14:53 ` [PATCH v2 1/2] rust: support overriding crate_name Alice Ryhl @ 2026-03-10 15:05 ` Alice Ryhl 2026-03-10 15:45 ` Tamir Duberstein 2026-03-10 22:36 ` Gary Guo 1 sibling, 1 reply; 13+ messages in thread From: Alice Ryhl @ 2026-03-10 15:05 UTC (permalink / raw) To: Miguel Ojeda, Tamir Duberstein, Nathan Chancellor, Nicolas Schier Cc: Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg, Trevor Gross, Danilo Krummrich, Jesung Yang, Greg Kroah-Hartman, Carlos Llamas, linux-kbuild, linux-kernel, rust-for-linux 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 <aliceryhl@google.com> > --- > 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 > ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 1/2] rust: support overriding crate_name 2026-03-10 15:05 ` Alice Ryhl @ 2026-03-10 15:45 ` Tamir Duberstein 2026-03-10 19:13 ` Miguel Ojeda 0 siblings, 1 reply; 13+ messages in thread From: Tamir Duberstein @ 2026-03-10 15:45 UTC (permalink / raw) To: Alice Ryhl Cc: Miguel Ojeda, Tamir Duberstein, Nathan Chancellor, Nicolas Schier, Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg, Trevor Gross, Danilo Krummrich, Jesung Yang, Greg Kroah-Hartman, Carlos Llamas, linux-kbuild, linux-kernel, rust-for-linux On 2026-03-10 15:05:48+00:00, Alice Ryhl wrote: > 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 <aliceryhl@google.com> > > --- > > 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 Did you want me to take this part through rust-analyzer-next? There's a significant rewrite there that adds type annotations to this file, so it would be better if this patch could apply on top (with annotations). > > @@ -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() It would be good to extract shelling out to rustc into a helper, now that we have two instances of this pattern. > > + > > # 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. It would probably be good to rename `name` to reduce some of this confusion. ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 1/2] rust: support overriding crate_name 2026-03-10 15:45 ` Tamir Duberstein @ 2026-03-10 19:13 ` Miguel Ojeda 2026-03-10 19:38 ` Tamir Duberstein 0 siblings, 1 reply; 13+ messages in thread From: Miguel Ojeda @ 2026-03-10 19:13 UTC (permalink / raw) To: Tamir Duberstein Cc: Alice Ryhl, Miguel Ojeda, Nathan Chancellor, Nicolas Schier, Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg, Trevor Gross, Danilo Krummrich, Jesung Yang, Greg Kroah-Hartman, Carlos Llamas, linux-kbuild, linux-kernel, rust-for-linux On Tue, Mar 10, 2026 at 4:45 PM Tamir Duberstein <tamird@kernel.org> wrote: > > Did you want me to take this part through rust-analyzer-next? There's a > significant rewrite there that adds type annotations to this file, so it > would be better if this patch could apply on top (with annotations). We should ideally avoid breaking it between commits, so we could apply it after I merge your future PR, with your Acked-by. Another way is next cycle, through rust-analyzer-next. Cheers, Miguel ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 1/2] rust: support overriding crate_name 2026-03-10 19:13 ` Miguel Ojeda @ 2026-03-10 19:38 ` Tamir Duberstein 2026-03-10 19:58 ` Alice Ryhl 2026-03-10 19:58 ` Miguel Ojeda 0 siblings, 2 replies; 13+ messages in thread From: Tamir Duberstein @ 2026-03-10 19:38 UTC (permalink / raw) To: Miguel Ojeda Cc: Alice Ryhl, Miguel Ojeda, Nathan Chancellor, Nicolas Schier, Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg, Trevor Gross, Danilo Krummrich, Jesung Yang, Greg Kroah-Hartman, Carlos Llamas, linux-kbuild, linux-kernel, rust-for-linux On Tue, Mar 10, 2026 at 3:13 PM Miguel Ojeda <miguel.ojeda.sandonis@gmail.com> wrote: > > On Tue, Mar 10, 2026 at 4:45 PM Tamir Duberstein <tamird@kernel.org> wrote: > > > > Did you want me to take this part through rust-analyzer-next? There's a > > significant rewrite there that adds type annotations to this file, so it > > would be better if this patch could apply on top (with annotations). > > We should ideally avoid breaking it between commits, so we could apply > it after I merge your future PR, with your Acked-by. Another way is > next cycle, through rust-analyzer-next. The change to `generate_rust_analyzer.py` is safe to land even without the other changes in this series, so it should be possible to take that through rust-analyzer-next this cycle and then take the other changes in this series after my PR. Do I understand correctly? ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 1/2] rust: support overriding crate_name 2026-03-10 19:38 ` Tamir Duberstein @ 2026-03-10 19:58 ` Alice Ryhl 2026-03-10 19:58 ` Miguel Ojeda 1 sibling, 0 replies; 13+ messages in thread From: Alice Ryhl @ 2026-03-10 19:58 UTC (permalink / raw) To: Tamir Duberstein Cc: Miguel Ojeda, Miguel Ojeda, Nathan Chancellor, Nicolas Schier, Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg, Trevor Gross, Danilo Krummrich, Jesung Yang, Greg Kroah-Hartman, Carlos Llamas, linux-kbuild, linux-kernel, rust-for-linux On Tue, Mar 10, 2026 at 03:38:58PM -0400, Tamir Duberstein wrote: > On Tue, Mar 10, 2026 at 3:13 PM Miguel Ojeda > <miguel.ojeda.sandonis@gmail.com> wrote: > > > > On Tue, Mar 10, 2026 at 4:45 PM Tamir Duberstein <tamird@kernel.org> wrote: > > > > > > Did you want me to take this part through rust-analyzer-next? There's a > > > significant rewrite there that adds type annotations to this file, so it > > > would be better if this patch could apply on top (with annotations). I will rebase on rust-analyzer-next and resend once discussion has died down. > > We should ideally avoid breaking it between commits, so we could apply > > it after I merge your future PR, with your Acked-by. Another way is > > next cycle, through rust-analyzer-next. > > The change to `generate_rust_analyzer.py` is safe to land even without > the other changes in this series, so it should be possible to take > that through rust-analyzer-next this cycle and then take the other > changes in this series after my PR. Do I understand correctly? I have no strong opinion on this. I can split it if you want me to, but I'm also fine with Miguel landing the entire thing in rust-next, or with Tamir landing the entire thing in rust-analyzer-next. Just let me know what you want me to do. Alice ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 1/2] rust: support overriding crate_name 2026-03-10 19:38 ` Tamir Duberstein 2026-03-10 19:58 ` Alice Ryhl @ 2026-03-10 19:58 ` Miguel Ojeda 2026-03-10 20:01 ` Miguel Ojeda 1 sibling, 1 reply; 13+ messages in thread From: Miguel Ojeda @ 2026-03-10 19:58 UTC (permalink / raw) To: Tamir Duberstein Cc: Alice Ryhl, Miguel Ojeda, Nathan Chancellor, Nicolas Schier, Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg, Trevor Gross, Danilo Krummrich, Jesung Yang, Greg Kroah-Hartman, Carlos Llamas, linux-kbuild, linux-kernel, rust-for-linux On Tue, Mar 10, 2026 at 8:39 PM Tamir Duberstein <tamird@kernel.org> wrote: > > The change to `generate_rust_analyzer.py` is safe to land even without > the other changes in this series, so it should be possible to take > that through rust-analyzer-next this cycle and then take the other > changes in this series after my PR. Do I understand correctly? Yeah, I think we could do that, but that means justifying the rust-analyzer change on its own, which currently wouldn't be needed. Sometimes we do things "for the future" to simplify landing them, but do we need that here? Either way, what I would suggest is that the changes take into account your changes, i.e. to base the patch on top of what you have in the branch, so that we can review it and so that you are happy with it one way or the other. Cheers, Miguel ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 1/2] rust: support overriding crate_name 2026-03-10 19:58 ` Miguel Ojeda @ 2026-03-10 20:01 ` Miguel Ojeda 2026-03-10 20:27 ` Tamir Duberstein 0 siblings, 1 reply; 13+ messages in thread From: Miguel Ojeda @ 2026-03-10 20:01 UTC (permalink / raw) To: Tamir Duberstein Cc: Alice Ryhl, Miguel Ojeda, Nathan Chancellor, Nicolas Schier, Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg, Trevor Gross, Danilo Krummrich, Jesung Yang, Greg Kroah-Hartman, Carlos Llamas, linux-kbuild, linux-kernel, rust-for-linux On Tue, Mar 10, 2026 at 8:58 PM Miguel Ojeda <miguel.ojeda.sandonis@gmail.com> wrote: > > and so that you are happy with it one > way or the other. By this I mean that either way I would wait for you to be OK with the change (e.g. with an Acked-by if we put it after merging your branch). Cheers, Miguel ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 1/2] rust: support overriding crate_name 2026-03-10 20:01 ` Miguel Ojeda @ 2026-03-10 20:27 ` Tamir Duberstein 0 siblings, 0 replies; 13+ messages in thread From: Tamir Duberstein @ 2026-03-10 20:27 UTC (permalink / raw) To: Miguel Ojeda Cc: Alice Ryhl, Miguel Ojeda, Nathan Chancellor, Nicolas Schier, Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg, Trevor Gross, Danilo Krummrich, Jesung Yang, Greg Kroah-Hartman, Carlos Llamas, linux-kbuild, linux-kernel, rust-for-linux On Tue, Mar 10, 2026 at 4:01 PM Miguel Ojeda <miguel.ojeda.sandonis@gmail.com> wrote: > > On Tue, Mar 10, 2026 at 8:58 PM Miguel Ojeda > <miguel.ojeda.sandonis@gmail.com> wrote: > > > > and so that you are happy with it one > > way or the other. > > By this I mean that either way I would wait for you to be OK with the > change (e.g. with an Acked-by if we put it after merging your branch). Makes sense to me (that this goes through rust-next after my PR). Thanks! ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 1/2] rust: support overriding crate_name 2026-03-10 14:53 ` [PATCH v2 1/2] rust: support overriding crate_name Alice Ryhl 2026-03-10 15:05 ` Alice Ryhl @ 2026-03-10 22:36 ` Gary Guo 1 sibling, 0 replies; 13+ messages in thread From: Gary Guo @ 2026-03-10 22:36 UTC (permalink / raw) To: Alice Ryhl, Miguel Ojeda, Tamir Duberstein, Nathan Chancellor, Nicolas Schier Cc: Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg, Trevor Gross, Danilo Krummrich, Jesung Yang, Greg Kroah-Hartman, Carlos Llamas, linux-kbuild, linux-kernel, rust-for-linux On Tue Mar 10, 2026 at 2:53 PM GMT, 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. Could you add a line about the fact that crate name have no impact on output locations as we always use fixed emit paths, as we discussed in v1? With that change: Acked-by: Gary Guo <gary@garyguo.net> > > 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 <aliceryhl@google.com> > --- > 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) > append_crate( > - name, > + get_crate_name(path), > path, > ["core", "kernel", "pin_init"], > cfg=cfg, ^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v2 2/2] rust_binder: override crate name to rust_binder 2026-03-10 14:53 [PATCH v2 0/2] Change Rust Binder crate name to rust_binder Alice Ryhl 2026-03-10 14:53 ` [PATCH v2 1/2] rust: support overriding crate_name Alice Ryhl @ 2026-03-10 14:53 ` Alice Ryhl 2026-03-10 19:10 ` Miguel Ojeda 1 sibling, 1 reply; 13+ messages in thread From: Alice Ryhl @ 2026-03-10 14:53 UTC (permalink / raw) To: Miguel Ojeda, Tamir Duberstein, Nathan Chancellor, Nicolas Schier Cc: Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg, Trevor Gross, Danilo Krummrich, Jesung Yang, Greg Kroah-Hartman, Carlos Llamas, linux-kbuild, linux-kernel, rust-for-linux, Alice Ryhl The Rust Binder object file is called rust_binder_main.o because the name rust_binder.o is used for the result of linking together rust_binder_main.o with rust_binderfs.o and a few others. However, the crate name is supposed to be rust_binder without a _main suffix. Thus, override the crate name accordingly. Signed-off-by: Alice Ryhl <aliceryhl@google.com> --- drivers/android/binder/rust_binder_main.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/android/binder/rust_binder_main.rs b/drivers/android/binder/rust_binder_main.rs index aa5f2a75adb4..14162af0f5a5 100644 --- a/drivers/android/binder/rust_binder_main.rs +++ b/drivers/android/binder/rust_binder_main.rs @@ -2,7 +2,9 @@ // Copyright (C) 2025 Google LLC. +#![crate_name = "rust_binder"] //! Binder -- the Android IPC mechanism. + #![recursion_limit = "256"] #![allow( clippy::as_underscore, -- 2.53.0.473.g4a7958ca14-goog ^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH v2 2/2] rust_binder: override crate name to rust_binder 2026-03-10 14:53 ` [PATCH v2 2/2] rust_binder: override crate name to rust_binder Alice Ryhl @ 2026-03-10 19:10 ` Miguel Ojeda 0 siblings, 0 replies; 13+ messages in thread From: Miguel Ojeda @ 2026-03-10 19:10 UTC (permalink / raw) To: Alice Ryhl Cc: Miguel Ojeda, Tamir Duberstein, Nathan Chancellor, Nicolas Schier, Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg, Trevor Gross, Danilo Krummrich, Jesung Yang, Greg Kroah-Hartman, Carlos Llamas, linux-kbuild, linux-kernel, rust-for-linux On Tue, Mar 10, 2026 at 3:53 PM Alice Ryhl <aliceryhl@google.com> wrote: > > // Copyright (C) 2025 Google LLC. > > +#![crate_name = "rust_binder"] > //! Binder -- the Android IPC mechanism. > + > #![recursion_limit = "256"] > #![allow( > clippy::as_underscore, So the crate name is a special crate attribute (together with `crate_type, it is forbidden inside `cfg_attr`), so I think it makes in a sense to put it between the SPDX/copyright block and the crate docs. I also think you didn't add a newline to put it closer to the title of the docs, as if it were a title of its own. On the other hand, it is a crate attribute nevertheless, so putting it together with the rest looks a bit more consistent, and as a title the English one is probably the best one to see first anyway: //! Binder -- the Android IPC mechanism. #![crate_name = "rust_binder"] #![recursion_limit = "256"] Hopefully the crate names are still close to the file names (and I would really not want people to abuse this...). Cheers, Miguel ^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2026-03-10 22:36 UTC | newest] Thread overview: 13+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-03-10 14:53 [PATCH v2 0/2] Change Rust Binder crate name to rust_binder Alice Ryhl 2026-03-10 14:53 ` [PATCH v2 1/2] rust: support overriding crate_name Alice Ryhl 2026-03-10 15:05 ` Alice Ryhl 2026-03-10 15:45 ` Tamir Duberstein 2026-03-10 19:13 ` Miguel Ojeda 2026-03-10 19:38 ` Tamir Duberstein 2026-03-10 19:58 ` Alice Ryhl 2026-03-10 19:58 ` Miguel Ojeda 2026-03-10 20:01 ` Miguel Ojeda 2026-03-10 20:27 ` Tamir Duberstein 2026-03-10 22:36 ` Gary Guo 2026-03-10 14:53 ` [PATCH v2 2/2] rust_binder: override crate name to rust_binder Alice Ryhl 2026-03-10 19:10 ` Miguel Ojeda
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox