Skip to content

Commit f82811e

Browse files
JamieCunliffectmarinas
authored andcommitted
rust: Refactor the build target to allow the use of builtin targets
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 <[email protected]> Acked-by: Masahiro Yamada <[email protected]> Tested-by: Alice Ryhl <[email protected]> Link: https://lore.kernel.org/r/[email protected] [[email protected]: squashed loongarch ifneq fix from WANG Rui] Signed-off-by: Catalin Marinas <[email protected]>
1 parent 54be6c6 commit f82811e

File tree

5 files changed

+9
-3
lines changed

5 files changed

+9
-3
lines changed

Makefile

-1
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,6 @@ KBUILD_CFLAGS += -fno-strict-aliasing
561561

562562
KBUILD_CPPFLAGS := -D__KERNEL__
563563
KBUILD_RUSTFLAGS := $(rust_common_flags) \
564-
--target=$(objtree)/scripts/target.json \
565564
-Cpanic=abort -Cembed-bitcode=n -Clto=n \
566565
-Cforce-unwind-tables=n -Ccodegen-units=1 \
567566
-Csymbol-mangling-version=v0 \

arch/loongarch/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ KBUILD_AFLAGS_MODULE += -Wa,-mla-global-with-abs
8282
KBUILD_CFLAGS_MODULE += -fplt -Wa,-mla-global-with-abs,-mla-local-with-abs
8383
endif
8484

85+
KBUILD_RUSTFLAGS += --target=$(objtree)/scripts/target.json
8586
KBUILD_RUSTFLAGS_MODULE += -Crelocation-model=pic
8687

8788
ifeq ($(CONFIG_RELOCATABLE),y)

arch/x86/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export BITS
6868
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53383
6969
#
7070
KBUILD_CFLAGS += -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx
71+
KBUILD_RUSTFLAGS += --target=$(objtree)/scripts/target.json
7172
KBUILD_RUSTFLAGS += -Ctarget-feature=-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-avx,-avx2
7273

7374
ifeq ($(CONFIG_X86_KERNEL_IBT),y)

rust/Makefile

+4-1
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,11 @@ $(obj)/core.o: private skip_clippy = 1
434434
$(obj)/core.o: private skip_flags = -Dunreachable_pub
435435
$(obj)/core.o: private rustc_objcopy = $(foreach sym,$(redirect-intrinsics),--redefine-sym $(sym)=__rust$(sym))
436436
$(obj)/core.o: private rustc_target_flags = $(core-cfgs)
437-
$(obj)/core.o: $(RUST_LIB_SRC)/core/src/lib.rs scripts/target.json FORCE
437+
$(obj)/core.o: $(RUST_LIB_SRC)/core/src/lib.rs FORCE
438438
$(call if_changed_dep,rustc_library)
439+
ifneq ($(or $(CONFIG_X86_64),$(CONFIG_LOONGARCH)),)
440+
$(obj)/core.o: scripts/target.json
441+
endif
439442

440443
$(obj)/compiler_builtins.o: private rustc_objcopy = -w -W '__*'
441444
$(obj)/compiler_builtins.o: $(src)/compiler_builtins.rs $(obj)/core.o FORCE

scripts/Makefile

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ hostprogs-always-$(CONFIG_MODULE_SIG_FORMAT) += sign-file
1111
hostprogs-always-$(CONFIG_SYSTEM_EXTRA_CERTIFICATE) += insert-sys-cert
1212
hostprogs-always-$(CONFIG_RUST_KERNEL_DOCTESTS) += rustdoc_test_builder
1313
hostprogs-always-$(CONFIG_RUST_KERNEL_DOCTESTS) += rustdoc_test_gen
14-
always-$(CONFIG_RUST) += target.json
1514

15+
ifneq ($(or $(CONFIG_X86_64),$(CONFIG_LOONGARCH)),)
16+
always-$(CONFIG_RUST) += target.json
1617
filechk_rust_target = $< < include/config/auto.conf
1718

1819
$(obj)/target.json: scripts/generate_rust_target include/config/auto.conf FORCE
1920
$(call filechk,rust_target)
21+
endif
2022

2123
hostprogs += generate_rust_target
2224
generate_rust_target-rust := y

0 commit comments

Comments
 (0)