Consultation on the issue of enabling Ninja for compilation in OpenWrt 21.02

Hello everyone,

While compiling on the OpenWrt 21.02 branch, I encountered an issue where a plugin requires the Ninja toolchain. After referring to the OpenWrt main branch, I made modifications to the following files. However, when using GitHub Actions for compilation, I still encounter the following error:

time: tools/ninja/compile#0.00#0.00#0.00
ERROR: tools/ninja failed to build.

Upon checking the detailed logs, I found that the directory under tools could not be found (make[2]: *** tools/ninja: No such file or directory. Stop.), even though I had manually copied it via the command line.

At the moment, I don’t have a good solution for this issue. Below are portions of the code from the OpenWrt main branch that I referenced to modify the 21.02 branch. Any advice or guidance from experienced members would be greatly appreciated.

rules.mk


NINJA = \
	MAKEFLAGS="$(MAKE_JOBSERVER)" \
	$(STAGING_DIR_HOST)/bin/ninja \
		$(if $(findstring c,$(OPENWRT_VERBOSE)),-v) \
		$(if $(MAKE_JOBSERVER),,-j1)

tools/Makefile

$(curdir)/meson/compile := $(curdir)/ninja/compile
$(curdir)/cmake/compile += $(curdir)/libressl/compile $(curdir)/ninja/compile
ifneq ($(CONFIG_CCACHE)$(CONFIG_SDK),)
$(foreach tool, $(filter-out xz zstd patch pkgconf libressl ninja meson cmake,$(tools-y)), $(eval $(curdir)/$(tool)/compile += $(curdir)/ccache/compile))
tools-y += ccache
$(curdir)/ccache/compile := $(curdir)/zstd/compile
endif

include/cmake.mk

PKG_USE_NINJA ?= 1
HOST_USE_NINJA ?= 1
ifeq ($(PKG_USE_NINJA),1)
  PKG_BUILD_PARALLEL ?= 1
endif
ifeq ($(HOST_USE_NINJA),1)
  HOST_BUILD_PARALLEL ?= 1
endif

ifeq ($(HOST_USE_NINJA),1)
  CMAKE_HOST_OPTIONS += -DCMAKE_GENERATOR="Ninja"

  define Host/Compile/Default
	+$(NINJA) -C $(HOST_CMAKE_BINARY_DIR) $(1)
  endef

  define Host/Install/Default
	+$(NINJA) -C $(HOST_CMAKE_BINARY_DIR) install
  endef

  define Host/Uninstall/Default
	+$(NINJA) -C $(HOST_CMAKE_BINARY_DIR) uninstall
  endef
else
  CMAKE_HOST_OPTIONS += -DCMAKE_GENERATOR="Unix Makefiles"
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
else
  CMAKE_OPTIONS += -DCMAKE_GENERATOR="Unix Makefiles"
endif

This is my action url:https://github.com/yuos-bit/AutoBuild-OpenWrt

and logs:
https://productionresultssa18.blob.core.windows.net/actions-results/8174a3f3-f67c-419f-a7b1-47e5acee32cf/workflow-job-run-ca395085-040a-526b-2ce8-bdc85f692774/logs/job/job-logs.txt?rsct=text%2Fplain&se=2025-01-14T03%3A29%3A54Z&sig=7UU6efwJw5wYeGS4jCLkzsCxevrjGTjOCb4qp%2ByWoNI%3D&ske=2025-01-14T14%3A45%3A37Z&skoid=ca7593d4-ee42-46cd-af88-8b886a2f84eb&sks=b&skt=2025-01-14T02%3A45%3A37Z&sktid=398a6654-997b-47e9-b12b-9515b896b4de&skv=2024-11-04&sp=r&spr=https&sr=b&st=2025-01-14T03%3A19%3A49Z&sv=2024-11-04

Thanks evreyone!

Likely you need contemporary build host release to build ancient openwrt.