Merge pull request #12165 from jefferyto/golang-tweaks
golang: Various improvements/tweaks
This commit is contained in:
commit
aee7061658
6 changed files with 125 additions and 77 deletions
|
@ -89,7 +89,12 @@ include $(GO_INCLUDE_DIR)/golang-values.mk
|
|||
#
|
||||
# Additional go tool link arguments to use when building targets.
|
||||
#
|
||||
# e.g. GO_PKG_LDFLAGS:=-s -w
|
||||
# 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
|
||||
|
@ -147,16 +152,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
|
||||
|
@ -165,7 +160,7 @@ define GoPackage/GoSubMenu
|
|||
CATEGORY:=Languages
|
||||
endef
|
||||
|
||||
define GoPackage/Environment/Target
|
||||
GO_PKG_TARGET_VARS= \
|
||||
GOOS=$(GO_OS) \
|
||||
GOARCH=$(GO_ARCH) \
|
||||
GO386=$(GO_386) \
|
||||
|
@ -179,20 +174,57 @@ define GoPackage/Environment/Target
|
|||
CGO_CPPFLAGS="$(TARGET_CPPFLAGS)" \
|
||||
CGO_CXXFLAGS="$(filter-out $(GO_CFLAGS_TO_REMOVE),$(TARGET_CXXFLAGS))" \
|
||||
CGO_LDFLAGS="$(TARGET_LDFLAGS)"
|
||||
endef
|
||||
|
||||
define GoPackage/Environment/Build
|
||||
GO_PKG_BUILD_VARS= \
|
||||
GOPATH=$(GO_PKG_BUILD_DIR) \
|
||||
GOCACHE=$(GO_PKG_CACHE_DIR) \
|
||||
GOENV=off
|
||||
endef
|
||||
|
||||
define GoPackage/Environment/Default
|
||||
$(call GoPackage/Environment/Target) \
|
||||
$(call GoPackage/Environment/Build)
|
||||
endef
|
||||
GO_PKG_DEFAULT_VARS= \
|
||||
$(GO_PKG_TARGET_VARS) \
|
||||
$(GO_PKG_BUILD_VARS)
|
||||
|
||||
GoPackage/Environment=$(call GoPackage/Environment/Default)
|
||||
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 \
|
||||
-extldflags '$(patsubst -z%,-Wl$(comma)-z$(comma)%,$(TARGET_LDFLAGS))'
|
||||
|
||||
GO_PKG_INSTALL_ARGS= \
|
||||
-v \
|
||||
-trimpath \
|
||||
-ldflags "all=$(GO_PKG_DEFAULT_LDFLAGS)"
|
||||
|
||||
ifeq ($(GO_PKG_ENABLE_PIE),1)
|
||||
GO_PKG_INSTALL_ARGS+= -buildmode pie
|
||||
endif
|
||||
|
||||
ifeq ($(GO_ARCH),arm)
|
||||
GO_PKG_INSTALL_ARGS+= -installsuffix "v$(GO_ARM)"
|
||||
|
||||
else ifneq ($(filter $(GO_ARCH),mips mipsle),)
|
||||
GO_PKG_INSTALL_ARGS+= -installsuffix "$(GO_MIPS)"
|
||||
|
||||
else ifneq ($(filter $(GO_ARCH),mips64 mips64le),)
|
||||
GO_PKG_INSTALL_ARGS+= -installsuffix "$(GO_MIPS64)"
|
||||
|
||||
endif
|
||||
|
||||
ifneq ($(strip $(GO_PKG_GCFLAGS)),)
|
||||
GO_PKG_INSTALL_ARGS+= -gcflags "$(GO_PKG_GCFLAGS)"
|
||||
endif
|
||||
|
||||
GO_PKG_CUSTOM_LDFLAGS= \
|
||||
$(GO_PKG_LDFLAGS) \
|
||||
$(patsubst %,-X %,$(GO_PKG_LDFLAGS_X))
|
||||
|
||||
ifneq ($(strip $(GO_PKG_CUSTOM_LDFLAGS)),)
|
||||
GO_PKG_INSTALL_ARGS+= -ldflags "$(GO_PKG_CUSTOM_LDFLAGS) $(GO_PKG_DEFAULT_LDFLAGS)"
|
||||
endif
|
||||
|
||||
# false if directory does not exist
|
||||
GoPackage/is_dir_not_empty=$$$$($(FIND) $(1) -maxdepth 0 -type d \! -empty 2>/dev/null)
|
||||
|
@ -278,7 +310,7 @@ endef
|
|||
define GoPackage/Build/Compile
|
||||
( \
|
||||
cd $(GO_PKG_BUILD_DIR) ; \
|
||||
export $(call GoPackage/Environment) ; \
|
||||
export $(GO_PKG_VARS) ; \
|
||||
\
|
||||
echo "Finding targets" ; \
|
||||
targets=$$$$(go list $(GO_PKG_BUILD_PKG)) ; \
|
||||
|
@ -295,27 +327,7 @@ define GoPackage/Build/Compile
|
|||
\
|
||||
if [ "$(strip $(GO_PKG_SOURCE_ONLY))" != 1 ]; then \
|
||||
echo "Building targets" ; \
|
||||
case $(GO_ARCH) in \
|
||||
arm) installsuffix="v$(GO_ARM)" ;; \
|
||||
mips|mipsle) installsuffix="$(GO_MIPS)" ;; \
|
||||
mips64|mips64le) installsuffix="$(GO_MIPS64)" ;; \
|
||||
esac ; \
|
||||
ldflags="-linkmode external -extldflags '$(TARGET_LDFLAGS:-z%=-Wl,-z,%)'" ; \
|
||||
pkg_gcflags="$(strip $(GO_PKG_GCFLAGS))" ; \
|
||||
pkg_ldflags="$(strip $(GO_PKG_LDFLAGS))" ; \
|
||||
for def in $(GO_PKG_LDFLAGS_X); do \
|
||||
pkg_ldflags="$$$$pkg_ldflags -X $$$$def" ; \
|
||||
done ; \
|
||||
go install \
|
||||
$(if $(GO_PKG_ENABLE_PIE),-buildmode pie) \
|
||||
$$$${installsuffix:+-installsuffix $$$$installsuffix} \
|
||||
-trimpath \
|
||||
-ldflags "all=$$$$ldflags" \
|
||||
-v \
|
||||
$$$${pkg_gcflags:+-gcflags "$$$$pkg_gcflags"} \
|
||||
$$$${pkg_ldflags:+-ldflags "$$$$pkg_ldflags $$$$ldflags"} \
|
||||
$(1) \
|
||||
$$$$targets ; \
|
||||
go install $(GO_PKG_INSTALL_ARGS) $(1) $$$$targets ; \
|
||||
retval=$$$$? ; \
|
||||
echo ; \
|
||||
\
|
||||
|
|
|
@ -156,32 +156,15 @@ ifeq ($(GO_ARCH),386)
|
|||
else ifeq ($(GO_ARCH),arm)
|
||||
GO_TARGET_FPU:=$(word 2,$(subst +,$(space),$(call qstrip,$(CONFIG_CPU_TYPE))))
|
||||
|
||||
# FPU names from https://gcc.gnu.org/onlinedocs/gcc-8.3.0/gcc/ARM-Options.html#index-mfpu-1
|
||||
# see also https://github.com/gcc-mirror/gcc/blob/gcc-8_3_0-release/gcc/config/arm/arm-cpus.in
|
||||
#
|
||||
# Assumptions:
|
||||
#
|
||||
# * -d16 variants (16 instead of 32 double-precision registers) acceptable
|
||||
# Go doesn't appear to check the HWCAP_VFPv3D16 flag in
|
||||
# https://github.com/golang/go/blob/release-branch.go1.13/src/runtime/os_linux_arm.go
|
||||
#
|
||||
# * Double-precision required
|
||||
# Based on no evidence(!)
|
||||
# Excludes vfpv3xd, vfpv3xd-fp16, fpv4-sp-d16, fpv5-sp-d16
|
||||
# FPU names from https://gcc.gnu.org/onlinedocs/gcc-8.4.0/gcc/ARM-Options.html#index-mfpu-1
|
||||
# see also https://github.com/gcc-mirror/gcc/blob/releases/gcc-8.4.0/gcc/config/arm/arm-cpus.in
|
||||
|
||||
GO_ARM_7_FPUS:= \
|
||||
vfpv3 vfpv3-fp16 vfpv3-d16 vfpv3-d16-fp16 neon neon-vfpv3 neon-fp16 \
|
||||
vfpv4 vfpv4-d16 neon-vfpv4 \
|
||||
fpv5-d16 fp-armv8 neon-fp-armv8 crypto-neon-fp-armv8
|
||||
|
||||
GO_ARM_6_FPUS:=vfp vfpv2
|
||||
|
||||
ifneq ($(filter $(GO_TARGET_FPU),$(GO_ARM_7_FPUS)),)
|
||||
GO_ARM:=7
|
||||
else ifneq ($(filter $(GO_TARGET_FPU),$(GO_ARM_6_FPUS)),)
|
||||
ifeq ($(GO_TARGET_FPU),)
|
||||
GO_ARM:=5
|
||||
else ifneq ($(filter $(GO_TARGET_FPU),vfp vfpv2),)
|
||||
GO_ARM:=6
|
||||
else
|
||||
GO_ARM:=5
|
||||
GO_ARM:=7
|
||||
endif
|
||||
|
||||
else ifneq ($(filter $(GO_ARCH),mips mipsle),)
|
||||
|
|
|
@ -12,7 +12,7 @@ GO_VERSION_PATCH:=2
|
|||
|
||||
PKG_NAME:=golang
|
||||
PKG_VERSION:=$(GO_VERSION_MAJOR_MINOR)$(if $(GO_VERSION_PATCH),.$(GO_VERSION_PATCH))
|
||||
PKG_RELEASE:=1
|
||||
PKG_RELEASE:=2
|
||||
|
||||
GO_SOURCE_URLS:=https://dl.google.com/go/ \
|
||||
https://mirrors.ustc.edu.cn/golang/ \
|
||||
|
@ -101,7 +101,7 @@ PKG_UNPACK:=$(HOST_TAR) -C $(PKG_BUILD_DIR) --strip-components=1 -xzf $(DL_DIR)/
|
|||
HOST_UNPACK:=$(HOST_TAR) -C $(HOST_BUILD_DIR) --strip-components=1 -xzf $(DL_DIR)/$(PKG_SOURCE)
|
||||
BOOTSTRAP_UNPACK:=$(HOST_TAR) -C $(BOOTSTRAP_BUILD_DIR) --strip-components=1 -xzf $(DL_DIR)/$(BOOTSTRAP_SOURCE)
|
||||
|
||||
# don't strip ELF executables in test data (and go itself)
|
||||
# don't strip ELF executables in test data
|
||||
RSTRIP:=:
|
||||
STRIP:=:
|
||||
|
||||
|
@ -154,6 +154,23 @@ This package provides an assembler, compiler, linker, and compiled
|
|||
libraries for the Go programming language.
|
||||
endef
|
||||
|
||||
define Package/golang/config
|
||||
menu "Configuration"
|
||||
|
||||
config GOLANG_EXTERNAL_BOOTSTRAP_ROOT
|
||||
string "External bootstrap Go root directory"
|
||||
help
|
||||
Path to a working Go tree (>= Go 1.4), with bin, pkg, and src
|
||||
subdirectories and the Go compiler at bin/go.
|
||||
|
||||
If specified, the existing Go installation will be used to
|
||||
compile host (buildroot) Go.
|
||||
|
||||
Leave blank to compile the default bootstrap Go.
|
||||
|
||||
endmenu
|
||||
endef
|
||||
|
||||
define Package/golang-doc
|
||||
$(call Package/golang/Default)
|
||||
TITLE+= (documentation)
|
||||
|
@ -177,22 +194,53 @@ This package provides the Go programming language source files needed
|
|||
for cross-compilation.
|
||||
endef
|
||||
|
||||
EXTERNAL_BOOTSTRAP_DIR:=$(call qstrip,$(CONFIG_GOLANG_EXTERNAL_BOOTSTRAP_ROOT))
|
||||
USE_DEFAULT_BOOTSTRAP:=$(if $(EXTERNAL_BOOTSTRAP_DIR),,1)
|
||||
|
||||
PKG_GO_ZBOOTSTRAP_MODS:= \
|
||||
s/defaultGO386 = `[^`]*`/defaultGO386 = `$(if $(GO_386),$(GO_386),387)`/; \
|
||||
s/defaultGOARM = `[^`]*`/defaultGOARM = `$(if $(GO_ARM),$(GO_ARM),5)`/; \
|
||||
s/defaultGOMIPS = `[^`]*`/defaultGOMIPS = `$(if $(GO_MIPS),$(GO_MIPS),hardfloat)`/; \
|
||||
s/defaultGOMIPS64 = `[^`]*`/defaultGOMIPS64 = `$(if $(GO_MIPS64),$(GO_MIPS64),hardfloat)`/; \
|
||||
s/defaultGOPPC64 = `[^`]*`/defaultGOPPC64 = `power8`/;
|
||||
|
||||
PKG_GO_LDFLAGS= \
|
||||
-buildid '$(SOURCE_DATE_EPOCH)'
|
||||
|
||||
ifeq ($(CONFIG_NO_STRIP)$(CONFIG_DEBUG),)
|
||||
PKG_GO_LDFLAGS+= -s -w
|
||||
endif
|
||||
|
||||
# setting -trimpath is not necessary here because the paths inside the
|
||||
# compiler binary are relative to GOROOT_FINAL (PKG_GO_ROOT), which is
|
||||
# static / not dependent on the build environment
|
||||
PKG_GO_INSTALL_ARGS= \
|
||||
-ldflags "all=$(PKG_GO_LDFLAGS)"
|
||||
|
||||
ifeq ($(PKG_GO_ENABLE_PIE),1)
|
||||
PKG_GO_INSTALL_ARGS+= -buildmode pie
|
||||
endif
|
||||
|
||||
define Download/golang-bootstrap
|
||||
FILE:=$(BOOTSTRAP_SOURCE)
|
||||
URL:=$(BOOTSTRAP_SOURCE_URL)
|
||||
HASH:=$(BOOTSTRAP_HASH)
|
||||
endef
|
||||
$(eval $(call Download,golang-bootstrap))
|
||||
|
||||
$(eval $(call GoCompiler/AddProfile,Bootstrap,$(BOOTSTRAP_BUILD_DIR),,bootstrap,$(GO_HOST_OS_ARCH)))
|
||||
$(eval $(call GoCompiler/AddProfile,Host,$(HOST_BUILD_DIR),$(HOST_GO_PREFIX),$(HOST_GO_VERSION_ID),$(GO_HOST_OS_ARCH),$(HOST_GO_INSTALL_SUFFIX)))
|
||||
$(eval $(call GoCompiler/AddProfile,Package,$(PKG_BUILD_DIR),$(PKG_GO_PREFIX),$(PKG_GO_VERSION_ID),$(GO_OS_ARCH),$(PKG_GO_INSTALL_SUFFIX)))
|
||||
|
||||
define Host/Prepare
|
||||
ifeq ($(USE_DEFAULT_BOOTSTRAP),1)
|
||||
$(eval $(call GoCompiler/AddProfile,Bootstrap,$(BOOTSTRAP_BUILD_DIR),,bootstrap,$(GO_HOST_OS_ARCH)))
|
||||
|
||||
$(eval $(call Download,golang-bootstrap))
|
||||
|
||||
define Host/Prepare
|
||||
$(call Host/Prepare/Default)
|
||||
mkdir -p $(BOOTSTRAP_BUILD_DIR)
|
||||
$(BOOTSTRAP_UNPACK)
|
||||
endef
|
||||
endef
|
||||
endif
|
||||
|
||||
# when https://github.com/golang/go/issues/31544 is fixed,
|
||||
# we should be able to set GO_LDFLAGS=-buildmode=pie for host make
|
||||
|
@ -212,7 +260,7 @@ define Host/Compile
|
|||
)
|
||||
|
||||
$(call GoCompiler/Host/Make, \
|
||||
GOROOT_BOOTSTRAP=$(BOOTSTRAP_BUILD_DIR) \
|
||||
GOROOT_BOOTSTRAP=$(if $(USE_DEFAULT_BOOTSTRAP),$(BOOTSTRAP_BUILD_DIR),$(EXTERNAL_BOOTSTRAP_DIR)) \
|
||||
GOCACHE=$(HOST_GO_CACHE_DIR) \
|
||||
CC=$(HOSTCC_NOCACHE) \
|
||||
CXX=$(HOSTCXX_NOCACHE) \
|
||||
|
@ -282,11 +330,16 @@ define Build/Compile
|
|||
PATH=$(HOST_GO_ROOT)/openwrt:$$$$PATH \
|
||||
)
|
||||
|
||||
ifneq ($(PKG_GO_ZBOOTSTRAP_MODS),)
|
||||
$(SED) '$(PKG_GO_ZBOOTSTRAP_MODS)' \
|
||||
$(PKG_BUILD_DIR)/src/cmd/internal/objabi/zbootstrap.go
|
||||
endif
|
||||
|
||||
@echo "Building target Go second stage"
|
||||
|
||||
( \
|
||||
cd $(PKG_BUILD_DIR)/bin ; \
|
||||
export $(call GoPackage/Environment/Target) ; \
|
||||
export $(GO_PKG_TARGET_VARS) ; \
|
||||
$(CP) go go-host ; \
|
||||
GOROOT_FINAL=$(PKG_GO_ROOT) \
|
||||
GOCACHE=$(PKG_GO_TARGET_CACHE_DIR) \
|
||||
|
@ -298,7 +351,7 @@ define Build/Compile
|
|||
CXX=g++ \
|
||||
PKG_CONFIG=pkg-config \
|
||||
PATH=$(HOST_GO_ROOT)/openwrt:$$$$PATH \
|
||||
./go-host install -a $(if $(PKG_GO_ENABLE_PIE),-buildmode=pie) std cmd ; \
|
||||
./go-host install -a $(PKG_GO_INSTALL_ARGS) std cmd ; \
|
||||
retval=$$$$? ; \
|
||||
rm -f go-host ; \
|
||||
exit $$$$retval ; \
|
||||
|
|
|
@ -49,7 +49,7 @@ endef
|
|||
|
||||
GO_PKG_INSTALL_ALL:=1
|
||||
MAKE_PATH:=$(GO_PKG_WORK_DIR_NAME)/build/src/$(GO_PKG)
|
||||
MAKE_VARS += $(call GoPackage/Environment)
|
||||
MAKE_VARS += $(GO_PKG_VARS)
|
||||
MAKE_FLAGS += \
|
||||
DESTDIR="$(PKG_INSTALL_DIR)" \
|
||||
VERSION=$(PKG_VERSION) \
|
||||
|
|
|
@ -78,7 +78,7 @@ endif
|
|||
|
||||
define Build/Compile
|
||||
( \
|
||||
export $(call GoPackage/Environment) \
|
||||
export $(GO_PKG_VARS) \
|
||||
GITCOMMIT=$(PKG_SOURCE_VERSION) \
|
||||
DOCKER_GITCOMMIT=$(PKG_SOURCE_VERSION) \
|
||||
DOCKER_BUILDTAGS='$(BUILDTAGS)' \
|
||||
|
|
|
@ -49,7 +49,7 @@ endef
|
|||
|
||||
GO_PKG_INSTALL_ALL:=1
|
||||
MAKE_PATH:=$(GO_PKG_WORK_DIR_NAME)/build/src/$(GO_PKG)
|
||||
MAKE_VARS += $(call GoPackage/Environment)
|
||||
MAKE_VARS += $(GO_PKG_VARS)
|
||||
MAKE_FLAGS += \
|
||||
COMMIT=$(PKG_SOURCE_VERSION)
|
||||
|
||||
|
|
Loading…
Reference in a new issue