[openwrt/openwrt] tools/llvm-bpf: add llvm+clang build suitable for compiling code to eBPF

LEDE Commits lede-commits at lists.infradead.org
Wed Oct 20 02:36:21 PDT 2021


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

commit faa6a9a04beda71da49dd2d96225e892899e84d7
Author: Felix Fietkau <nbd at nbd.name>
AuthorDate: Sun Oct 17 17:50:53 2021 +0200

    tools/llvm-bpf: add llvm+clang build suitable for compiling code to eBPF
    
    Preparation for building packages that ship eBPF code
    
    Signed-off-by: Felix Fietkau <nbd at nbd.name>
---
 toolchain/Config.in     |  7 +++++++
 tools/Makefile          |  2 ++
 tools/llvm-bpf/Makefile | 36 ++++++++++++++++++++++++++++++++++++
 3 files changed, 45 insertions(+)

diff --git a/toolchain/Config.in b/toolchain/Config.in
index 8ff5438d79..1d230ca22f 100644
--- a/toolchain/Config.in
+++ b/toolchain/Config.in
@@ -37,6 +37,13 @@ menuconfig TARGET_OPTIONS
 
 		  Most people will answer N.
 
+config BUILD_LLVM_BPF
+	bool "Build LLVM toolchain for eBPF" if DEVEL
+	help
+	  If enabled, a LLVM toolchain for building eBPF binaries will be built.
+	  If this is not enabled, eBPF packages can only be built if the host
+	  has a suitable toolchain
+
 
 menuconfig EXTERNAL_TOOLCHAIN
 	bool
diff --git a/tools/Makefile b/tools/Makefile
index f794e57f2e..dc665f6b46 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -35,6 +35,7 @@ tools-$(CONFIG_TARGET_mxs) += elftosb sdimage
 tools-$(CONFIG_TARGET_tegra) += cbootimage cbootimage-configs
 tools-$(CONFIG_USES_MINOR) += kernel2minor
 tools-$(CONFIG_USE_SPARSE) += sparse
+tools-$(CONFIG_BUILD_LLVM_BPF) += llvm-bpf
 
 # builddir dependencies
 $(curdir)/autoconf/compile := $(curdir)/m4/compile
@@ -56,6 +57,7 @@ $(curdir)/isl/compile := $(curdir)/gmp/compile
 $(curdir)/libressl/compile := $(curdir)/pkgconf/compile
 $(curdir)/libtool/compile := $(curdir)/m4/compile $(curdir)/autoconf/compile $(curdir)/automake/compile $(curdir)/missing-macros/compile
 $(curdir)/lzma-old/compile := $(curdir)/zlib/compile
+$(curdir)/llvm-bpf/compile := $(curdir)/cmake/compile
 $(curdir)/make-ext4fs/compile := $(curdir)/zlib/compile
 $(curdir)/meson/compile := $(curdir)/ninja/compile
 $(curdir)/missing-macros/compile := $(curdir)/autoconf/compile
diff --git a/tools/llvm-bpf/Makefile b/tools/llvm-bpf/Makefile
new file mode 100644
index 0000000000..a5ba2a4cb7
--- /dev/null
+++ b/tools/llvm-bpf/Makefile
@@ -0,0 +1,36 @@
+#
+# Copyright (C) 2006-2016 OpenWrt.org
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=llvm-project
+PKG_VERSION:=13.0.0
+PKG_RELEASE:=1
+
+PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).src.tar.xz
+PKG_SOURCE_URL:=https://github.com/llvm/llvm-project/releases/download/llvmorg-$(PKG_VERSION)
+PKG_HASH:=6075ad30f1ac0e15f07c1bf062c1e1268c241d674f11bd32cdf0e040c71f2bf3
+
+HOST_BUILD_DIR:=$(BUILD_DIR_HOST)/$(PKG_NAME)-$(PKG_VERSION).src
+
+HOST_BUILD_PARALLEL:=1
+
+CMAKE_BINARY_SUBDIR := build
+CMAKE_SOURCE_SUBDIR := llvm
+
+include $(INCLUDE_DIR)/host-build.mk
+include $(INCLUDE_DIR)/cmake.mk
+
+CMAKE_HOST_OPTIONS += \
+	-DLLVM_ENABLE_BINDINGS=OFF \
+	-DLLVM_INCLUDE_DOCS=OFF \
+	-DLLVM_INCLUDE_EXAMPLES=OFF \
+	-DLLVM_INCLUDE_TESTS=OFF \
+	-DLLVM_ENABLE_PROJECTS="clang;lld" \
+	-DLLVM_TARGETS_TO_BUILD=BPF \
+	-DCLANG_BUILD_EXAMPLES=OFF
+
+$(eval $(call HostBuild))



More information about the lede-commits mailing list