rust: Refactor the build target to allow the use of builtin targets
authorJamie Cunliffe <Jamie.Cunliffe@arm.com>
Fri, 20 Oct 2023 15:50:55 +0000 (16:50 +0100)
committerCatalin Marinas <catalin.marinas@arm.com>
Fri, 9 Feb 2024 16:11:07 +0000 (16:11 +0000)
Eventually we want all architectures to be using the target as defined
by rustc. However currently some architectures can't do that and are
using the target.json specification. This puts in place the foundation
to allow the use of the builtin target definition or a target.json
specification.

Signed-off-by: Jamie Cunliffe <Jamie.Cunliffe@arm.com>
Acked-by: Masahiro Yamada <masahiroy@kernel.org>
Tested-by: Alice Ryhl <aliceryhl@google.com>
Link: https://lore.kernel.org/r/20231020155056.3495121-2-Jamie.Cunliffe@arm.com
[catalin.marinas@arm.com: squashed loongarch ifneq fix from WANG Rui]
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
Makefile
arch/loongarch/Makefile
arch/x86/Makefile
rust/Makefile
scripts/Makefile

index a171eafce2a3b98d025cc071e54d3bf3c84f2446..c951c14fd4e70f36b77b3e24515c4307815353eb 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -561,7 +561,6 @@ KBUILD_CFLAGS += -fno-strict-aliasing
 
 KBUILD_CPPFLAGS := -D__KERNEL__
 KBUILD_RUSTFLAGS := $(rust_common_flags) \
-                   --target=$(objtree)/scripts/target.json \
                    -Cpanic=abort -Cembed-bitcode=n -Clto=n \
                    -Cforce-unwind-tables=n -Ccodegen-units=1 \
                    -Csymbol-mangling-version=v0 \
index 983aa2b1629a69fe74c4c8358d094fbd424283b9..fa4fb09909aeb1c7ebe640329936cd095e8224c8 100644 (file)
@@ -82,6 +82,7 @@ KBUILD_AFLAGS_MODULE          += -Wa,-mla-global-with-abs
 KBUILD_CFLAGS_MODULE           += -fplt -Wa,-mla-global-with-abs,-mla-local-with-abs
 endif
 
+KBUILD_RUSTFLAGS                       += --target=$(objtree)/scripts/target.json
 KBUILD_RUSTFLAGS_MODULE                += -Crelocation-model=pic
 
 ifeq ($(CONFIG_RELOCATABLE),y)
index 2264db14a25d3b034ffa93685d6353564d4a9225..18cf8f0cf7cd17e0469857eccf4f75500c27ccfa 100644 (file)
@@ -68,6 +68,7 @@ export BITS
 #    https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53383
 #
 KBUILD_CFLAGS += -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx
+KBUILD_RUSTFLAGS += --target=$(objtree)/scripts/target.json
 KBUILD_RUSTFLAGS += -Ctarget-feature=-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-avx,-avx2
 
 ifeq ($(CONFIG_X86_KERNEL_IBT),y)
index 9d2a16cc91cb44f8f8836b3e45f4ad30c13b9c22..88f88a26e5032ee0ad9d228c30eedf33782d8cd4 100644 (file)
@@ -434,8 +434,11 @@ $(obj)/core.o: private skip_clippy = 1
 $(obj)/core.o: private skip_flags = -Dunreachable_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 scripts/target.json FORCE
+$(obj)/core.o: $(RUST_LIB_SRC)/core/src/lib.rs FORCE
        $(call if_changed_dep,rustc_library)
+ifneq ($(or $(CONFIG_X86_64),$(CONFIG_LOONGARCH)),)
+$(obj)/core.o: scripts/target.json
+endif
 
 $(obj)/compiler_builtins.o: private rustc_objcopy = -w -W '__*'
 $(obj)/compiler_builtins.o: $(src)/compiler_builtins.rs $(obj)/core.o FORCE
index 576cf64be6677c28e1a048e082594e303a4c7f78..6673cbb6194fe0b317014b7a96485d78d87fe19b 100644 (file)
@@ -11,12 +11,14 @@ hostprogs-always-$(CONFIG_MODULE_SIG_FORMAT)                += sign-file
 hostprogs-always-$(CONFIG_SYSTEM_EXTRA_CERTIFICATE)    += insert-sys-cert
 hostprogs-always-$(CONFIG_RUST_KERNEL_DOCTESTS)                += rustdoc_test_builder
 hostprogs-always-$(CONFIG_RUST_KERNEL_DOCTESTS)                += rustdoc_test_gen
-always-$(CONFIG_RUST)                                  += target.json
 
+ifneq ($(or $(CONFIG_X86_64),$(CONFIG_LOONGARCH)),)
+always-$(CONFIG_RUST)                                  += target.json
 filechk_rust_target = $< < include/config/auto.conf
 
 $(obj)/target.json: scripts/generate_rust_target include/config/auto.conf FORCE
        $(call filechk,rust_target)
+endif
 
 hostprogs += generate_rust_target
 generate_rust_target-rust := y