[PATCH 0/2] Change Rust Binder crate name to rust_binder

Alice Ryhl posted 2 patches 1 month, 3 weeks ago
There is a newer version of this series
drivers/android/binder/Makefile   |  1 +
scripts/Makefile.build            |  4 +++-
scripts/generate_rust_analyzer.py | 21 ++++++++++++++++++---
3 files changed, 22 insertions(+), 4 deletions(-)
[PATCH 0/2] Change Rust Binder crate name to rust_binder
Posted by Alice Ryhl 1 month, 3 weeks ago
Currently the crate name of the Rust Binder driver is rust_binder_main,
but I'd like it to be called rust_binder instead. This affects e.g.
symbol names in stack traces.

Thus, introduce a RUST_CRATENAME_stem.o parameter, 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>
---
Alice Ryhl (2):
      rust: support overriding crate_name
      rust_binder: override crate name to rust_binder

 drivers/android/binder/Makefile   |  1 +
 scripts/Makefile.build            |  4 +++-
 scripts/generate_rust_analyzer.py | 21 ++++++++++++++++++---
 3 files changed, 22 insertions(+), 4 deletions(-)
---
base-commit: 6de23f81a5e08be8fbf5e8d7e9febc72a5b5f27f
change-id: 20260224-binder-crate-name-15f14e134fca

Best regards,
-- 
Alice Ryhl <aliceryhl@google.com>
Re: [PATCH 0/2] Change Rust Binder crate name to rust_binder
Posted by Miguel Ojeda 1 month, 3 weeks ago
On Tue, Feb 24, 2026 at 10:38 AM Alice Ryhl <aliceryhl@google.com> wrote:
>
> Currently the crate name of the Rust Binder driver is rust_binder_main,
> but I'd like it to be called rust_binder instead. This affects e.g.
> symbol names in stack traces.

We discussed allowing to customize crate names years ago, at least for
dashes vs. underscores, for matching C names more closely and perhaps
other needs.

Back then, we decided to keep things simple to avoid confusion (i.e. a
single identifier used everywhere the same way is simpler, at least
for humans) and to avoid having to deal with those dual names
everywhere (e.g. adding workarounds for rust-analyzer here).

I talked with Alice about what she needed here -- could we rename that
source file to just something like `binder`? That would avoid the need
to have a custom name, so everything would still match (symbols,
source file, object file...), and it would give you even shorter
names.

Cheers,
Miguel
Re: [PATCH 0/2] Change Rust Binder crate name to rust_binder
Posted by Alice Ryhl 1 month, 3 weeks ago
On Tue, Feb 24, 2026 at 02:24:59PM +0100, Miguel Ojeda wrote:
> On Tue, Feb 24, 2026 at 10:38 AM Alice Ryhl <aliceryhl@google.com> wrote:
> >
> > Currently the crate name of the Rust Binder driver is rust_binder_main,
> > but I'd like it to be called rust_binder instead. This affects e.g.
> > symbol names in stack traces.
> 
> We discussed allowing to customize crate names years ago, at least for
> dashes vs. underscores, for matching C names more closely and perhaps
> other needs.
> 
> Back then, we decided to keep things simple to avoid confusion (i.e. a
> single identifier used everywhere the same way is simpler, at least
> for humans) and to avoid having to deal with those dual names
> everywhere (e.g. adding workarounds for rust-analyzer here).
> 
> I talked with Alice about what she needed here -- could we rename that
> source file to just something like `binder`? That would avoid the need
> to have a custom name, so everything would still match (symbols,
> source file, object file...), and it would give you even shorter
> names.

Sure just renaming rust_binder_main.rs to binder.rs would work too.

Alice
Re: [PATCH 0/2] Change Rust Binder crate name to rust_binder
Posted by Alice Ryhl 1 month, 1 week ago
On Tue, Feb 24, 2026 at 03:17:16PM +0000, Alice Ryhl wrote:
> On Tue, Feb 24, 2026 at 02:24:59PM +0100, Miguel Ojeda wrote:
> > On Tue, Feb 24, 2026 at 10:38 AM Alice Ryhl <aliceryhl@google.com> wrote:
> > >
> > > Currently the crate name of the Rust Binder driver is rust_binder_main,
> > > but I'd like it to be called rust_binder instead. This affects e.g.
> > > symbol names in stack traces.
> > 
> > We discussed allowing to customize crate names years ago, at least for
> > dashes vs. underscores, for matching C names more closely and perhaps
> > other needs.
> > 
> > Back then, we decided to keep things simple to avoid confusion (i.e. a
> > single identifier used everywhere the same way is simpler, at least
> > for humans) and to avoid having to deal with those dual names
> > everywhere (e.g. adding workarounds for rust-analyzer here).
> > 
> > I talked with Alice about what she needed here -- could we rename that
> > source file to just something like `binder`? That would avoid the need
> > to have a custom name, so everything would still match (symbols,
> > source file, object file...), and it would give you even shorter
> > names.
> 
> Sure just renaming rust_binder_main.rs to binder.rs would work too.

