build: add ninja build tool and make it available for cmake

ninja is faster at building cmake packages than make, and according to reports
also more reliable at handling parallel builds
This commit includes a patch that adds GNU make jobserver support, in order to
allow more precise control over the number of parallel tasks

Enable parallel build by default for packages using ninja

Signed-off-by: Felix Fietkau <nbd@nbd.name>
Signed-off-by: Rosen Penev <rosenp@gmail.com>
This commit is contained in:
Felix Fietkau 2021-06-06 14:31:01 +02:00
parent a85aaa1bc2
commit 97258f5363
5 changed files with 2359 additions and 1 deletions

View File

@ -1,5 +1,11 @@
cmake_bool = $(patsubst %,-D%:BOOL=$(if $($(1)),ON,OFF),$(2))
ifeq ($(PKG_USE_NINJA),1)
PKG_BUILD_PARALLEL ?= 1
endif
ifeq ($(HOST_USE_NINJA),1)
HOST_BUILD_PARALLEL ?= 1
endif
PKG_INSTALL:=1
ifneq ($(findstring c,$(OPENWRT_VERBOSE)),)
@ -44,6 +50,34 @@ CMAKE_FIND_ROOT_PATH:=$(STAGING_DIR)/usr;$(TOOLCHAIN_DIR)$(if $(CONFIG_EXTERNAL_
CMAKE_HOST_FIND_ROOT_PATH:=$(STAGING_DIR)/host;$(STAGING_DIR_HOSTPKG);$(STAGING_DIR_HOST)
CMAKE_SHARED_LDFLAGS:=-Wl,-Bsymbolic-functions
ifeq ($(HOST_USE_NINJA),1)
CMAKE_HOST_OPTIONS += -DCMAKE_GENERATOR="Ninja"
define Host/Compile/Default
+$(NINJA) -C $(HOST_BUILD_DIR) $(1)
endef
define Host/Install/Default
+DESTDIR="$(HOST_INSTALL_DIR)" $(NINJA) -C $(HOST_BUILD_DIR) install
endef
define Host/Uninstall/Default
+DESTDIR="$(HOST_INSTALL_DIR)" $(NINJA) -C $(HOST_BUILD_DIR) uninstall
endef
endif
ifeq ($(PKG_USE_NINJA),1)
CMAKE_OPTIONS += -DCMAKE_GENERATOR="Ninja"
define Build/Compile/Default
+$(NINJA) -C $(CMAKE_BINARY_DIR) $(1)
endef
define Build/Install/Default
+DESTDIR="$(PKG_INSTALL_DIR)" $(NINJA) -C $(CMAKE_BINARY_DIR) install
endef
endif
define Build/Configure/Default
mkdir -p $(CMAKE_BINARY_DIR)
(cd $(CMAKE_BINARY_DIR); \

View File

@ -342,6 +342,12 @@ else
$(SCRIPT_DIR)/rstrip.sh
endif
NINJA = \
MAKEFLAGS="$(MAKE_JOBSERVER)" \
$(STAGING_DIR_HOST)/bin/ninja \
$(if $(findstring c,$(OPENWRT_VERBOSE)),-v) \
$(if $(MAKE_JOBSERVER),,-j1)
ifeq ($(CONFIG_IPV6),y)
DISABLE_IPV6:=
else

View File

@ -24,7 +24,7 @@ endif
tools-y += autoconf autoconf-archive automake bc bison cmake cpio dosfstools
tools-y += e2fsprogs fakeroot findutils firmware-utils flex gengetopt
tools-y += libressl libtool lzma m4 make-ext4fs missing-macros mkimage
tools-y += mklibs mm-macros mtd-utils mtools padjffs2 patch-image
tools-y += mklibs mm-macros mtd-utils mtools ninja padjffs2 patch-image
tools-y += patchelf pkgconf quilt squashfskit4 sstrip xxd zip zlib zstd
tools-$(BUILD_B43_TOOLS) += b43-tools
tools-$(BUILD_ISL) += isl

39
tools/ninja/Makefile Normal file
View File

@ -0,0 +1,39 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=ninja
PKG_VERSION:=1.10.2
PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://codeload.github.com/ninja-build/ninja/tar.gz/v$(PKG_VERSION)?
PKG_HASH:=ce35865411f0490368a8fc383f29071de6690cbadc27704734978221f25e2bed
include $(INCLUDE_DIR)/host-build.mk
CONFIGURE_ARGS:=
ifneq ($(findstring c,$(OPENWRT_VERBOSE)),)
CONFIGURE_ARGS+=--verbose
endif
define Host/Configure
endef
define Host/Compile
cd $(HOST_BUILD_DIR) && \
CXX="$(HOSTCXX)" \
CXXFLAGS="$(HOST_CXXFLAGS) $(HOST_CPPFLAGS)" \
LDFLAGS="$(HOST_LDFLAGS)" \
$(STAGING_DIR_HOST)/bin/$(PYTHON) configure.py --bootstrap $(CONFIGURE_ARGS)
endef
define Host/Install
$(INSTALL_DIR) $(STAGING_DIR_HOST)/bin
$(INSTALL_BIN) $(HOST_BUILD_DIR)/ninja $(STAGING_DIR_HOST)/bin/
endef
define Host/Clean
$(call Host/Clean/Default)
rm -f $(STAGING_DIR_HOST)/bin/ninja
endef
$(eval $(call HostBuild))

File diff suppressed because it is too large Load Diff