build: add support for using prebuilt LLVM toolchain
authorFelix Fietkau <nbd@nbd.name>
Thu, 4 Nov 2021 19:04:44 +0000 (20:04 +0100)
committerFelix Fietkau <nbd@nbd.name>
Thu, 4 Nov 2021 19:06:14 +0000 (20:06 +0100)
When the prebuilt llvm toolchain is unpacked into the source dir,
it is automatically picked up and used by the build system, and eBPF
based packages can be selected

Signed-off-by: Felix Fietkau <nbd@nbd.name>
include/bpf.mk
toolchain/Config.in

index 28cdf6cb3235f938077c521b2c0b86e19feb01db..c68ad74554911afa8240c6addc6c26c45167c54f 100644 (file)
@@ -1,6 +1,7 @@
 BPF_DEPENDS := @HAS_BPF_TOOLCHAIN
+LLVM_VER:=
 
-ifneq ($(CONFIG_BPF_TOOLCHAIN_HOST),)
+ifneq ($(CONFIG_USE_LLVM_HOST),)
   BPF_TOOLCHAIN_HOST_PATH:=$(call qstrip,$(CONFIG_BPF_TOOLCHAIN_HOST_PATH))
   ifneq ($(BPF_TOOLCHAIN_HOST_PATH),)
     BPF_PATH:=$(BPF_TOOLCHAIN_HOST_PATH)/bin:$(PATH)
@@ -9,9 +10,12 @@ ifneq ($(CONFIG_BPF_TOOLCHAIN_HOST),)
   endif
   CLANG:=$(firstword $(shell PATH='$(BPF_PATH)' which clang clang-13 clang-12 clang-11))
   LLVM_VER:=$(subst clang,,$(notdir $(CLANG)))
-else
+endif
+ifneq ($(CONFIG_USE_LLVM_PREBUILT),)
+  CLANG:=$(TOPDIR)/llvm-bpf/bin/clang
+endif
+ifneq ($(CONFIG_USE_LLVM_BUILD),)
   CLANG:=$(STAGING_DIR_HOST)/llvm-bpf/bin/clang
-  LLVM_VER:=
 endif
 
 LLVM_PATH:=$(dir $(CLANG))
index a7da2a1f732535d3c1ac56545728ad725860d012..366f5c8b486c462372ae3f1f187a363c249c531e 100644 (file)
@@ -41,11 +41,17 @@ menuconfig TARGET_OPTIONS
        choice BPF_TOOLCHAIN
                prompt "BPF toolchain" if DEVEL
                default BPF_TOOLCHAIN_BUILD_LLVM if BUILDBOT
+               default BPF_TOOLCHAIN_PREBUILT if HAS_PREBUILT_LLVM_TOOLCHAIN
                default BPF_TOOLCHAIN_NONE
 
                config BPF_TOOLCHAIN_NONE
                        bool "None"
 
+               config BPF_TOOLCHAIN_PREBUILT
+                       bool "Use prebuilt LLVM toolchain"
+                       depends on HAS_PREBUILT_LLVM_TOOLCHAIN
+                       select USE_LLVM_PREBUILT
+
                config BPF_TOOLCHAIN_HOST
                        select USE_LLVM_HOST
                        bool "Use host LLVM toolchain"
@@ -298,10 +304,18 @@ config GDB_PYTHON
 config HAS_BPF_TOOLCHAIN
        bool
 
+config HAS_PREBUILT_LLVM_TOOLCHAIN
+       def_bool $(shell, [ -f llvm-bpf/.llvm-version ] && echo y || echo n)
+
 config USE_LLVM_HOST
        select HAS_BPF_TOOLCHAIN
        bool
 
+config USE_LLVM_PREBUILT
+       select HAS_BPF_TOOLCHAIN
+       default y if !DEVEL && !BUILDBOT && HAS_PREBUILT_LLVM_TOOLCHAIN
+       bool
+
 config USE_LLVM_BUILD
        default y if !DEVEL && BUILDBOT
        select HAS_BPF_TOOLCHAIN