I realized that there's a much simpler way to allow crates to rename
themselves: do not pass the --crate-name argument at all.

Because if you do not pass this argument, then rustc will use the
name of the .rs file as the crate name by default, *but* if the crate
contains #![crate_name = "..."], then that will be used instead.

Do you still want to enforce that the crate name always matches the
file name? It seems unfortunate that it's currently impossible to create
a Rust module where the .ko file and crate name is the same, unless no
extra object files are linked into the module.

Alice
Re: [PATCH 0/2] Change Rust Binder crate name to rust_binder
Posted by Gary Guo 1 month, 1 week ago
On Thu Mar 5, 2026 at 10:49 AM GMT, Alice Ryhl wrote:
> On Tue, Feb 24, 2026 at 03:17:16PM +0000, Alice Ryhl wrote:
>> On Tue, Feb 24, 2026 at 02:24:59PM +0100, Miguel Ojeda wrote:
>> > On Tue, Feb 24, 2026 at 10:38 AM Alice Ryhl <aliceryhl@google.com> wrote:
>> > >
>> > > Currently the crate name of the Rust Binder driver is rust_binder_main,
>> > > but I'd like it to be called rust_binder instead. This affects e.g.
>> > > symbol names in stack traces.
>> > 
>> > We discussed allowing to customize crate names years ago, at least for
>> > dashes vs. underscores, for matching C names more closely and perhaps
>> > other needs.
>> > 
>> > Back then, we decided to keep things simple to avoid confusion (i.e. a
>> > single identifier used everywhere the same way is simpler, at least
>> > for humans) and to avoid having to deal with those dual names
>> > everywhere (e.g. adding workarounds for rust-analyzer here).
>> > 
>> > I talked with Alice about what she needed here -- could we rename that
>> > source file to just something like `binder`? That would avoid the need
>> > to have a custom name, so everything would still match (symbols,
>> > source file, object file...), and it would give you even shorter
>> > names.
>> 
>> Sure just renaming rust_binder_main.rs to binder.rs would work too.
>
> I realized that there's a much simpler way to allow crates to rename
> themselves: do not pass the --crate-name argument at all.
>
> Because if you do not pass this argument, then rustc will use the
> name of the .rs file as the crate name by default, *but* if the crate
> contains #![crate_name = "..."], then that will be used instead.
>
> Do you still want to enforce that the crate name always matches the
> file name? It seems unfortunate that it's currently impossible to create
> a Rust module where the .ko file and crate name is the same, unless no
> extra object files are linked into the module.

I think previously a fixed crate name is load-bearing because we need rustc to
emit outputs to a fixed location.

This shouldn't be needed after commit 295d8398c67e ("kbuild: specify output
names separately for each emission type from rustc"), so if nothing breaks with
`--crate-name` removed, then I think it makes sense to drop it to allow custom
rustflags to override them.

