aboutsummaryrefslogtreecommitdiff
path: root/lang/golang
diff options
context:
space:
mode:
authorJeffery To <jeffery.to@gmail.com>2020-05-13 16:02:09 +0800
committerJeffery To <jeffery.to@gmail.com>2020-05-13 16:07:27 +0800
commit46017682f43817144e4f4294d50b3bb7172cd1be (patch)
treea27b0e2a3f69e6b2674cf09d751728b8c63bdc5e /lang/golang
parent74b02ca24c3e422f58a3eb59f31c5ec72455d3c4 (diff)
golang: Set buildid and enable stripping for Go compiler
Doing both should make the compiler reproducible. Signed-off-by: Jeffery To <jeffery.to@gmail.com>
Diffstat (limited to 'lang/golang')
-rw-r--r--lang/golang/golang/Makefile23
1 files changed, 20 insertions, 3 deletions
diff --git a/lang/golang/golang/Makefile b/lang/golang/golang/Makefile
index 21e261b1c..54091398e 100644
--- a/lang/golang/golang/Makefile
+++ b/lang/golang/golang/Makefile
@@ -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:=:
@@ -197,6 +197,23 @@ endef
EXTERNAL_BOOTSTRAP_DIR:=$(call qstrip,$(CONFIG_GOLANG_EXTERNAL_BOOTSTRAP_ROOT))
USE_DEFAULT_BOOTSTRAP:=$(if $(EXTERNAL_BOOTSTRAP_DIR),,1)
+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)
@@ -322,7 +339,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 ; \