Re: [PATCH v3 1/2] kbuild: Introduce CONFIG_CROSS_COMPILING
From: Nathan Chancellor
Date: Wed Nov 25 2026 - 15:28:48 EST
On Wed, Nov 25, 2026 at 11:27:10AM +0100, Thomas Weißschuh wrote:
> The expansion to bit width and endianess will be a lot of busy-work.
> See the CC_CAN_LINK infrastructure.
Yeah, fair enough.
> We already have host-architecture detection in kbuild through
> scripts/subarch.include. So CC_HAS_MARCH_NATIVE could depend on
> $(ARCH) = $(SUBARCH), after exporting SUBARCH. Or maybe give the
> variable a better name, like HOSTARCH.
>
> This would avoid the introduction of a new, not-really-correct flag
> and also the whack-a-mole that Boris complained about.
Ah, thanks a lot for reminding me about SUBARCH! In looking around, I
noticed that Kbuild already checks if SRCARCH = SUBARCH and exports
cross_compiling=1 in that case, which means this patch should just
become
diff --git a/scripts/Kconfig.toolchain b/scripts/Kconfig.toolchain
index 2acbd40a38f1..a8b5258eac7e 100644
--- a/scripts/Kconfig.toolchain
+++ b/scripts/Kconfig.toolchain
@@ -97,6 +97,9 @@ config RUSTC_CLANG_LLVM_COMPATIBLE
LTO) require the same LLVM major version to work properly. For best
compatibility it is recommended that the exact same LLVM is used.
+config CROSS_COMPILING
+ def_bool $(success,test "$(cross_compiling)" = "1")
+
config ARCH_HAS_CC_CAN_LINK
bool
--
unless we did not want the separate symbol, in which case patch two
could just become
diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
index 6e7a366f0798..b40aaff6867d 100644
--- a/arch/x86/Kconfig.cpu
+++ b/arch/x86/Kconfig.cpu
@@ -217,6 +217,7 @@ config RUSTC_HAS_APXF
config X86_NATIVE_CPU
bool "Build and optimize for local/native CPU"
depends on X86_64
+ depends on $(success,test "$(cross_compiling)" = "")
depends on CC_HAS_MARCH_NATIVE
depends on !RUST || RUSTC_HAS_APXF
help
--
-tip folks, preferences?
--
Cheers,
Nathan