Best,
Gary
Re: [PATCH 0/2] Change Rust Binder crate name to rust_binder
Posted by Alice Ryhl 1 month, 1 week ago
On Thu, Mar 05, 2026 at 12:17:52PM +0000, Gary Guo wrote:
> On Thu Mar 5, 2026 at 10:49 AM GMT, Alice Ryhl wrote:
> > On Tue, Feb 24, 2026 at 03:17:16PM +0000, Alice Ryhl wrote:
> >> On Tue, Feb 24, 2026 at 02:24:59PM +0100, Miguel Ojeda wrote:
> >> > On Tue, Feb 24, 2026 at 10:38 AM Alice Ryhl <aliceryhl@google.com> wrote:
> >> > >
> >> > > Currently the crate name of the Rust Binder driver is rust_binder_main,
> >> > > but I'd like it to be called rust_binder instead. This affects e.g.
> >> > > symbol names in stack traces.
> >> > 
> >> > We discussed allowing to customize crate names years ago, at least for
> >> > dashes vs. underscores, for matching C names more closely and perhaps
> >> > other needs.
> >> > 
> >> > Back then, we decided to keep things simple to avoid confusion (i.e. a
> >> > single identifier used everywhere the same way is simpler, at least
> >> > for humans) and to avoid having to deal with those dual names
> >> > everywhere (e.g. adding workarounds for rust-analyzer here).
> >> > 
> >> > I talked with Alice about what she needed here -- could we rename that
> >> > source file to just something like `binder`? That would avoid the need
> >> > to have a custom name, so everything would still match (symbols,
> >> > source file, object file...), and it would give you even shorter
> >> > names.
> >> 
> >> Sure just renaming rust_binder_main.rs to binder.rs would work too.
> >
> > I realized that there's a much simpler way to allow crates to rename
> > themselves: do not pass the --crate-name argument at all.
> >
> > Because if you do not pass this argument, then rustc will use the
> > name of the .rs file as the crate name by default, *but* if the crate
> > contains #![crate_name = "..."], then that will be used instead.
> >
> > Do you still want to enforce that the crate name always matches the
> > file name? It seems unfortunate that it's currently impossible to create
> > a Rust module where the .ko file and crate name is the same, unless no
> > extra object files are linked into the module.
> 
> I think previously a fixed crate name is load-bearing because we need rustc to
> emit outputs to a fixed location.
> 
> This shouldn't be needed after commit 295d8398c67e ("kbuild: specify output
> names separately for each emission type from rustc"), so if nothing breaks with
> `--crate-name` removed, then I think it makes sense to drop it to allow custom
> rustflags to override them.

Are you sure? I know this commit shows up in blame, but it just adds a
backslash to the --crate-name argument.

I do not believe that omitting --crate-name changes anything in cases
where the crate name already matches the file name.

Alice
Re: [PATCH 0/2] Change Rust Binder crate name to rust_binder
Posted by Gary Guo 1 month, 1 week ago
On Thu Mar 5, 2026 at 12:27 PM GMT, Alice Ryhl wrote:
> On Thu, Mar 05, 2026 at 12:17:52PM +0000, Gary Guo wrote:
>> On Thu Mar 5, 2026 at 10:49 AM GMT, Alice Ryhl wrote:
>> > On Tue, Feb 24, 2026 at 03:17:16PM +0000, Alice Ryhl wrote:
>> >> On Tue, Feb 24, 2026 at 02:24:59PM +0100, Miguel Ojeda wrote:
>> >> > On Tue, Feb 24, 2026 at 10:38 AM Alice Ryhl <aliceryhl@google.com> wrote:
>> >> > >
>> >> > > Currently the crate name of the Rust Binder driver is rust_binder_main,
>> >> > > but I'd like it to be called rust_binder instead. This affects e.g.
>> >> > > symbol names in stack traces.
>> >> > 
>> >> > We discussed allowing to customize crate names years ago, at least for
>> >> > dashes vs. underscores, for matching C names more closely and perhaps
>> >> > other needs.
>> >> > 
>> >> > Back then, we decided to keep things simple to avoid confusion (i.e. a
>> >> > single identifier used everywhere the same way is simpler, at least
>> >> > for humans) and to avoid having to deal with those dual names
>> >> > everywhere (e.g. adding workarounds for rust-analyzer here).
>> >> > 
>> >> > I talked with Alice about what she needed here -- could we rename that
>> >> > source file to just something like `binder`? That would avoid the need
>> >> > to have a custom name, so everything would still match (symbols,
>> >> > source file, object file...), and it would give you even shorter
>> >> > names.
>> >> 
>> >> Sure just renaming rust_binder_main.rs to binder.rs would work too.
>> >
>> > I realized that there's a much simpler way to allow crates to rename
>> > themselves: do not pass the --crate-name argument at all.
>> >
>> > Because if you do not pass this argument, then rustc will use the
>> > name of the .rs file as the crate name by default, *but* if the crate
>> > contains #![crate_name = "..."], then that will be used instead.
>> >
>> > Do you still want to enforce that the crate name always matches the
>> > file name? It seems unfortunate that it's currently impossible to create
>> > a Rust module where the .ko file and crate name is the same, unless no
>> > extra object files are linked into the module.
>> 
>> I think previously a fixed crate name is load-bearing because we need rustc to
>> emit outputs to a fixed location.
>> 
>> This shouldn't be needed after commit 295d8398c67e ("kbuild: specify output
>> names separately for each emission type from rustc"), so if nothing breaks with
>> `--crate-name` removed, then I think it makes sense to drop it to allow custom
>> rustflags to override them.
>
> Are you sure? I know this commit shows up in blame, but it just adds a
> backslash to the --crate-name argument.
>
> I do not believe that omitting --crate-name changes anything in cases
> where the crate name already matches the file name.

