[openwrt/openwrt] llvm-bpf: support creating a tarball in bin

LEDE Commits lede-commits at lists.infradead.org
Thu Nov 4 08:59:43 PDT 2021


nbd pushed a commit to openwrt/openwrt.git, branch master:
https://git.openwrt.org/2a832b3df5990f33aa3d5944733e43bf5287475c

commit 2a832b3df5990f33aa3d5944733e43bf5287475c
Author: Felix Fietkau <nbd at nbd.name>
AuthorDate: Thu Nov 4 15:16:07 2021 +0100

    llvm-bpf: support creating a tarball in bin
    
    This can be used for adding the toolchain to an existing tree without having
    to build it from scratch.
    Enable building the toolchain + tarball by default on buildbot
    
    Signed-off-by: Felix Fietkau <nbd at nbd.name>
---
 target/sdk/Config.in    |  9 ++++++++-
 target/sdk/Makefile     |  3 ++-
 toolchain/Config.in     |  2 ++
 tools/llvm-bpf/Makefile | 25 ++++++++++++++++++++++++-
 4 files changed, 36 insertions(+), 3 deletions(-)

diff --git a/target/sdk/Config.in b/target/sdk/Config.in
index 0c8a61d247..1984e242e7 100644
--- a/target/sdk/Config.in
+++ b/target/sdk/Config.in
@@ -7,4 +7,11 @@ config SDK
 	  with a precompiled toolchain. It can be used to develop and
 	  test packages for OpenWrt before including them in the buildroot
 
-
+config SDK_LLVM_BPF
+	bool "Build the LLVM-BPF toolchain tarball"
+	depends on BPF_TOOLCHAIN_BUILD_LLVM
+	default BUILDBOT
+	help
+	  This is a tarball of the precompiled LLVM toolchain suitable
+	  for unpacking into the buildroot/SDK. It is used to build packages
+	  that ship with eBPF kernel modules
diff --git a/target/sdk/Makefile b/target/sdk/Makefile
index 0606621192..7d7f09b514 100644
--- a/target/sdk/Makefile
+++ b/target/sdk/Makefile
@@ -34,7 +34,8 @@ EXCLUDE_DIRS:= \
 	*.install.flags \
 	*.install \
 	*/doc \
-	*/share/locale
+	*/share/locale \
+	*/llvm-bpf*
 
 SDK_DIRS = \
 		$(STAGING_SUBDIR_HOST) \
diff --git a/toolchain/Config.in b/toolchain/Config.in
index b8b4cfeb88..a7da2a1f73 100644
--- a/toolchain/Config.in
+++ b/toolchain/Config.in
@@ -40,6 +40,7 @@ menuconfig TARGET_OPTIONS
 
 	choice BPF_TOOLCHAIN
 		prompt "BPF toolchain" if DEVEL
+		default BPF_TOOLCHAIN_BUILD_LLVM if BUILDBOT
 		default BPF_TOOLCHAIN_NONE
 
 		config BPF_TOOLCHAIN_NONE
@@ -302,6 +303,7 @@ config USE_LLVM_HOST
 	bool
 
 config USE_LLVM_BUILD
+	default y if !DEVEL && BUILDBOT
 	select HAS_BPF_TOOLCHAIN
 	bool
 
diff --git a/tools/llvm-bpf/Makefile b/tools/llvm-bpf/Makefile
index ae279d26d2..a9fcc04495 100644
--- a/tools/llvm-bpf/Makefile
+++ b/tools/llvm-bpf/Makefile
@@ -24,7 +24,9 @@ CMAKE_SOURCE_SUBDIR := llvm
 include $(INCLUDE_DIR)/host-build.mk
 include $(INCLUDE_DIR)/cmake.mk
 
-CMAKE_HOST_INSTALL_PREFIX = $(STAGING_DIR_HOST)/llvm-bpf
+LLVM_BPF_PREFIX = llvm-bpf-$(PKG_VERSION).$(HOST_OS)-$(HOST_ARCH)
+
+CMAKE_HOST_INSTALL_PREFIX = $(STAGING_DIR_HOST)/$(LLVM_BPF_PREFIX)
 
 CMAKE_HOST_OPTIONS += \
 	-DLLVM_ENABLE_BINDINGS=OFF \
@@ -39,4 +41,25 @@ CMAKE_HOST_OPTIONS += \
 	-DLLVM_TOOLCHAIN_TOOLS="llvm-objcopy;llvm-objdump;llvm-readelf;llvm-strip;llvm-ar;llvm-as;llvm-dis;llvm-link;llvm-nm;llvm-ranlib;llc;opt" \
 	-DCMAKE_SKIP_RPATH=OFF
 
+ifneq ($(CONFIG_SDK_LLVM_BPF),)
+  define Host/Install/Bin
+	echo "$(PKG_VERSION)" > $(CMAKE_HOST_INSTALL_PREFIX)/.llvm-version
+	STRIP_KMOD= PATCHELF= STRIP=strip $(SCRIPT_DIR)/rstrip.sh $(STAGING_DIR_HOST)/llvm-bpf
+	tar -C $(STAGING_DIR_HOST) \
+		-I '$(STAGING_DIR_HOST)/bin/xz -7e -T$(if $(filter 1,$(NPROC)),2,0)' \
+		-cf $(BIN_DIR)/llvm-bpf-$(PKG_VERSION).tar.xz llvm-bpf $(LLVM_BPF_PREFIX)
+  endef
+endif
+
+define Host/Install
+	rm -rf $(STAGING_DIR_HOST)/llvm-bpf*
+	$(Host/Install/Default)
+	ln -s $(LLVM_BPF_PREFIX) $(STAGING_DIR_HOST)/llvm-bpf
+	$(Host/Install/Bin)
+endef
+
+define Host/Uninstall
+	rm -rf $(STAGING_DIR_HOST)/llvm-bpf*
+endef
+
 $(eval $(call HostBuild))



More information about the lede-commits mailing list