Message ID | 20240808221138.873750-5-ojeda@kernel.org (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | kbuild: rust: add `RUSTC_VERSION` and reconfig/rebuild support | expand |
On Fri, Aug 09, 2024 at 12:11:36AM +0200, Miguel Ojeda wrote: > Now that `RUSTC_VERSION_TEXT` exists, use it to rebuild `core` when the > version text changes (which in turn will trigger a rebuild of all the > kernel Rust code). > > This also applies to proc macros (which only work with the `rustc` that > compiled them), via the already existing dependency on `core.o`. That > is cleaned up in the next commit. > > However, this does not cover host programs written in Rust, which is > the same case in the C side. > > This is accomplished by referencing directly the generated file, instead > of using the `fixdep` header trick, since we cannot change the Rust > standard library sources. This is not too much of a burden, since it > only needs to be done for `core`. > > Signed-off-by: Miguel Ojeda <ojeda@kernel.org> > --- > Masahiro: I used `$(objtree)` here since we still use it in the rest of > this `Makefile`, but please let me know if you prefer otherwise. Thanks! > > rust/Makefile | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/rust/Makefile b/rust/Makefile > index 6c0644b6090c..966743a9ee25 100644 > --- a/rust/Makefile > +++ b/rust/Makefile > @@ -370,7 +370,8 @@ $(obj)/core.o: private skip_clippy = 1 > $(obj)/core.o: private skip_flags = -Wunreachable_pub > $(obj)/core.o: private rustc_objcopy = $(foreach sym,$(redirect-intrinsics),--redefine-sym $(sym)=__rust$(sym)) > $(obj)/core.o: private rustc_target_flags = $(core-cfgs) > -$(obj)/core.o: $(RUST_LIB_SRC)/core/src/lib.rs FORCE > +$(obj)/core.o: $(RUST_LIB_SRC)/core/src/lib.rs \ > + $(wildcard $(objtree)/include/config/RUSTC_VERSION_TEXT) FORCE > +$(call if_changed_dep,rustc_library) > ifneq ($(or $(CONFIG_X86_64),$(CONFIG_X86_32)),) > $(obj)/core.o: scripts/target.json > -- > 2.46.0 Looks good to me, but I'd prefer something like the suggestion from Masahiro: https://lore.kernel.org/linux-kbuild/CAK7LNAQBG0nDupXSgAAk-6nOqeqGVkr3H1RjYaqRJ1OxmLm6xA@mail.gmail.com/
On Sat, Aug 17, 2024 at 3:04 PM Nicolas Schier <nicolas@fjasle.eu> wrote: > > Looks good to me, but I'd prefer something like the suggestion from > Masahiro: > https://lore.kernel.org/linux-kbuild/CAK7LNAQBG0nDupXSgAAk-6nOqeqGVkr3H1RjYaqRJ1OxmLm6xA@mail.gmail.com/ Do you mean for `core` (here), or for `macros` (in the next commit)? (if you mean for `core`, please see my reply to Masahiro there). Thanks for taking a look! Cheers, Miguel
On Sat, Aug 17, 2024 at 03:36:30PM +0200, Miguel Ojeda wrote: > On Sat, Aug 17, 2024 at 3:04 PM Nicolas Schier <nicolas@fjasle.eu> wrote: > > > > Looks good to me, but I'd prefer something like the suggestion from > > Masahiro: > > https://lore.kernel.org/linux-kbuild/CAK7LNAQBG0nDupXSgAAk-6nOqeqGVkr3H1RjYaqRJ1OxmLm6xA@mail.gmail.com/ > > Do you mean for `core` (here), or for `macros` (in the next commit)? > (if you mean for `core`, please see my reply to Masahiro there). oops, I missed that 'core' is delivered external. Sorry for the noise. Kind regards, Nicolas
On Sat, Aug 17, 2024 at 5:50 PM Nicolas Schier <nicolas@fjasle.eu> wrote: > > oops, I missed that 'core' is delivered external. Sorry for the noise. No worries at all, thanks for taking a look! I appreciate the reviews. Cheers, Miguel
diff --git a/rust/Makefile b/rust/Makefile index 6c0644b6090c..966743a9ee25 100644 --- a/rust/Makefile +++ b/rust/Makefile @@ -370,7 +370,8 @@ $(obj)/core.o: private skip_clippy = 1 $(obj)/core.o: private skip_flags = -Wunreachable_pub $(obj)/core.o: private rustc_objcopy = $(foreach sym,$(redirect-intrinsics),--redefine-sym $(sym)=__rust$(sym)) $(obj)/core.o: private rustc_target_flags = $(core-cfgs) -$(obj)/core.o: $(RUST_LIB_SRC)/core/src/lib.rs FORCE +$(obj)/core.o: $(RUST_LIB_SRC)/core/src/lib.rs \ + $(wildcard $(objtree)/include/config/RUSTC_VERSION_TEXT) FORCE +$(call if_changed_dep,rustc_library) ifneq ($(or $(CONFIG_X86_64),$(CONFIG_X86_32)),) $(obj)/core.o: scripts/target.json
Now that `RUSTC_VERSION_TEXT` exists, use it to rebuild `core` when the version text changes (which in turn will trigger a rebuild of all the kernel Rust code). This also applies to proc macros (which only work with the `rustc` that compiled them), via the already existing dependency on `core.o`. That is cleaned up in the next commit. However, this does not cover host programs written in Rust, which is the same case in the C side. This is accomplished by referencing directly the generated file, instead of using the `fixdep` header trick, since we cannot change the Rust standard library sources. This is not too much of a burden, since it only needs to be done for `core`. Signed-off-by: Miguel Ojeda <ojeda@kernel.org> --- Masahiro: I used `$(objtree)` here since we still use it in the rest of this `Makefile`, but please let me know if you prefer otherwise. Thanks! rust/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) -- 2.46.0