Before this change we rely on the crate name to match the file name, otherwise
the .d file and .o file will be placed at wrong location and Kbuild cannot find
the output files.

With this change we specify everything explicitly, so even if you pass
`--crate-name=foo`, the object file is still `rust_binder.o` so the build can
continue.

My point is that you *cannot* reasonably override crate names before this
change.

Best,
Gary
Re: [PATCH 0/2] Change Rust Binder crate name to rust_binder
Posted by Alice Ryhl 1 month, 1 week ago
On Thu, Mar 05, 2026 at 12:34:16PM +0000, Gary Guo wrote:
> On Thu Mar 5, 2026 at 12:27 PM GMT, Alice Ryhl wrote:
> > On Thu, Mar 05, 2026 at 12:17:52PM +0000, Gary Guo wrote:
> >> On Thu Mar 5, 2026 at 10:49 AM GMT, Alice Ryhl wrote:
> >> > On Tue, Feb 24, 2026 at 03:17:16PM +0000, Alice Ryhl wrote:
> >> >> On Tue, Feb 24, 2026 at 02:24:59PM +0100, Miguel Ojeda wrote:
> >> >> > On Tue, Feb 24, 2026 at 10:38 AM Alice Ryhl <aliceryhl@google.com> wrote:
> >> >> > >
> >> >> > > Currently the crate name of the Rust Binder driver is rust_binder_main,
> >> >> > > but I'd like it to be called rust_binder instead. This affects e.g.
> >> >> > > symbol names in stack traces.
> >> >> > 
> >> >> > We discussed allowing to customize crate names years ago, at least for
> >> >> > dashes vs. underscores, for matching C names more closely and perhaps
> >> >> > other needs.
> >> >> > 
> >> >> > Back then, we decided to keep things simple to avoid confusion (i.e. a
> >> >> > single identifier used everywhere the same way is simpler, at least
> >> >> > for humans) and to avoid having to deal with those dual names
> >> >> > everywhere (e.g. adding workarounds for rust-analyzer here).
> >> >> > 
> >> >> > I talked with Alice about what she needed here -- could we rename that
> >> >> > source file to just something like `binder`? That would avoid the need
> >> >> > to have a custom name, so everything would still match (symbols,
> >> >> > source file, object file...), and it would give you even shorter
> >> >> > names.
> >> >> 
> >> >> Sure just renaming rust_binder_main.rs to binder.rs would work too.
> >> >
> >> > I realized that there's a much simpler way to allow crates to rename
> >> > themselves: do not pass the --crate-name argument at all.
> >> >
> >> > Because if you do not pass this argument, then rustc will use the
> >> > name of the .rs file as the crate name by default, *but* if the crate
> >> > contains #![crate_name = "..."], then that will be used instead.
> >> >
> >> > Do you still want to enforce that the crate name always matches the
> >> > file name? It seems unfortunate that it's currently impossible to create
> >> > a Rust module where the .ko file and crate name is the same, unless no
> >> > extra object files are linked into the module.
> >> 
> >> I think previously a fixed crate name is load-bearing because we need rustc to
> >> emit outputs to a fixed location.
> >> 
> >> This shouldn't be needed after commit 295d8398c67e ("kbuild: specify output
> >> names separately for each emission type from rustc"), so if nothing breaks with
> >> `--crate-name` removed, then I think it makes sense to drop it to allow custom
> >> rustflags to override them.
> >
> > Are you sure? I know this commit shows up in blame, but it just adds a
> > backslash to the --crate-name argument.
> >
> > I do not believe that omitting --crate-name changes anything in cases
> > where the crate name already matches the file name.
> 
> Before this change we rely on the crate name to match the file name, otherwise
> the .d file and .o file will be placed at wrong location and Kbuild cannot find
> the output files.
> 
> With this change we specify everything explicitly, so even if you pass
> `--crate-name=foo`, the object file is still `rust_binder.o` so the build can
> continue.
> 
> My point is that you *cannot* reasonably override crate names before this
> change.

Ok I understand now what you're getting at. That commit is required to
change the crate name (but it's not required to omit --crate-name
without changing what the crate name is).

Alice