Browse Source

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 <jeffery.to@gmail.com>
lilik-openwrt-22.03
Jeffery To 4 years ago
parent
commit
9074dbd917
No known key found for this signature in database GPG Key ID: C616D9E719E868E4
6 changed files with 29 additions and 35 deletions
  1. +12
    -10
      lang/golang/golang-package.mk
  2. +1
    -0
      lang/golang/golang-values.mk
  3. +7
    -0
      lang/golang/golang/Config.in
  4. +6
    -20
      lang/golang/golang/Makefile
  5. +2
    -3
      utils/ctop/Makefile
  6. +1
    -2
      utils/docker-ce/Makefile

+ 12
- 10
lang/golang/golang-package.mk View File

@ -123,11 +123,7 @@ GO_PKG_PATH:=/usr/share/gocode
GO_PKG_BUILD_PKG?=$(strip $(GO_PKG))/... GO_PKG_BUILD_PKG?=$(strip $(GO_PKG))/...
GO_PKG_WORK_DIR_NAME:=.go_work 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_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 GO_PKG_BUILD_DEPENDS_SRC=$(STAGING_DIR)$(GO_PKG_PATH)/src
@ -185,7 +181,7 @@ GO_PKG_TARGET_VARS= \
GO_PKG_BUILD_VARS= \ GO_PKG_BUILD_VARS= \
GOPATH=$(GO_PKG_BUILD_DIR) \ GOPATH=$(GO_PKG_BUILD_DIR) \
GOCACHE=$(GO_PKG_CACHE_DIR) \
GOCACHE=$(GO_BUILD_CACHE_DIR) \
GOMODCACHE=$(GO_MOD_CACHE_DIR) \ GOMODCACHE=$(GO_MOD_CACHE_DIR) \
GOENV=off GOENV=off
@ -195,9 +191,6 @@ GO_PKG_DEFAULT_VARS= \
GO_PKG_VARS=$(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= \ GO_PKG_DEFAULT_LDFLAGS= \
-buildid '$(SOURCE_DATE_EPOCH)' \ -buildid '$(SOURCE_DATE_EPOCH)' \
-linkmode external \ -linkmode external \
@ -227,7 +220,9 @@ GoPackage/has_binaries=$(call GoPackage/is_dir_not_empty,$(GO_PKG_BUILD_BIN_DIR)
define GoPackage/Build/Configure define GoPackage/Build/Configure
( \ ( \
cd $(PKG_BUILD_DIR) ; \ 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) ./ \ files=$$$$($(FIND) ./ \
-type d -a \( -path './.git' -o -path './$(GO_PKG_WORK_DIR_NAME)' \) -prune -o \ -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)) Package/$(1)/install=$$(call GoPackage/Package/Install/Src,$$(1))
endif endif
endef 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

+ 1
- 0
lang/golang/golang-values.mk View File

@ -223,6 +223,7 @@ endif
# General build info # 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_CACHE_DIR:=$(DL_DIR)/go-mod-cache
GO_MOD_ARGS= \ GO_MOD_ARGS= \


+ 7
- 0
lang/golang/golang/Config.in View File

@ -12,6 +12,13 @@ config GOLANG_EXTERNAL_BOOTSTRAP_ROOT
Leave blank to compile the default bootstrap Go. 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 config GOLANG_MOD_CACHE_WORLD_READABLE
bool "Ensure Go module cache is world-readable" bool "Ensure Go module cache is world-readable"
default n default n


+ 6
- 20
lang/golang/golang/Makefile View File

@ -32,10 +32,6 @@ PKG_BUILD_DIR:=$(BUILD_DIR)/go-$(PKG_VERSION)
PKG_BUILD_PARALLEL:=1 PKG_BUILD_PARALLEL:=1
PKG_USE_MIPS16:=0 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_PREFIX:=/usr
PKG_GO_VERSION_ID:=$(GO_VERSION_MAJOR_MINOR) PKG_GO_VERSION_ID:=$(GO_VERSION_MAJOR_MINOR)
PKG_GO_ROOT:=$(PKG_GO_PREFIX)/lib/go-$(PKG_GO_VERSION_ID) 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_DIR:=$(BUILD_DIR_HOST)/go-$(PKG_VERSION)
HOST_BUILD_PARALLEL:=1 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_PREFIX:=$(STAGING_DIR_HOSTPKG)
HOST_GO_VERSION_ID:=cross HOST_GO_VERSION_ID:=cross
HOST_GO_ROOT:=$(HOST_GO_PREFIX)/lib/go-$(HOST_GO_VERSION_ID) 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_HASH:=f4ff5b5eb3a3cae1c993723f3eab519c5bae18866b5e5f96fe1102f0cb5c3e52
BOOTSTRAP_BUILD_DIR:=$(HOST_BUILD_DIR)/.go_bootstrap 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:= \ BOOTSTRAP_GO_VALID_OS_ARCH:= \
darwin_386 darwin_amd64 \ darwin_386 darwin_amd64 \
@ -236,19 +227,16 @@ define Host/Compile
$(call GoCompiler/Bootstrap/CheckHost,$(BOOTSTRAP_GO_VALID_OS_ARCH)) $(call GoCompiler/Bootstrap/CheckHost,$(BOOTSTRAP_GO_VALID_OS_ARCH))
$(call GoCompiler/Host/CheckHost,$(HOST_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, \ $(call GoCompiler/Bootstrap/Make, \
GOCACHE=$(BOOTSTRAP_CACHE_DIR) \
CC=$(HOSTCC_NOCACHE) \ CC=$(HOSTCC_NOCACHE) \
CXX=$(HOSTCXX_NOCACHE) \ CXX=$(HOSTCXX_NOCACHE) \
) )
$(call GoCompiler/Host/Make, \ $(call GoCompiler/Host/Make, \
GOROOT_BOOTSTRAP=$(if $(USE_DEFAULT_BOOTSTRAP),$(BOOTSTRAP_BUILD_DIR),$(EXTERNAL_BOOTSTRAP_DIR)) \ 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) \ CC=$(HOSTCC_NOCACHE) \
CXX=$(HOSTCXX_NOCACHE) \ CXX=$(HOSTCXX_NOCACHE) \
) )
@ -259,7 +247,7 @@ define Host/Compile
( \ ( \
cd $(HOST_BUILD_DIR)/bin ; \ cd $(HOST_BUILD_DIR)/bin ; \
$(CP) go go-nopie ; \ $(CP) go go-nopie ; \
GOCACHE=$(HOST_GO_CACHE_DIR) \
GOCACHE=$(GO_BUILD_CACHE_DIR) \
GOENV=off \ GOENV=off \
CC=$(HOSTCC_NOCACHE) \ CC=$(HOSTCC_NOCACHE) \
CXX=$(HOSTCXX_NOCACHE) \ CXX=$(HOSTCXX_NOCACHE) \
@ -299,15 +287,13 @@ define Host/Uninstall
endef endef
define Build/Compile 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" @echo "Building target Go first stage"
$(call GoCompiler/Package/Make, \ $(call GoCompiler/Package/Make, \
GOROOT_BOOTSTRAP=$(HOST_GO_ROOT) \ GOROOT_BOOTSTRAP=$(HOST_GO_ROOT) \
GOCACHE=$(PKG_GO_HOST_CACHE_DIR) \
GOCACHE=$(GO_BUILD_CACHE_DIR) \
GO_GCC_HELPER_CC="$(HOSTCC)" \ GO_GCC_HELPER_CC="$(HOSTCC)" \
GO_GCC_HELPER_CXX="$(HOSTCXX)" \ GO_GCC_HELPER_CXX="$(HOSTCXX)" \
GO_GCC_HELPER_PATH=$$$$PATH \ GO_GCC_HELPER_PATH=$$$$PATH \
@ -327,7 +313,7 @@ define Build/Compile
export $(GO_PKG_TARGET_VARS) ; \ export $(GO_PKG_TARGET_VARS) ; \
$(CP) go go-host ; \ $(CP) go go-host ; \
GOROOT_FINAL=$(PKG_GO_ROOT) \ GOROOT_FINAL=$(PKG_GO_ROOT) \
GOCACHE=$(PKG_GO_TARGET_CACHE_DIR) \
GOCACHE=$(GO_BUILD_CACHE_DIR) \
GOENV=off \ GOENV=off \
GO_GCC_HELPER_CC="$(TARGET_CC)" \ GO_GCC_HELPER_CC="$(TARGET_CC)" \
GO_GCC_HELPER_CXX="$(TARGET_CXX)" \ GO_GCC_HELPER_CXX="$(TARGET_CXX)" \


+ 2
- 3
utils/ctop/Makefile View File

@ -35,12 +35,11 @@ endef
MAKE_PATH:=$(GO_PKG_WORK_DIR_NAME)/build/src/$(GO_PKG) MAKE_PATH:=$(GO_PKG_WORK_DIR_NAME)/build/src/$(GO_PKG)
MAKE_VARS += \ MAKE_VARS += \
GOPATH=$(GO_PKG_BUILD_DIR) \ 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) \ GOROOT_FINAL=$(GO_TARGET_ROOT) \
CC=$(TARGET_CC) \ CC=$(TARGET_CC) \
CXX=$(TARGET_CXX) \ CXX=$(TARGET_CXX) \
$(call GoPackage/Environment)
$(GO_PKG_VARS)
MAKE_FLAGS += \ MAKE_FLAGS += \
COMMIT=$(PKG_SOURCE_VERSION) COMMIT=$(PKG_SOURCE_VERSION)


+ 1
- 2
utils/docker-ce/Makefile View File

@ -77,8 +77,7 @@ define Build/Configure
mkdir -p $(GO_PKG_BUILD_DIR)/bin \ mkdir -p $(GO_PKG_BUILD_DIR)/bin \
$(GO_PKG_BUILD_DIR)/src \ $(GO_PKG_BUILD_DIR)/src \
$(GO_PKG_BUILD_DIR)/src/$(GO_PKG)/ \ $(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)/cli $(GO_PKG_BUILD_DIR)/src/$(GO_PKG)/cli
$(LN) $(PKG_BUILD_DIR)/engine $(GO_PKG_BUILD_DIR)/src/$(GO_PKG)/docker $(LN) $(PKG_BUILD_DIR)/engine $(GO_PKG_BUILD_DIR)/src/$(GO_PKG)/docker
endef endef


Loading…
Cancel
Save