1
0
Fork 0
mirror of https://github.com/Ysurac/openmptcprouter-feeds.git synced 2025-03-09 15:40:03 +00:00

Update golang

This commit is contained in:
Ycarus (Yannick Chabanois) 2020-10-09 13:15:13 +02:00
parent 66c06647c9
commit e0f08f96f5
9 changed files with 1061 additions and 328 deletions

View file

@ -1,5 +1,5 @@
#
# Copyright (C) 2018 Jeffery To
# Copyright (C) 2018-2020 Jeffery To
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
@ -28,10 +28,12 @@ include $(GO_INCLUDE_DIR)/golang-values.mk
# files are installed:
#
# * Files with one of these extensions:
# .go, .c, .cc, .h, .hh, .proto, .s
# .go, .c, .cc, .cpp, .h, .hh, .hpp, .proto, .s
#
# * Files in any 'testdata' directory
#
# * go.mod and go.sum, in any directory
#
# e.g. GO_PKG_INSTALL_EXTRA:=example.toml marshal_test.toml
#
#
@ -54,7 +56,7 @@ include $(GO_INCLUDE_DIR)/golang-values.mk
# GO_PKG_BUILD_PKG - list of build targets, default GO_PKG/...
#
# Build targets for compiling this Go package, i.e. arguments passed
# to 'go install'
# to 'go install'.
#
# e.g. GO_PKG_BUILD_PKG:=github.com/debian/ratt/cmd/...
#
@ -74,28 +76,92 @@ include $(GO_INCLUDE_DIR)/golang-values.mk
# not necessary.
#
# e.g. GO_PKG_GO_GENERATE:=1
#
#
# GO_PKG_GCFLAGS - list of options, default empty
#
# Additional go tool compile options to use when building targets.
#
# e.g. GO_PKG_GCFLAGS:=-N -l
#
#
# GO_PKG_LDFLAGS - list of options, default empty
#
# Additional go tool link options to use when building targets.
#
# Note that the OpenWrt build system has an option to strip binaries
# (enabled by default), so -s (Omit the symbol table and debug
# information) and -w (Omit the DWARF symbol table) flags are not
# necessary.
#
# e.g. GO_PKG_LDFLAGS:=-r dir1:dir2 -u
#
#
# GO_PKG_LDFLAGS_X - list of string variable definitions, default empty
#
# Each definition will be passed as the parameter to the -X go tool
# link option, i.e. -ldflags "-X importpath.name=value".
#
# e.g. GO_PKG_LDFLAGS_X:=main.Version=$(PKG_VERSION) main.BuildStamp=$(SOURCE_DATE_EPOCH)
#
#
# GO_PKG_TAGS - list of build tags, default empty
#
# Build tags to consider satisfied during the build, passed as the
# parameter to the -tags option for 'go install'.
#
# e.g. GO_PKG_TAGS:=release,noupgrade
#
#
# GO_PKG_INSTALL_BIN_PATH - target directory path, default /usr/bin
#
# Directory path under "dest_dir" where binaries will be installed by
# '$(call GoPackage/Package/Install/Bin,dest_dir)'.
#
# e.g. GO_PKG_INSTALL_BIN_PATH:=/sbin
# Credit for this package build process (GoPackage/Build/Configure and
# GoPackage/Build/Compile) belong to Debian's dh-golang completely.
# https://anonscm.debian.org/cgit/pkg-go/packages/dh-golang.git
# https://salsa.debian.org/go-team/packages/dh-golang
# for building packages, not user code
GO_PKG_PATH:=/usr/share/gocode
GO_PKG_BUILD_PKG?=$(GO_PKG)/...
GO_PKG_BUILD_PKG?=$(strip $(GO_PKG))/...
GO_PKG_INSTALL_BIN_PATH?=/usr/bin
GO_PKG_WORK_DIR_NAME:=.go_work
GO_PKG_WORK_DIR:=$(PKG_BUILD_DIR)/$(GO_PKG_WORK_DIR_NAME)
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_DIR:=$(GO_PKG_WORK_DIR)/build
GO_PKG_CACHE_DIR:=$(GO_PKG_WORK_DIR)/cache
GO_PKG_TMP_DIR:=$(GO_PKG_WORK_DIR)/tmp
GO_PKG_BUILD_DEPENDS_PATH:=/usr/share/gocode
GO_PKG_BUILD_DEPENDS_SRC=$(STAGING_DIR)$(GO_PKG_BUILD_DEPENDS_PATH)/src
GO_PKG_BUILD_BIN_DIR:=$(GO_PKG_BUILD_DIR)/bin$(if \
$(GO_HOST_TARGET_DIFFERENT),/$(GO_OS)_$(GO_ARCH))
ifdef CONFIG_PKG_ASLR_PIE_ALL
ifeq ($(strip $(PKG_ASLR_PIE)),1)
ifeq ($(GO_TARGET_PIE_SUPPORTED),1)
GO_PKG_ENABLE_PIE:=1
else
$(warning PIE buildmode is not supported for $(GO_OS)/$(GO_ARCH))
endif
endif
endif
GO_PKG_BUILD_DEPENDS_SRC:=$(STAGING_DIR)$(GO_PKG_PATH)/src
ifdef CONFIG_PKG_ASLR_PIE_REGULAR
ifeq ($(strip $(PKG_ASLR_PIE_REGULAR)),1)
ifeq ($(GO_TARGET_PIE_SUPPORTED),1)
GO_PKG_ENABLE_PIE:=1
else
$(warning PIE buildmode is not supported for $(GO_OS)/$(GO_ARCH))
endif
endif
endif
ifdef CONFIG_GOLANG_SPECTRE
ifeq ($(GO_TARGET_SPECTRE_SUPPORTED),1)
GO_PKG_ENABLE_SPECTRE:=1
else
$(warning Spectre mitigations are not supported for $(GO_ARCH))
endif
endif
# sstrip causes corrupted section header size
ifneq ($(CONFIG_USE_SSTRIP),)
@ -105,16 +171,6 @@ ifneq ($(CONFIG_USE_SSTRIP),)
GO_PKG_STRIP_ARGS:=--strip-all
endif
STRIP:=$(TARGET_CROSS)strip $(GO_PKG_STRIP_ARGS)
RSTRIP= \
export CROSS="$(TARGET_CROSS)" \
$(if $(PKG_BUILD_ID),KEEP_BUILD_ID=1) \
$(if $(CONFIG_KERNEL_KALLSYMS),NO_RENAME=1) \
$(if $(CONFIG_KERNEL_PROFILING),KEEP_SYMBOLS=1); \
NM="$(TARGET_CROSS)nm" \
STRIP="$(STRIP)" \
STRIP_KMOD="$(SCRIPT_DIR)/strip-kmod.sh" \
PATCHELF="$(STAGING_DIR_HOST)/bin/patchelf" \
$(SCRIPT_DIR)/rstrip.sh
endif
define GoPackage/GoSubMenu
@ -123,151 +179,87 @@ define GoPackage/GoSubMenu
CATEGORY:=Languages
endef
define GoPackage/Environment
GOOS=$(GO_OS) \
GOARCH=$(GO_ARCH) \
GO386=$(GO_386) \
GOARM=$(GO_ARM) \
GOMIPS=$(GO_MIPS) \
GOMIPS64=$(GO_MIPS64) \
GO_PKG_BUILD_CONFIG_VARS= \
GO_PKG="$(strip $(GO_PKG))" \
GO_INSTALL_EXTRA="$(strip $(GO_PKG_INSTALL_EXTRA))" \
GO_INSTALL_ALL="$(strip $(GO_PKG_INSTALL_ALL))" \
GO_SOURCE_ONLY="$(strip $(GO_PKG_SOURCE_ONLY))" \
GO_BUILD_PKG="$(strip $(GO_PKG_BUILD_PKG))" \
GO_EXCLUDES="$(strip $(GO_PKG_EXCLUDES))" \
GO_GO_GENERATE="$(strip $(GO_PKG_GO_GENERATE))" \
GO_INSTALL_BIN_PATH="$(strip $(GO_PKG_INSTALL_BIN_PATH))" \
BUILD_DIR="$(PKG_BUILD_DIR)" \
GO_BUILD_DIR="$(GO_PKG_BUILD_DIR)" \
GO_BUILD_BIN_DIR="$(GO_PKG_BUILD_BIN_DIR)" \
GO_BUILD_DEPENDS_PATH="$(GO_PKG_BUILD_DEPENDS_PATH)" \
GO_BUILD_DEPENDS_SRC="$(GO_PKG_BUILD_DEPENDS_SRC)"
GO_PKG_TARGET_VARS= \
GOOS="$(GO_OS)" \
GOARCH="$(GO_ARCH)" \
GO386="$(GO_386)" \
GOARM="$(GO_ARM)" \
GOMIPS="$(GO_MIPS)" \
GOMIPS64="$(GO_MIPS64)" \
CGO_ENABLED=1 \
CC="$(TARGET_CC)" \
CXX="$(TARGET_CXX)" \
CGO_CFLAGS="$(filter-out $(GO_CFLAGS_TO_REMOVE),$(TARGET_CFLAGS))" \
CGO_CPPFLAGS="$(TARGET_CPPFLAGS)" \
CGO_CXXFLAGS="$(filter-out $(GO_CFLAGS_TO_REMOVE),$(TARGET_CXXFLAGS))"
endef
CGO_CXXFLAGS="$(filter-out $(GO_CFLAGS_TO_REMOVE),$(TARGET_CXXFLAGS))" \
CGO_LDFLAGS="$(TARGET_LDFLAGS)"
# false if directory does not exist
GoPackage/is_dir_not_empty=$$$$($(FIND) $(1) -maxdepth 0 -type d \! -empty 2>/dev/null)
GO_PKG_BUILD_VARS= \
GOPATH="$(GO_PKG_BUILD_DIR)" \
GOCACHE="$(GO_BUILD_CACHE_DIR)" \
GOMODCACHE="$(GO_MOD_CACHE_DIR)" \
GOENV=off
GoPackage/has_binaries=$(call GoPackage/is_dir_not_empty,$(GO_PKG_BUILD_BIN_DIR))
GO_PKG_VARS= \
$(GO_PKG_TARGET_VARS) \
$(GO_PKG_BUILD_VARS)
GO_PKG_DEFAULT_GCFLAGS= \
$(if $(GO_PKG_ENABLE_SPECTRE),-spectre all)
GO_PKG_DEFAULT_ASMFLAGS= \
$(if $(GO_PKG_ENABLE_SPECTRE),-spectre all)
GO_PKG_DEFAULT_LDFLAGS= \
-buildid '$(SOURCE_DATE_EPOCH)' \
-linkmode external \
-extldflags '$(patsubst -z%,-Wl$(comma)-z$(comma)%,$(TARGET_LDFLAGS))'
GO_PKG_CUSTOM_LDFLAGS= \
$(GO_PKG_LDFLAGS) \
$(patsubst %,-X %,$(GO_PKG_LDFLAGS_X))
GO_PKG_INSTALL_ARGS= \
-v \
-trimpath \
-ldflags "all=$(GO_PKG_DEFAULT_LDFLAGS)" \
$(if $(GO_PKG_DEFAULT_GCFLAGS),-gcflags "all=$(GO_PKG_DEFAULT_GCFLAGS)") \
$(if $(GO_PKG_DEFAULT_ASMFLAGS),-asmflags "all=$(GO_PKG_DEFAULT_ASMFLAGS)") \
$(if $(filter $(GO_PKG_ENABLE_PIE),1),-buildmode pie) \
$(if $(filter $(GO_ARCH),arm),-installsuffix "v$(GO_ARM)") \
$(if $(filter $(GO_ARCH),mips mipsle),-installsuffix "$(GO_MIPS)") \
$(if $(filter $(GO_ARCH),mips64 mips64le),-installsuffix "$(GO_MIPS64)") \
$(if $(GO_PKG_GCFLAGS),-gcflags "$(GO_PKG_GCFLAGS) $(GO_PKG_DEFAULT_GCFLAGS)") \
$(if $(GO_PKG_CUSTOM_LDFLAGS),-ldflags "$(GO_PKG_CUSTOM_LDFLAGS) $(GO_PKG_DEFAULT_LDFLAGS)") \
$(if $(GO_PKG_TAGS),-tags "$(GO_PKG_TAGS)")
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_PKG_TMP_DIR) ; \
\
files=$$$$($(FIND) ./ \
-type d -a \( -path './.git' -o -path './$(GO_PKG_WORK_DIR_NAME)' \) -prune -o \
\! -type d -print | \
sed 's|^\./||') ; \
\
if [ "$(GO_PKG_INSTALL_ALL)" != 1 ]; then \
code=$$$$(echo "$$$$files" | grep '\.\(c\|cc\|go\|h\|hh\|proto\|s\)$$$$') ; \
testdata=$$$$(echo "$$$$files" | grep '\(^\|/\)testdata/') ; \
\
for pattern in $(GO_PKG_INSTALL_EXTRA); do \
extra=$$$$(echo "$$$$extra"; echo "$$$$files" | grep "$$$$pattern") ; \
done ; \
\
files=$$$$(echo "$$$$code"; echo "$$$$testdata"; echo "$$$$extra") ; \
files=$$$$(echo "$$$$files" | grep -v '^[[:space:]]*$$$$' | sort -u) ; \
fi ; \
\
echo "Copying files from $(PKG_BUILD_DIR) into $(GO_PKG_BUILD_DIR)/src/$(GO_PKG)" ; \
for file in $$$$files; do \
echo $$$$file ; \
dest=$(GO_PKG_BUILD_DIR)/src/$(GO_PKG)/$$$$file ; \
mkdir -p $$$$(dirname $$$$dest) ; \
$(CP) $$$$file $$$$dest ; \
done ; \
echo ; \
\
link_contents() { \
local src=$$$$1 ; \
local dest=$$$$2 ; \
local dirs dir base ; \
\
if [ -n "$$$$($(FIND) $$$$src -mindepth 1 -maxdepth 1 -name '*.go' \! -type d)" ]; then \
echo "$$$$src is already a Go library" ; \
return 1 ; \
fi ; \
\
dirs=$$$$($(FIND) $$$$src -mindepth 1 -maxdepth 1 -type d) ; \
for dir in $$$$dirs; do \
base=$$$$(basename $$$$dir) ; \
if [ -d $$$$dest/$$$$base ]; then \
case $$$$dir in \
*$(GO_PKG_PATH)/src/$(GO_PKG)) \
echo "$(GO_PKG) is already installed. Please check for circular dependencies." ;; \
*) \
link_contents $$$$src/$$$$base $$$$dest/$$$$base ;; \
esac ; \
else \
echo "...$$$${src#$(GO_PKG_BUILD_DEPENDS_SRC)}/$$$$base" ; \
$(LN) $$$$src/$$$$base $$$$dest/$$$$base ; \
fi ; \
done ; \
} ; \
\
if [ "$(GO_PKG_SOURCE_ONLY)" != 1 ]; then \
if [ -d $(GO_PKG_BUILD_DEPENDS_SRC) ]; then \
echo "Symlinking directories from $(GO_PKG_BUILD_DEPENDS_SRC) into $(GO_PKG_BUILD_DIR)/src" ; \
link_contents $(GO_PKG_BUILD_DEPENDS_SRC) $(GO_PKG_BUILD_DIR)/src ; \
else \
echo "$(GO_PKG_BUILD_DEPENDS_SRC) does not exist, skipping symlinks" ; \
fi ; \
else \
echo "Not building binaries, skipping symlinks" ; \
fi ; \
echo ; \
)
$(GO_GENERAL_BUILD_CONFIG_VARS) \
$(GO_PKG_BUILD_CONFIG_VARS) \
$(SHELL) $(GO_INCLUDE_DIR)/golang-build.sh configure
endef
# $(1) additional arguments for go command line (optional)
define GoPackage/Build/Compile
( \
cd $(GO_PKG_BUILD_DIR) ; \
export GOPATH=$(GO_PKG_BUILD_DIR) \
GOCACHE=$(GO_PKG_CACHE_DIR) \
GOTMPDIR=$(GO_PKG_TMP_DIR) \
GOROOT_FINAL=$(GO_TARGET_ROOT) \
CC=$(TARGET_CC) \
CXX=$(TARGET_CXX) \
$(call GoPackage/Environment) ; \
\
echo "Finding targets" ; \
targets=$$$$(go list $(GO_PKG_BUILD_PKG)) ; \
for pattern in $(GO_PKG_EXCLUDES); do \
targets=$$$$(echo "$$$$targets" | grep -v "$$$$pattern") ; \
done ; \
echo ; \
\
if [ "$(GO_PKG_GO_GENERATE)" = 1 ]; then \
echo "Calling go generate" ; \
go generate -v $(1) $$$$targets ; \
echo ; \
fi ; \
\
if [ "$(GO_PKG_SOURCE_ONLY)" != 1 ]; then \
echo "Building targets" ; \
case $(GO_ARCH) in \
arm) installsuffix="-installsuffix v$(GO_ARM)" ;; \
mips|mipsle) installsuffix="-installsuffix $(GO_MIPS)" ;; \
mips64|mips64le) installsuffix="-installsuffix $(GO_MIPS64)" ;; \
esac ; \
ldflags="all=-linkmode external -extldflags '$(TARGET_LDFLAGS)'" ; \
go install \
$$$$installsuffix \
-trimpath \
-ldflags "$$$$ldflags" \
-v \
$(1) \
$$$$targets ; \
retval=$$$$? ; \
echo ; \
\
if [ "$$$$retval" -eq 0 ] && [ -z "$(call GoPackage/has_binaries)" ]; then \
echo "No binaries were generated, consider adding GO_PKG_SOURCE_ONLY:=1 to Makefile" ; \
echo ; \
fi ; \
\
echo "Cleaning module download cache (golang/go#27455)" ; \
go clean -modcache ; \
echo ; \
fi ; \
exit $$$$retval ; \
)
$(GO_GENERAL_BUILD_CONFIG_VARS) \
$(GO_PKG_BUILD_CONFIG_VARS) \
$(GO_PKG_VARS) \
$(SHELL) $(GO_INCLUDE_DIR)/golang-build.sh build $(GO_PKG_INSTALL_ARGS) $(1)
endef
define GoPackage/Build/InstallDev
@ -275,27 +267,33 @@ define GoPackage/Build/InstallDev
endef
define GoPackage/Package/Install/Bin
if [ -n "$(call GoPackage/has_binaries)" ]; then \
$(INSTALL_DIR) $(1)/usr/bin ; \
$(INSTALL_BIN) $(GO_PKG_BUILD_BIN_DIR)/* $(1)/usr/bin/ ; \
fi
$(GO_GENERAL_BUILD_CONFIG_VARS) \
$(GO_PKG_BUILD_CONFIG_VARS) \
$(SHELL) $(GO_INCLUDE_DIR)/golang-build.sh install_bin "$(1)"
endef
define GoPackage/Package/Install/Src
dir=$$$$(dirname $(GO_PKG)) ; \
$(INSTALL_DIR) $(1)$(GO_PKG_PATH)/src/$$$$dir ; \
$(CP) $(GO_PKG_BUILD_DIR)/src/$(GO_PKG) $(1)$(GO_PKG_PATH)/src/$$$$dir/
$(GO_GENERAL_BUILD_CONFIG_VARS) \
$(GO_PKG_BUILD_CONFIG_VARS) \
$(SHELL) $(GO_INCLUDE_DIR)/golang-build.sh install_src "$(1)"
endef
define GoPackage/Package/Install
$(call GoPackage/Package/Install/Bin,$(1))
$(if $(filter $(GO_PKG_SOURCE_ONLY),1),, \
$(call GoPackage/Package/Install/Bin,$(1)) \
)
$(call GoPackage/Package/Install/Src,$(1))
endef
ifneq ($(GO_PKG),)
ifneq ($(strip $(GO_PKG)),)
ifeq ($(GO_TARGET_SPECTRE_SUPPORTED),1)
PKG_CONFIG_DEPENDS+=CONFIG_GOLANG_SPECTRE
endif
Build/Configure=$(call GoPackage/Build/Configure)
Build/Compile=$(call GoPackage/Build/Compile)
Hooks/Compile/Post+=Go/CacheCleanup
Build/InstallDev=$(call GoPackage/Build/InstallDev,$(1))
endif
@ -316,3 +314,14 @@ 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_PATH=$(GO_PKG_BUILD_DEPENDS_PATH)
GO_PKG_WORK_DIR=$(PKG_BUILD_DIR)/$(GO_PKG_WORK_DIR_NAME)
GO_PKG_CACHE_DIR=$(GO_BUILD_CACHE_DIR)
GO_PKG_DEFAULT_VARS=$(GO_PKG_VARS)
GoPackage/Environment=$(GO_PKG_VARS)
GoPackage/is_dir_not_empty=$$$$($(FIND) "$(1)" -maxdepth 0 -type d \! -empty 2>/dev/null)
GoPackage/has_binaries=$(call GoPackage/is_dir_not_empty,$(GO_PKG_BUILD_BIN_DIR))
# End of deprecated variables