Re: [PATCH v2] Kbuild: fix issues with rustc-option

From: Masahiro Yamada
Date: Wed Oct 09 2024 - 06:33:03 EST


On Wed, Oct 9, 2024 at 4:42 AM Alice Ryhl <aliceryhl@xxxxxxxxxx> wrote:
>
> On Tue, Oct 8, 2024 at 9:00 PM Masahiro Yamada <masahiroy@xxxxxxxxxx> wrote:
> >
> > On Wed, Oct 9, 2024 at 2:32 AM Alice Ryhl <aliceryhl@xxxxxxxxxx> wrote:
> > > diff --git a/scripts/Makefile.compiler b/scripts/Makefile.compiler
> > > index 057305eae85c..08d5b7177ea8 100644
> > > --- a/scripts/Makefile.compiler
> > > +++ b/scripts/Makefile.compiler
> > > @@ -21,6 +21,7 @@ TMPOUT = $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/).tmp_$$$$
> > > # automatically cleaned up.
> > > try-run = $(shell set -e; \
> > > TMP=$(TMPOUT)/tmp; \
> > > + export RUSTC_BOOTSTRAP=1; \
> >
> >
> > try-run is not Rust-specific.
> >
> > Is there any reason why you did not add it
> > to __rustc-option?
> >
> >
> > __rustc-option = $(call try-run,\
> > RUSTC_BOOTSTRAP=1 $(1) $(2) $(3) --crate-type=rlib
> > $(srctree)/rust/probe.rs --out-dir=$$TMP,$(3),$(4))
>
> I had an explanation for this in the commit message, but it looks like
> it got lost when I rewrote it for v2. Anyway, the reason is that I'd
> have to modify both __rustc-option and rustc-option-yn to do that, and
> putting it here seemed more future-proof against making the same
> mistake in any rustc-* commands added in the future.


One solution is to delete rustc-option-yn since there are no users of it.

Another solution is to refactor the code.

Either way, there is no good reason for code duplication.


If you keep rustc-option-yn, you can rebased v3 on top of this patch:
https://lore.kernel.org/lkml/20241009102821.2675718-1-masahiroy@xxxxxxxxxx/T/#u




>
> But I realize that it's not clear-cut. I'm happy to move it if you prefer,
> or perhaps add a try-run-rust. Let me know what you think.
>
> > I guess it is still suspicious because the top-level Makefile
> > exports RUCTC_BOOTSTRAP.
>
> Moving the declaration of RUSTC_BOOTSTRAP to the top of the Makefile
> seems to fix it. I guess moving it is probably a better solution than
> adding it in scripts/Makefile.compiler.



I prefer to keep RUSTC_BOOTSTRAP close to other compiler flags.


>
> Not that I really understand why that is. The existing invocations are
> in scripts/Makefile.kasan which is invoked after RUSTC_BOOTSTRAP is
> declared.


Miguel gave perfect explanation.
https://lore.kernel.org/linux-kbuild/CAK7LNARDkS6uAHcdyZatc2SB7A66TWGfKZWNkYOoa7i3jo3QqA@xxxxxxxxxxxxxx/T/#m899bc321ae80d9c4a904680709c9a53f09e51b9e


>
>
> Alice
>
--
Best Regards
Masahiro Yamada