From 9074dbd91770d9913378a3c20e31ea5bde2c2be7 Mon Sep 17 00:00:00 2001 From: Jeffery To Date: Mon, 24 Aug 2020 04:59:05 +0800 Subject: [PATCH] golang: Share build cache across package builds This also adds a config option GOLANG_BUILD_CACHE_DIR to customize the location of the build cache directory. Signed-off-by: Jeffery To --- lang/golang/golang-package.mk | 22 ++++++++++++---------- lang/golang/golang-values.mk | 1 + lang/golang/golang/Config.in | 7 +++++++ lang/golang/golang/Makefile | 26 ++++++-------------------- utils/ctop/Makefile | 5 ++--- utils/docker-ce/Makefile | 3 +-- 6 files changed, 29 insertions(+), 35 deletions(-) diff --git a/lang/golang/golang-package.mk b/lang/golang/golang-package.mk index 266bfeda4..46b484b4d 100644 --- a/lang/golang/golang-package.mk +++ b/lang/golang/golang-package.mk @@ -123,11 +123,7 @@ GO_PKG_PATH:=/usr/share/gocode GO_PKG_BUILD_PKG?=$(strip $(GO_PKG))/... GO_PKG_WORK_DIR_NAME:=.go_work -GO_PKG_WORK_DIR=$(PKG_BUILD_DIR)/$(GO_PKG_WORK_DIR_NAME) - -GO_PKG_BUILD_DIR=$(GO_PKG_WORK_DIR)/build -GO_PKG_CACHE_DIR=$(GO_PKG_WORK_DIR)/cache - +GO_PKG_BUILD_DIR=$(PKG_BUILD_DIR)/$(GO_PKG_WORK_DIR_NAME)/build GO_PKG_BUILD_BIN_DIR=$(GO_PKG_BUILD_DIR)/bin$(if $(GO_HOST_TARGET_DIFFERENT),/$(GO_OS_ARCH)) GO_PKG_BUILD_DEPENDS_SRC=$(STAGING_DIR)$(GO_PKG_PATH)/src @@ -185,7 +181,7 @@ GO_PKG_TARGET_VARS= \ GO_PKG_BUILD_VARS= \ GOPATH=$(GO_PKG_BUILD_DIR) \ - GOCACHE=$(GO_PKG_CACHE_DIR) \ + GOCACHE=$(GO_BUILD_CACHE_DIR) \ GOMODCACHE=$(GO_MOD_CACHE_DIR) \ GOENV=off @@ -195,9 +191,6 @@ GO_PKG_DEFAULT_VARS= \ GO_PKG_VARS=$(GO_PKG_DEFAULT_VARS) -# do not use for new code; this will be removed after the next OpenWrt release -GoPackage/Environment=$(GO_PKG_VARS) - GO_PKG_DEFAULT_LDFLAGS= \ -buildid '$(SOURCE_DATE_EPOCH)' \ -linkmode external \ @@ -227,7 +220,9 @@ GoPackage/has_binaries=$(call GoPackage/is_dir_not_empty,$(GO_PKG_BUILD_BIN_DIR) define GoPackage/Build/Configure ( \ cd $(PKG_BUILD_DIR) ; \ - mkdir -p $(GO_PKG_BUILD_DIR)/bin $(GO_PKG_BUILD_DIR)/src $(GO_PKG_CACHE_DIR) $(GO_MOD_CACHE_DIR) ; \ + mkdir -p \ + $(GO_PKG_BUILD_DIR)/bin $(GO_PKG_BUILD_DIR)/src \ + $(GO_BUILD_CACHE_DIR) $(GO_MOD_CACHE_DIR) ; \ \ files=$$$$($(FIND) ./ \ -type d -a \( -path './.git' -o -path './$(GO_PKG_WORK_DIR_NAME)' \) -prune -o \ @@ -387,3 +382,10 @@ define GoSrcPackage Package/$(1)/install=$$(call GoPackage/Package/Install/Src,$$(1)) endif endef + + +# Deprecated variables - these will be removed after the next OpenWrt release +GO_PKG_WORK_DIR=$(PKG_BUILD_DIR)/$(GO_PKG_WORK_DIR_NAME) +GO_PKG_CACHE_DIR=$(GO_BUILD_CACHE_DIR) +GoPackage/Environment=$(GO_PKG_VARS) +# End of deprecated variables diff --git a/lang/golang/golang-values.mk b/lang/golang/golang-values.mk index 84b6b5892..596270caf 100644 --- a/lang/golang/golang-values.mk +++ b/lang/golang/golang-values.mk @@ -223,6 +223,7 @@ endif # General build info +GO_BUILD_CACHE_DIR:=$(or $(call qstrip,$(CONFIG_GOLANG_BUILD_CACHE_DIR)),$(TOPDIR)/.go-build) GO_MOD_CACHE_DIR:=$(DL_DIR)/go-mod-cache GO_MOD_ARGS= \ diff --git a/lang/golang/golang/Config.in b/lang/golang/golang/Config.in index cb5fec6d5..2e7159173 100644 --- a/lang/golang/golang/Config.in +++ b/lang/golang/golang/Config.in @@ -12,6 +12,13 @@ config GOLANG_EXTERNAL_BOOTSTRAP_ROOT Leave blank to compile the default bootstrap Go. +config GOLANG_BUILD_CACHE_DIR + string "Go build cache directory" + default "" + help + Store the Go build cache in this directory. + If not set, uses './.go-build'. + config GOLANG_MOD_CACHE_WORLD_READABLE bool "Ensure Go module cache is world-readable" default n diff --git a/lang/golang/golang/Makefile b/lang/golang/golang/Makefile index c08028d09..8557179b0 100644 --- a/lang/golang/golang/Makefile +++ b/lang/golang/golang/Makefile @@ -32,10 +32,6 @@ PKG_BUILD_DIR:=$(BUILD_DIR)/go-$(PKG_VERSION) PKG_BUILD_PARALLEL:=1 PKG_USE_MIPS16:=0 -PKG_GO_WORK_DIR:=$(PKG_BUILD_DIR)/.go_work -PKG_GO_HOST_CACHE_DIR:=$(PKG_GO_WORK_DIR)/host_cache -PKG_GO_TARGET_CACHE_DIR:=$(PKG_GO_WORK_DIR)/target_cache - PKG_GO_PREFIX:=/usr PKG_GO_VERSION_ID:=$(GO_VERSION_MAJOR_MINOR) PKG_GO_ROOT:=$(PKG_GO_PREFIX)/lib/go-$(PKG_GO_VERSION_ID) @@ -43,9 +39,6 @@ PKG_GO_ROOT:=$(PKG_GO_PREFIX)/lib/go-$(PKG_GO_VERSION_ID) HOST_BUILD_DIR:=$(BUILD_DIR_HOST)/go-$(PKG_VERSION) HOST_BUILD_PARALLEL:=1 -HOST_GO_WORK_DIR:=$(HOST_BUILD_DIR)/.go_work -HOST_GO_CACHE_DIR:=$(HOST_GO_WORK_DIR)/cache - HOST_GO_PREFIX:=$(STAGING_DIR_HOSTPKG) HOST_GO_VERSION_ID:=cross HOST_GO_ROOT:=$(HOST_GO_PREFIX)/lib/go-$(HOST_GO_VERSION_ID) @@ -78,8 +71,6 @@ BOOTSTRAP_SOURCE_URL:=$(GO_SOURCE_URLS) BOOTSTRAP_HASH:=f4ff5b5eb3a3cae1c993723f3eab519c5bae18866b5e5f96fe1102f0cb5c3e52 BOOTSTRAP_BUILD_DIR:=$(HOST_BUILD_DIR)/.go_bootstrap -BOOTSTRAP_WORK_DIR:=$(BOOTSTRAP_BUILD_DIR)/.go_work -BOOTSTRAP_CACHE_DIR:=$(BOOTSTRAP_WORK_DIR)/cache BOOTSTRAP_GO_VALID_OS_ARCH:= \ darwin_386 darwin_amd64 \ @@ -236,19 +227,16 @@ define Host/Compile $(call GoCompiler/Bootstrap/CheckHost,$(BOOTSTRAP_GO_VALID_OS_ARCH)) $(call GoCompiler/Host/CheckHost,$(HOST_GO_VALID_OS_ARCH)) - mkdir -p \ - $(BOOTSTRAP_CACHE_DIR) \ - $(HOST_GO_CACHE_DIR) + mkdir -p $(GO_BUILD_CACHE_DIR) $(call GoCompiler/Bootstrap/Make, \ - GOCACHE=$(BOOTSTRAP_CACHE_DIR) \ CC=$(HOSTCC_NOCACHE) \ CXX=$(HOSTCXX_NOCACHE) \ ) $(call GoCompiler/Host/Make, \ GOROOT_BOOTSTRAP=$(if $(USE_DEFAULT_BOOTSTRAP),$(BOOTSTRAP_BUILD_DIR),$(EXTERNAL_BOOTSTRAP_DIR)) \ - GOCACHE=$(HOST_GO_CACHE_DIR) \ + GOCACHE=$(GO_BUILD_CACHE_DIR) \ CC=$(HOSTCC_NOCACHE) \ CXX=$(HOSTCXX_NOCACHE) \ ) @@ -259,7 +247,7 @@ define Host/Compile ( \ cd $(HOST_BUILD_DIR)/bin ; \ $(CP) go go-nopie ; \ - GOCACHE=$(HOST_GO_CACHE_DIR) \ + GOCACHE=$(GO_BUILD_CACHE_DIR) \ GOENV=off \ CC=$(HOSTCC_NOCACHE) \ CXX=$(HOSTCXX_NOCACHE) \ @@ -299,15 +287,13 @@ define Host/Uninstall endef define Build/Compile - mkdir -p \ - $(PKG_GO_HOST_CACHE_DIR) \ - $(PKG_GO_TARGET_CACHE_DIR) + mkdir -p $(GO_BUILD_CACHE_DIR) @echo "Building target Go first stage" $(call GoCompiler/Package/Make, \ GOROOT_BOOTSTRAP=$(HOST_GO_ROOT) \ - GOCACHE=$(PKG_GO_HOST_CACHE_DIR) \ + GOCACHE=$(GO_BUILD_CACHE_DIR) \ GO_GCC_HELPER_CC="$(HOSTCC)" \ GO_GCC_HELPER_CXX="$(HOSTCXX)" \ GO_GCC_HELPER_PATH=$$$$PATH \ @@ -327,7 +313,7 @@ define Build/Compile export $(GO_PKG_TARGET_VARS) ; \ $(CP) go go-host ; \ GOROOT_FINAL=$(PKG_GO_ROOT) \ - GOCACHE=$(PKG_GO_TARGET_CACHE_DIR) \ + GOCACHE=$(GO_BUILD_CACHE_DIR) \ GOENV=off \ GO_GCC_HELPER_CC="$(TARGET_CC)" \ GO_GCC_HELPER_CXX="$(TARGET_CXX)" \ diff --git a/utils/ctop/Makefile b/utils/ctop/Makefile index aae82f010..85242dbe5 100644 --- a/utils/ctop/Makefile +++ b/utils/ctop/Makefile @@ -35,12 +35,11 @@ endef MAKE_PATH:=$(GO_PKG_WORK_DIR_NAME)/build/src/$(GO_PKG) MAKE_VARS += \ GOPATH=$(GO_PKG_BUILD_DIR) \ - GOCACHE=$(GO_PKG_CACHE_DIR) \ - GOTMPDIR=$(GO_PKG_TMP_DIR) \ + GOCACHE=$(GO_BUILD_CACHE_DIR) \ GOROOT_FINAL=$(GO_TARGET_ROOT) \ CC=$(TARGET_CC) \ CXX=$(TARGET_CXX) \ - $(call GoPackage/Environment) + $(GO_PKG_VARS) MAKE_FLAGS += \ COMMIT=$(PKG_SOURCE_VERSION) diff --git a/utils/docker-ce/Makefile b/utils/docker-ce/Makefile index 1f6c1ee79..fe072902e 100644 --- a/utils/docker-ce/Makefile +++ b/utils/docker-ce/Makefile @@ -77,8 +77,7 @@ define Build/Configure mkdir -p $(GO_PKG_BUILD_DIR)/bin \ $(GO_PKG_BUILD_DIR)/src \ $(GO_PKG_BUILD_DIR)/src/$(GO_PKG)/ \ - $(GO_PKG_CACHE_DIR) \ - $(GO_PKG_TMP_DIR) + $(GO_BUILD_CACHE_DIR) $(LN) $(PKG_BUILD_DIR)/cli $(GO_PKG_BUILD_DIR)/src/$(GO_PKG)/cli $(LN) $(PKG_BUILD_DIR)/engine $(GO_PKG_BUILD_DIR)/src/$(GO_PKG)/docker endef