Skip to content

Commit b8870fd

Browse files
committed
Makefile: generate CLANG_FLAGS even in GCC builds
To support Rust under GCC-built kernels, we need to save the flags that would have been passed if the kernel was being compiled with Clang. The reason is that `bindgen` -- the tool we use to generate Rust bindings to the C side of the kernel -- relies on `libclang` to parse C. Ideally: - `bindgen` would support a GCC backend (requested at [1]), - or the Clang driver would be perfectly compatible with GCC, including plugins. Unlikely, of course, but perhaps a big subset of configs may be possible to guarantee to be kept compatible nevertheless. This is also the reason why GCC builds are very experimental and some configurations may not work (e.g. `GCC_PLUGIN_RANDSTRUCT`). However, we keep GCC builds working (for some example configs) in the CI to avoid diverging/regressing further, so that we are better prepared for the future when a solution might become available. [1] rust-lang/rust-bindgen#1949 Link: Rust-for-Linux#167 Co-developed-by: Alex Gaynor <[email protected]> Signed-off-by: Alex Gaynor <[email protected]> Co-developed-by: Geoffrey Thomas <[email protected]> Signed-off-by: Geoffrey Thomas <[email protected]> Co-developed-by: Finn Behrens <[email protected]> Signed-off-by: Finn Behrens <[email protected]> Co-developed-by: Adam Bratschi-Kaye <[email protected]> Signed-off-by: Adam Bratschi-Kaye <[email protected]> Co-developed-by: Wedson Almeida Filho <[email protected]> Signed-off-by: Wedson Almeida Filho <[email protected]> Signed-off-by: Miguel Ojeda <[email protected]>
1 parent eefb53b commit b8870fd

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

Makefile

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -573,18 +573,23 @@ endif
573573
# and from include/config/auto.conf.cmd to detect the compiler upgrade.
574574
CC_VERSION_TEXT = $(subst $(pound),,$(shell $(CC) --version 2>/dev/null | head -n 1))
575575

576-
ifneq ($(findstring clang,$(CC_VERSION_TEXT)),)
576+
TENTATIVE_CLANG_FLAGS := -Werror=unknown-warning-option
577+
577578
ifneq ($(CROSS_COMPILE),)
578-
CLANG_FLAGS += --target=$(notdir $(CROSS_COMPILE:%-=%))
579+
TENTATIVE_CLANG_FLAGS += --target=$(notdir $(CROSS_COMPILE:%-=%))
579580
endif
580581
ifeq ($(LLVM_IAS),1)
581-
CLANG_FLAGS += -integrated-as
582+
TENTATIVE_CLANG_FLAGS += -integrated-as
582583
else
583-
CLANG_FLAGS += -no-integrated-as
584+
TENTATIVE_CLANG_FLAGS += -no-integrated-as
584585
GCC_TOOLCHAIN_DIR := $(dir $(shell which $(CROSS_COMPILE)elfedit))
585-
CLANG_FLAGS += --prefix=$(GCC_TOOLCHAIN_DIR)$(notdir $(CROSS_COMPILE))
586+
TENTATIVE_CLANG_FLAGS += --prefix=$(GCC_TOOLCHAIN_DIR)$(notdir $(CROSS_COMPILE))
586587
endif
587-
CLANG_FLAGS += -Werror=unknown-warning-option
588+
589+
export TENTATIVE_CLANG_FLAGS
590+
591+
ifneq ($(findstring clang,$(CC_VERSION_TEXT)),)
592+
CLANG_FLAGS += $(TENTATIVE_CLANG_FLAGS)
588593
KBUILD_CFLAGS += $(CLANG_FLAGS)
589594
KBUILD_AFLAGS += $(CLANG_FLAGS)
590595
export CLANG_FLAGS

0 commit comments

Comments
 (0)