diff --git a/lang/golang/golang/Config.in b/lang/golang/Config.in similarity index 100% rename from lang/golang/golang/Config.in rename to lang/golang/Config.in diff --git a/lang/golang/golang/files/go-gcc-helper b/lang/golang/go-gcc-helper similarity index 79% rename from lang/golang/golang/files/go-gcc-helper rename to lang/golang/go-gcc-helper index b21457b55c181..d76e45aecf2c8 100644 --- a/lang/golang/golang/files/go-gcc-helper +++ b/lang/golang/go-gcc-helper @@ -1,16 +1,13 @@ -#!/bin/sh +#!/bin/bash # # Copyright (C) 2018, 2020 Jeffery To # -# This is free software, licensed under the GNU General Public License v2. -# See /LICENSE for more information. -# +# SPDX-License-Identifier: GPL-2.0-only me=go-gcc-helper name="${0##*/}" log() { - # shellcheck disable=SC2039 local IFS=" " printf '%s\n' "$me: $*" } diff --git a/lang/golang/golang-bootstrap/Makefile b/lang/golang/golang-bootstrap/Makefile new file mode 100644 index 0000000000000..86677770c253c --- /dev/null +++ b/lang/golang/golang-bootstrap/Makefile @@ -0,0 +1,269 @@ +# +# Copyright (C) 2018-2023, Jeffery To +# Copyright (C) 2025-2026, George Sapkin +# +# SPDX-License-Identifier: GPL-2.0-only + +include $(TOPDIR)/rules.mk + +GO_VERSION_MAJOR_MINOR:=1.22 +GO_VERSION_PATCH:=12 +PKG_HASH:=012a7e1f37f362c0918c1dfa3334458ac2da1628c4b9cf4d9ca02db986e17d71 + +PKG_NAME:=golang-bootstrap +PKG_VERSION:=$(GO_VERSION_MAJOR_MINOR)$(if $(GO_VERSION_PATCH),.$(GO_VERSION_PATCH)) +PKG_RELEASE:=1 + +GO_SOURCE_URLS:=https://go.dev/dl/ \ + https://dl.google.com/go/ \ + https://golang.google.cn/dl/ \ + https://mirrors.nju.edu.cn/golang/ \ + https://mirrors.ustc.edu.cn/golang/ + +PKG_SOURCE:=go$(PKG_VERSION).src.tar.gz +PKG_SOURCE_URL:=$(GO_SOURCE_URLS) + +PKG_MAINTAINER:=George Sapkin +PKG_LICENSE:=BSD-3-Clause +PKG_LICENSE_FILES:=LICENSE +PKG_CPE_ID:=cpe:/a:golang:go + +PKG_BUILD_DIR:=$(BUILD_DIR)/go-$(PKG_VERSION) +PKG_BUILD_PARALLEL:=1 +PKG_BUILD_FLAGS:=no-mips16 + +PKG_HOST_ONLY:=1 + +HOST_BUILD_DIR:=$(BUILD_DIR_HOST)/go-$(PKG_VERSION) +HOST_BUILD_PARALLEL:=1 + +HOST_GO_PREFIX:=$(STAGING_DIR_HOSTPKG) +HOST_GO_VERSION_ID:=bootstrap +HOST_GO_ROOT:=$(HOST_GO_PREFIX)/lib/go-$(HOST_GO_VERSION_ID) + +HOST_GO_VALID_OS_ARCH:= \ + android_386 android_amd64 android_arm android_arm64 \ + freebsd_386 freebsd_amd64 freebsd_arm freebsd_arm64 \ + linux_386 linux_amd64 linux_arm linux_arm64 \ + openbsd_386 openbsd_amd64 openbsd_arm openbsd_arm64 \ + netbsd_386 netbsd_amd64 netbsd_arm netbsd_arm64 \ + windows_386 windows_amd64 windows_arm windows_arm64 \ + \ + plan9_386 plan9_amd64 plan9_arm \ + \ + darwin_amd64 darwin_arm64 \ + ios_amd64 ios_arm64 \ + \ + dragonfly_amd64 \ + illumos_amd64 \ + solaris_amd64 \ + \ + aix_ppc64 \ + js_wasm \ + wasip1_wasm \ + \ + freebsd_riscv64 \ + openbsd_riscv64 \ + \ + linux_ppc64 linux_ppc64le \ + linux_mips linux_mipsle linux_mips64 linux_mips64le \ + linux_loong64 linux_riscv64 linux_s390x \ + \ + openbsd_mips64 + +BOOTSTRAP_SOURCE:=go1.4-bootstrap-20171003.tar.gz +BOOTSTRAP_SOURCE_URL:=$(GO_SOURCE_URLS) +BOOTSTRAP_HASH:=f4ff5b5eb3a3cae1c993723f3eab519c5bae18866b5e5f96fe1102f0cb5c3e52 + +BOOTSTRAP_BUILD_DIR:=$(HOST_BUILD_DIR)/.go_bootstrap + +BOOTSTRAP_GO_VALID_OS_ARCH:= \ + darwin_386 darwin_amd64 \ + dragonfly_386 dragonfly_amd64 \ + freebsd_386 freebsd_amd64 freebsd_arm \ + linux_386 linux_amd64 linux_arm \ + netbsd_386 netbsd_amd64 netbsd_arm \ + openbsd_386 openbsd_amd64 \ + plan9_386 plan9_amd64 \ + solaris_amd64 \ + windows_386 windows_amd64 + +BOOTSTRAP_1_17_SOURCE:=go1.17.13.src.tar.gz +BOOTSTRAP_1_17_SOURCE_URL:=$(GO_SOURCE_URLS) +BOOTSTRAP_1_17_HASH:=a1a48b23afb206f95e7bbaa9b898d965f90826f6f1d1fc0c1d784ada0cd300fd + +BOOTSTRAP_1_17_BUILD_DIR:=$(HOST_BUILD_DIR)/.go_bootstrap_1.17 + +BOOTSTRAP_1_20_SOURCE:=go1.20.14.src.tar.gz +BOOTSTRAP_1_20_SOURCE_URL:=$(GO_SOURCE_URLS) +BOOTSTRAP_1_20_HASH:=1aef321a0e3e38b7e91d2d7eb64040666cabdcc77d383de3c9522d0d69b67f4e + +BOOTSTRAP_1_20_BUILD_DIR:=$(HOST_BUILD_DIR)/.go_bootstrap_1.20 + +include $(INCLUDE_DIR)/host-build.mk +include $(INCLUDE_DIR)/package.mk +include ../golang-compiler.mk +include ../golang-package.mk + +PKG_UNPACK:=$(HOST_TAR) -C "$(PKG_BUILD_DIR)" --strip-components=1 -xzf "$(DL_DIR)/$(PKG_SOURCE)" +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)" +BOOTSTRAP_1_17_UNPACK:=$(HOST_TAR) -C "$(BOOTSTRAP_1_17_BUILD_DIR)" --strip-components=1 -xzf "$(DL_DIR)/$(BOOTSTRAP_1_17_SOURCE)" +BOOTSTRAP_1_20_UNPACK:=$(HOST_TAR) -C "$(BOOTSTRAP_1_20_BUILD_DIR)" --strip-components=1 -xzf "$(DL_DIR)/$(BOOTSTRAP_1_20_SOURCE)" + +# don't strip ELF executables in test data +RSTRIP:=: +STRIP:=: + +ifeq ($(GO_TARGET_SPECTRE_SUPPORTED),1) + PKG_CONFIG_DEPENDS+=CONFIG_GOLANG_SPECTRE +endif + +define Package/golang-bootstrap + TITLE:=Go programming language (bootstrap) + DEPENDS:=$(GO_ARCH_DEPENDS) + HIDDEN:=1 +endef + +define Package/golang-bootstrap/description + The Go programming language is an open source project to make programmers more + productive. + + Go is expressive, concise, clean, and efficient. Its concurrency mechanisms + make it easy to write programs that get the most out of multicore and + networked machines, while its novel type system enables flexible and modular + program construction. Go compiles quickly to machine code yet has the + convenience of garbage collection and the power of run-time reflection. It's a + fast, statically typed, compiled language that feels like a dynamically typed, + interpreted language. +endef + +define Package/golang-bootstrap/config + source "$(SOURCE)/../Config.in" +endef + +BOOTSTRAP_ROOT_DIR:=$(call qstrip,$(CONFIG_GOLANG_EXTERNAL_BOOTSTRAP_ROOT)) + +ifeq ($(BOOTSTRAP_ROOT_DIR),) + BOOTSTRAP_ROOT_DIR:=$(BOOTSTRAP_BUILD_DIR) + + define Download/golang-bootstrap + FILE:=$(BOOTSTRAP_SOURCE) + URL:=$(BOOTSTRAP_SOURCE_URL) + HASH:=$(BOOTSTRAP_HASH) + endef + $(eval $(call Download,golang-bootstrap)) + + define Bootstrap/Prepare + mkdir -p "$(BOOTSTRAP_BUILD_DIR)" && $(BOOTSTRAP_UNPACK) ; + endef + Hooks/HostPrepare/Post+=Bootstrap/Prepare + + $(eval $(call GoCompiler/AddProfile,Bootstrap,$(BOOTSTRAP_BUILD_DIR),,bootstrap,$(GO_HOST_OS_ARCH))) +endif + +# Bootstrap 1.17 + +define Download/golang-bootstrap-1.17 + FILE:=$(BOOTSTRAP_1_17_SOURCE) + URL:=$(BOOTSTRAP_1_17_SOURCE_URL) + HASH:=$(BOOTSTRAP_1_17_HASH) +endef +$(eval $(call Download,golang-bootstrap-1.17)) + +define Bootstrap-1.17/Prepare + mkdir -p "$(BOOTSTRAP_1_17_BUILD_DIR)" && $(BOOTSTRAP_1_17_UNPACK) ; +endef +Hooks/HostPrepare/Post+=Bootstrap-1.17/Prepare + +$(eval $(call GoCompiler/AddProfile,Bootstrap-1.17,$(BOOTSTRAP_1_17_BUILD_DIR),,bootstrap-1.17,$(GO_HOST_OS_ARCH))) + +# Bootstrap 1.20 + +define Download/golang-bootstrap-1.20 + FILE:=$(BOOTSTRAP_1_20_SOURCE) + URL:=$(BOOTSTRAP_1_20_SOURCE_URL) + HASH:=$(BOOTSTRAP_1_20_HASH) +endef +$(eval $(call Download,golang-bootstrap-1.20)) + +define Bootstrap-1.20/Prepare + mkdir -p "$(BOOTSTRAP_1_20_BUILD_DIR)" && $(BOOTSTRAP_1_20_UNPACK) ; +endef +Hooks/HostPrepare/Post+=Bootstrap-1.20/Prepare + +$(eval $(call GoCompiler/AddProfile,Bootstrap-1.20,$(BOOTSTRAP_1_20_BUILD_DIR),,bootstrap-1.20,$(GO_HOST_OS_ARCH))) + +# Host + +ifeq ($(GO_HOST_PIE_SUPPORTED),1) + HOST_GO_ENABLE_PIE:=1 +endif + +# When using GO_LDFLAGS to set buildmode=pie, the PIE install suffix does not +# apply (we also delete the std lib during Host/Install) + +$(eval $(call GoCompiler/AddProfile,Host,$(HOST_BUILD_DIR),$(HOST_GO_PREFIX),$(HOST_GO_VERSION_ID),$(GO_HOST_OS_ARCH))) + +HOST_GO_VARS= \ + GOHOSTARCH="$(GO_HOST_ARCH)" \ + GOCACHE="$(GO_BUILD_CACHE_DIR)" \ + GOENV=off \ + CC="$(HOSTCC_NOCACHE)" \ + CXX="$(HOSTCXX_NOCACHE)" + +define Host/Configure + $(call GoCompiler/Bootstrap/CheckHost,$(BOOTSTRAP_GO_VALID_OS_ARCH)) + $(call GoCompiler/Host/CheckHost,$(HOST_GO_VALID_OS_ARCH)) + + mkdir -p "$(GO_BUILD_CACHE_DIR)" +endef + +define Host/Compile + $(call GoCompiler/Bootstrap/Make, \ + $(HOST_GO_VARS) \ + CC="$(HOSTCC_NOCACHE) -std=gnu17" \ + ) + + $(call GoCompiler/Bootstrap-1.17/Make, \ + GOROOT_BOOTSTRAP="$(BOOTSTRAP_ROOT_DIR)" \ + $(HOST_GO_VARS) \ + ) + + $(call GoCompiler/Bootstrap-1.20/Make, \ + GOROOT_BOOTSTRAP="$(BOOTSTRAP_1_17_BUILD_DIR)" \ + $(HOST_GO_VARS) \ + ) + + $(call GoCompiler/Host/Make, \ + GOROOT_BOOTSTRAP="$(BOOTSTRAP_1_20_BUILD_DIR)" \ + $(if $(HOST_GO_ENABLE_PIE),GO_LDFLAGS="-buildmode pie") \ + $(HOST_GO_VARS) \ + ) +endef + +# If host and target OS/arch are the same, # when go compiles a program, it will +# use the host std lib, so remove it now and force go to rebuild std for target +# later +define Host/Install + $(call Host/Uninstall) + + $(call GoCompiler/Host/Install/Bin) + $(call GoCompiler/Host/Install/Src) + + rm -rf "$(HOST_GO_ROOT)/pkg/$(GO_HOST_OS_ARCH)" + + $(INSTALL_DIR) "$(HOST_GO_ROOT)/openwrt" + $(INSTALL_BIN) ../go-gcc-helper "$(HOST_GO_ROOT)/openwrt/" + $(LN) go-gcc-helper "$(HOST_GO_ROOT)/openwrt/gcc" + $(LN) go-gcc-helper "$(HOST_GO_ROOT)/openwrt/g++" +endef + +define Host/Uninstall + rm -rf "$(HOST_GO_ROOT)/openwrt" + + $(call GoCompiler/Host/Uninstall) +endef + +$(eval $(call HostBuild)) +$(eval $(call BuildPackage,golang-bootstrap)) diff --git a/lang/golang/golang-build.sh b/lang/golang/golang-build.sh index 01df4aa427a5b..d145b34b5ea5b 100644 --- a/lang/golang/golang-build.sh +++ b/lang/golang/golang-build.sh @@ -1,28 +1,23 @@ -#!/bin/sh +#!/bin/bash # # Copyright (C) 2020, 2022 Jeffery To # -# This is free software, licensed under the GNU General Public License v2. -# See /LICENSE for more information. -# +# SPDX-License-Identifier: GPL-2.0-only nl=" " log() { - # shellcheck disable=SC2039 local IFS=" " printf '%s\n' "$*" } log_error() { - # shellcheck disable=SC2039 local IFS=" " printf 'Error: %s\n' "$*" >&2 } link_contents() { - # shellcheck disable=SC2039 local src="$1" dest="$2" IFS="$nl" dirs dir base if [ -n "$(find "$src" -mindepth 1 -maxdepth 1 -name "*.go" -not -type d)" ]; then @@ -52,7 +47,6 @@ link_contents() { } configure() { - # shellcheck disable=SC2039 local files code testdata gomod pattern extra IFS file dest cd "$BUILD_DIR" || return 1 @@ -99,7 +93,6 @@ configure() { } build() { - # shellcheck disable=SC2039 local modargs pattern targets retval cd "$GO_BUILD_DIR" || return 1 @@ -149,14 +142,12 @@ build() { } install_bin() { - # shellcheck disable=SC2039 local dest="$1" install -d -m0755 "$dest/$GO_INSTALL_BIN_PATH" install -m0755 "$GO_BUILD_BIN_DIR"/* "$dest/$GO_INSTALL_BIN_PATH/" } install_src() { - # shellcheck disable=SC2039 local dest="$1" dir="${GO_PKG%/*}" install -d -m0755 "$dest/$GO_BUILD_DEPENDS_PATH/src/$dir" cp -fpR "$GO_BUILD_DIR/src/$GO_PKG" "$dest/$GO_BUILD_DEPENDS_PATH/src/$dir/" diff --git a/lang/golang/golang-compiler.mk b/lang/golang/golang-compiler.mk index 44defed7b4442..f683c1e34e9e8 100644 --- a/lang/golang/golang-compiler.mk +++ b/lang/golang/golang-compiler.mk @@ -1,9 +1,7 @@ # # Copyright (C) 2018, 2020-2021, 2023 Jeffery To # -# This is free software, licensed under the GNU General Public License v2. -# See /LICENSE for more information. -# +# SPDX-License-Identifier: GPL-2.0-only ifeq ($(origin GO_INCLUDE_DIR),undefined) GO_INCLUDE_DIR:=$(dir $(lastword $(MAKEFILE_LIST))) @@ -21,14 +19,10 @@ endef # $(1) source go root # $(2) additional environment variables (optional) define GoCompiler/Default/Make - ( \ - cd "$(1)/src" ; \ - $(2) \ - $(BASH) make.bash \ + cd "$(1)/src" ; \ + $(2) $(BASH) make.bash \ $(if $(findstring s,$(OPENWRT_VERBOSE)),-v) \ - --no-banner \ - ; \ - ) + --no-banner endef # $(1) destination prefix @@ -87,8 +81,8 @@ endef # $(2) go version id define GoCompiler/Default/Install/BinLinks $(INSTALL_DIR) "$(1)/bin" - $(LN) "../lib/go-$(2)/bin/go" "$(1)/bin/go" - $(LN) "../lib/go-$(2)/bin/gofmt" "$(1)/bin/gofmt" + $(LN) "../lib/go-$(2)/bin/go" "$(1)/bin/go$(2)" + $(LN) "../lib/go-$(2)/bin/gofmt" "$(1)/bin/gofmt$(2)" endef # $(1) source go root @@ -132,9 +126,10 @@ define GoCompiler/Default/Uninstall endef # $(1) destination prefix +# $(2) go version id define GoCompiler/Default/Uninstall/BinLinks - rm -f "$(1)/bin/go" - rm -f "$(1)/bin/gofmt" + rm -f "$(1)/bin/go$(2)" + rm -f "$(1)/bin/gofmt$(2)" endef @@ -183,7 +178,7 @@ define GoCompiler/AddProfile # $$(1) override install prefix (optional) define GoCompiler/$(1)/Uninstall/BinLinks - $$(call GoCompiler/Default/Uninstall/BinLinks,$$(or $$(1),$(3))) + $$(call GoCompiler/Default/Uninstall/BinLinks,$$(or $$(1),$(3)),$(4)) endef endef diff --git a/lang/golang/golang-host-build.mk b/lang/golang/golang-host-build.mk index 7c7551fd18827..f1bb70f273b94 100644 --- a/lang/golang/golang-host-build.mk +++ b/lang/golang/golang-host-build.mk @@ -1,9 +1,7 @@ # # Copyright (C) 2020, 2022 Jeffery To # -# This is free software, licensed under the GNU General Public License v2. -# See /LICENSE for more information. -# +# SPDX-License-Identifier: GPL-2.0-only ifeq ($(origin GO_INCLUDE_DIR),undefined) GO_INCLUDE_DIR:=$(dir $(lastword $(MAKEFILE_LIST))) diff --git a/lang/golang/golang-package.mk b/lang/golang/golang-package.mk index 8edcb278c5b9b..4d76d30c6ce97 100644 --- a/lang/golang/golang-package.mk +++ b/lang/golang/golang-package.mk @@ -1,9 +1,7 @@ # # Copyright (C) 2018-2022 Jeffery To # -# This is free software, licensed under the GNU General Public License v2. -# See /LICENSE for more information. -# +# SPDX-License-Identifier: GPL-2.0-only ifeq ($(origin GO_INCLUDE_DIR),undefined) GO_INCLUDE_DIR:=$(dir $(lastword $(MAKEFILE_LIST))) @@ -179,7 +177,13 @@ define GoPackage/GoSubMenu CATEGORY:=Languages endef +# Some packages like docker use go directly and don't process vars like GO, so +# just add selected version to path and insert it into several used vars. +GO_BIN_PATH:= \ + PATH=$(STAGING_DIR_HOSTPKG)/lib/go-$(GO_HOST_VERSION)/bin:$(PATH) + GO_PKG_BUILD_CONFIG_VARS= \ + $(GO_BIN_PATH) \ GO_PKG="$(strip $(GO_PKG))" \ GO_INSTALL_EXTRA="$(strip $(GO_PKG_INSTALL_EXTRA))" \ GO_INSTALL_ALL="$(strip $(GO_PKG_INSTALL_ALL))" \ @@ -220,6 +224,7 @@ GO_PKG_BUILD_VARS= \ GOTOOLCHAIN=local GO_PKG_VARS= \ + $(GO_BIN_PATH) \ $(GO_PKG_TARGET_VARS) \ $(GO_PKG_BUILD_VARS) @@ -256,7 +261,7 @@ GO_PKG_INSTALL_ARGS= \ define GoPackage/Build/Configure $(GO_GENERAL_BUILD_CONFIG_VARS) \ $(GO_PKG_BUILD_CONFIG_VARS) \ - $(SHELL) $(GO_INCLUDE_DIR)/golang-build.sh configure + $(SHELL) $(GO_INCLUDE_DIR)golang-build.sh configure endef # $(1) additional arguments for go command line (optional) @@ -264,7 +269,7 @@ define GoPackage/Build/Compile $(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) + $(SHELL) $(GO_INCLUDE_DIR)golang-build.sh build $(GO_PKG_INSTALL_ARGS) $(1) endef define GoPackage/Build/InstallDev @@ -274,13 +279,13 @@ endef define GoPackage/Package/Install/Bin $(GO_GENERAL_BUILD_CONFIG_VARS) \ $(GO_PKG_BUILD_CONFIG_VARS) \ - $(SHELL) $(GO_INCLUDE_DIR)/golang-build.sh install_bin "$(1)" + $(SHELL) $(GO_INCLUDE_DIR)golang-build.sh install_bin "$(1)" endef define GoPackage/Package/Install/Src $(GO_GENERAL_BUILD_CONFIG_VARS) \ $(GO_PKG_BUILD_CONFIG_VARS) \ - $(SHELL) $(GO_INCLUDE_DIR)/golang-build.sh install_src "$(1)" + $(SHELL) $(GO_INCLUDE_DIR)golang-build.sh install_src "$(1)" endef define GoPackage/Package/Install diff --git a/lang/golang/golang-values.mk b/lang/golang/golang-values.mk index 06e6cec38ffd0..e47e1323b9c31 100644 --- a/lang/golang/golang-values.mk +++ b/lang/golang/golang-values.mk @@ -1,9 +1,7 @@ # # Copyright (C) 2018-2023 Jeffery To # -# This is free software, licensed under the GNU General Public License v2. -# See /LICENSE for more information. -# +# SPDX-License-Identifier: GPL-2.0-only ifeq ($(origin GO_INCLUDE_DIR),undefined) GO_INCLUDE_DIR:=$(dir $(lastword $(MAKEFILE_LIST))) @@ -125,6 +123,12 @@ unexport \ GOBOOTSTRAP_TOOLEXEC +GO_DEFAULT_VERSION:=1.25 +GO_HOST_VERSION:=$(patsubst golang%/host,%,$(filter golang%/host,$(PKG_BUILD_DEPENDS))) +ifeq ($(GO_HOST_VERSION),) + GO_HOST_VERSION:=$(GO_DEFAULT_VERSION) +endif + # GOOS / GOARCH go_arch=$(subst \ diff --git a/lang/golang/golang-version.mk b/lang/golang/golang-version.mk new file mode 100644 index 0000000000000..1883b31a29029 --- /dev/null +++ b/lang/golang/golang-version.mk @@ -0,0 +1,270 @@ +# +# Copyright (C) 2018-2023, Jeffery To +# Copyright (C) 2025-2026, George Sapkin +# +# SPDX-License-Identifier: GPL-2.0-only + +HOST_GO_PREFIX:=$(STAGING_DIR_HOSTPKG) +HOST_GO_VERSION_ID:=$(GO_VERSION_MAJOR_MINOR) +HOST_GO_ROOT:=$(HOST_GO_PREFIX)/lib/go-$(HOST_GO_VERSION_ID) + +BOOTSTRAP_DIR:=$(HOST_GO_PREFIX)/lib/go-$(GO_BOOTSTRAP_VERSION) + +include ../golang-compiler.mk +include ../golang-package.mk +include ../golang-values.mk + +PKG_UNPACK:=$(HOST_TAR) -C "$(PKG_BUILD_DIR)" --strip-components=1 -xzf "$(DL_DIR)/$(PKG_SOURCE)" +HOST_UNPACK:=$(HOST_TAR) -C "$(HOST_BUILD_DIR)" --strip-components=1 -xzf "$(DL_DIR)/$(PKG_SOURCE)" + +# don't strip ELF executables in test data +RSTRIP:=: +STRIP:=: + +ifeq ($(GO_TARGET_SPECTRE_SUPPORTED),1) + PKG_CONFIG_DEPENDS+=CONFIG_GOLANG_SPECTRE +endif + +define Package/$(PKG_NAME)/Default + $(call GoPackage/GoSubMenu) + TITLE:=Go programming language + URL:=https://go.dev/ + DEPENDS:=$(GO_ARCH_DEPENDS) +endef + +define Package/$(PKG_NAME)/Default/description + The Go programming language is an open source project to make programmers more + productive. + + Go is expressive, concise, clean, and efficient. Its concurrency mechanisms + make it easy to write programs that get the most out of multi-core and + networked machines, while its novel type system enables flexible and modular + program construction. Go compiles quickly to machine code yet has the + convenience of garbage collection and the power of run-time reflection. It's + a fast, statically typed, compiled language that feels like a dynamically + typed, interpreted language. +endef + +ifeq ($(GO_DEFAULT_VERSION),$(GO_VERSION_MAJOR_MINOR)) + ALT_PRIORITY:=500 +else + ALT_PRIORITY:=100 +endif + +# go tool requires source present: +# https://github.com/golang/go/issues/4635 +define Package/$(PKG_NAME) + $(call Package/$(PKG_NAME)/Default) + TITLE+= (compiler) + DEPENDS+= +golang$(GO_VERSION_MAJOR_MINOR)-src + EXTRA_DEPENDS:=golang$(GO_VERSION_MAJOR_MINOR)-src (=$(PKG_VERSION)-r$(PKG_RELEASE)) + PROVIDES:=@golang + $(if $(filter $(GO_DEFAULT_VERSION),$(GO_VERSION_MAJOR_MINOR)),DEFAULT_VARIANT:=1) + ALTERNATIVES:=\ + $(ALT_PRIORITY):/usr/bin/go:/usr/lib/go-$(GO_VERSION_MAJOR_MINOR)/bin/go \ + $(ALT_PRIORITY):/usr/bin/gofmt:/usr/lib/go-$(GO_VERSION_MAJOR_MINOR)/bin/gofmt +endef + +define Package/$(PKG_NAME)/description + $(call Package/$(PKG_NAME)/Default/description) + + This package provides an assembler, compiler, linker, and compiled libraries + for the Go programming language. +endef + +define Package/$(PKG_NAME)/config + source "$(SOURCE)/../Config.in" +endef + +define Package/$(PKG_NAME)-doc + $(call Package/$(PKG_NAME)/Default) + TITLE+= (documentation) + PROVIDES:=@golang-doc + $(if $(filter $(GO_DEFAULT_VERSION),$(GO_VERSION_MAJOR_MINOR)),DEFAULT_VARIANT:=1) +endef + +define Package/$(PKG_NAME)-doc/description + $(call Package/$(PKG_NAME)/Default/description) + + This package provides the documentation for the Go programming language. +endef + +define Package/$(PKG_NAME)-src + $(call Package/$(PKG_NAME)/Default) + TITLE+= (source files) + DEPENDS+= +libstdcpp +libtiff + PROVIDES:=@golang-src + $(if $(filter $(GO_DEFAULT_VERSION),$(GO_VERSION_MAJOR_MINOR)),DEFAULT_VARIANT:=1) +endef + +define Package/$(PKG_NAME)-src/description + $(call Package/$(PKG_NAME)/Default/description) + + This package provides the Go programming language source files needed for + cross-compilation. +endef + + +# Host + +ifeq ($(GO_HOST_PIE_SUPPORTED),1) + HOST_GO_ENABLE_PIE:=1 +endif + +# When using GO_LDFLAGS to set buildmode=pie, the PIE install suffix does not +# apply (we also delete the std lib during Host/Install) + +$(eval $(call GoCompiler/AddProfile,$(HOST_GO_PROFILE_ID),$(HOST_BUILD_DIR),$(HOST_GO_PREFIX),$(HOST_GO_VERSION_ID),$(GO_HOST_OS_ARCH))) + +HOST_GO_VARS?= \ + GOHOSTARCH="$(GO_HOST_ARCH)" \ + GOCACHE="$(GO_BUILD_CACHE_DIR)" \ + GOENV=off \ + CC="$(HOSTCC_NOCACHE)" \ + CXX="$(HOSTCXX_NOCACHE)" + +define Host/Configure + $(call GoCompiler/$(HOST_GO_PROFILE_ID)/CheckHost,$(HOST_GO_VALID_OS_ARCH)) + + mkdir -p "$(GO_BUILD_CACHE_DIR)" +endef + +define Host/Compile + $(call GoCompiler/$(HOST_GO_PROFILE_ID)/Make, \ + GOROOT_BOOTSTRAP="$(BOOTSTRAP_DIR)" \ + $(if $(HOST_GO_ENABLE_PIE),GO_LDFLAGS="-buildmode pie") \ + $(HOST_GO_VARS) \ + ) +endef + +# If host and target OS/arch are the same, when go compiles a program, it will +# use the host std lib, so remove it now and force go to rebuild std for target +# later +define Host/Install + $(call Host/Uninstall) + + $(call GoCompiler/$(HOST_GO_PROFILE_ID)/Install/Bin) + $(call GoCompiler/$(HOST_GO_PROFILE_ID)/Install/Src) + $(call GoCompiler/$(HOST_GO_PROFILE_ID)/Install/BinLinks) + + rm -rf "$(HOST_GO_ROOT)/pkg/$(GO_HOST_OS_ARCH)" + + $(INSTALL_DIR) "$(HOST_GO_ROOT)/openwrt" + $(INSTALL_BIN) ../go-gcc-helper "$(HOST_GO_ROOT)/openwrt/" + $(LN) go-gcc-helper "$(HOST_GO_ROOT)/openwrt/gcc" + $(LN) go-gcc-helper "$(HOST_GO_ROOT)/openwrt/g++" +endef + +define Host/Uninstall + rm -rf "$(HOST_GO_ROOT)/openwrt" + + $(call GoCompiler/$(HOST_GO_PROFILE_ID)/Uninstall/BinLinks) + $(call GoCompiler/$(HOST_GO_PROFILE_ID)/Uninstall) +endef + + +# Target + +ifeq ($(GO_PKG_ENABLE_PIE),1) + PKG_GO_INSTALL_SUFFIX:=$(GO_TARGET_PIE_INSTALL_SUFFIX) +endif + +$(eval $(call GoCompiler/AddProfile,Package,$(PKG_BUILD_DIR),$(PKG_GO_PREFIX),$(PKG_GO_VERSION_ID),$(GO_OS_ARCH),$(PKG_GO_INSTALL_SUFFIX))) + +PKG_GO_ZBOOTSTRAP_MODS?= \ + s/defaultGO386 = `[^`]*`/defaultGO386 = `$(or $(GO_386),sse2)`/; \ + s/defaultGOAMD64 = `[^`]*`/defaultGOAMD64 = `$(or $(GO_AMD64),v1)`/; \ + s/defaultGOARM = `[^`]*`/defaultGOARM = `$(or $(GO_ARM),7)`/; \ + s/defaultGOARM64 = `[^`]*`/defaultGOARM64 = `$(or $(GO_ARM64),v8.0)`/; \ + s/defaultGOMIPS = `[^`]*`/defaultGOMIPS = `$(or $(GO_MIPS),hardfloat)`/; \ + s/defaultGOMIPS64 = `[^`]*`/defaultGOMIPS64 = `$(or $(GO_MIPS64),hardfloat)`/; \ + s/defaultGOPPC64 = `[^`]*`/defaultGOPPC64 = `$(or $(GO_PPC64),power8)`/; + +PKG_GO_ZBOOTSTRAP_PATH:=$(PKG_BUILD_DIR)/src/internal/buildcfg/zbootstrap.go + +PKG_GO_VARS?= \ + GOHOSTARCH="$(GO_HOST_ARCH)" \ + GOCACHE="$(GO_BUILD_CACHE_DIR)" \ + GOENV=off \ + GO_GCC_HELPER_PATH="$$$$PATH" \ + CC=gcc \ + CXX=g++ \ + PKG_CONFIG=pkg-config \ + PATH="$(HOST_GO_ROOT)/openwrt:$$$$PATH" + +PKG_GO_GCFLAGS?= \ + $(if $(GO_PKG_ENABLE_SPECTRE),-spectre all) + +PKG_GO_ASMFLAGS?= \ + $(if $(GO_PKG_ENABLE_SPECTRE),-spectre all) + +PKG_GO_LDFLAGS?= \ + -buildid '$(SOURCE_DATE_EPOCH)' \ + -linkmode external \ + -extldflags '$(patsubst -z%,-Wl$(comma)-z$(comma)%,$(TARGET_LDFLAGS))' \ + $(if $(CONFIG_NO_STRIP)$(CONFIG_DEBUG),,-s -w) + +PKG_GO_INSTALL_ARGS?= \ + -buildvcs=false \ + -trimpath \ + -ldflags "all=$(PKG_GO_LDFLAGS)" \ + $(if $(PKG_GO_GCFLAGS),-gcflags "all=$(PKG_GO_GCFLAGS)") \ + $(if $(PKG_GO_ASMFLAGS),-asmflags "all=$(PKG_GO_ASMFLAGS)") \ + $(if $(filter $(GO_PKG_ENABLE_PIE),1),-buildmode pie) + +define Build/Configure + mkdir -p "$(GO_BUILD_CACHE_DIR)" +endef + +define Build/Compile + @echo "Building target Go first stage" + + $(call GoCompiler/Package/Make, \ + GOROOT_BOOTSTRAP="$(HOST_GO_ROOT)" \ + GO_GCC_HELPER_CC="$(HOSTCC)" \ + GO_GCC_HELPER_CXX="$(HOSTCXX)" \ + $(PKG_GO_VARS) \ + ) + + $(SED) '$(PKG_GO_ZBOOTSTRAP_MODS)' "$(PKG_GO_ZBOOTSTRAP_PATH)" + + if echo 'int main() { return 0; }' | $(TARGET_CC) -o $(PKG_BUILD_DIR)/test-ldso -x c - > /dev/null 2>&1; then \ + LDSO=$$$$( \ + readelf -l $(PKG_BUILD_DIR)/test-ldso | \ + sed -n -e 's/^.*interpreter: \(.*\)[]]/\1/p' \ + ) ; \ + fi ; \ + $(SED) "s,defaultGO_LDSO = \`[^\`]*\`,defaultGO_LDSO = \`$$$$LDSO\`," "$(PKG_GO_ZBOOTSTRAP_PATH)" + + @echo "Building target Go second stage" + + cd "$(PKG_BUILD_DIR)/bin" ; \ + export $(GO_PKG_TARGET_VARS) ; \ + $(CP) go go-host ; \ + GO_GCC_HELPER_CC="$(TARGET_CC)" \ + GO_GCC_HELPER_CXX="$(TARGET_CXX)" \ + $(PKG_GO_VARS) \ + ./go-host install -a $(PKG_GO_INSTALL_ARGS) std cmd; \ + retval=$$$$? ; \ + rm -f go-host ; \ + exit $$$$retval +endef + +define Package/$(PKG_NAME)/install + $(call GoCompiler/Package/Install/Bin,$(1)$(PKG_GO_PREFIX)) +endef + +define Package/$(PKG_NAME)-doc/install + $(call GoCompiler/Package/Install/Doc,$(1)$(PKG_GO_PREFIX)) +endef + +define Package/$(PKG_NAME)-src/install + $(call GoCompiler/Package/Install/Src,$(1)$(PKG_GO_PREFIX)) +endef + +# src/debug contains ELF executables as test data and they reference these +# libraries we need to call this in Package/$(GO_VERSION_MAJOR_MINOR)/extra_provides to pass +# CheckDependencies in package-pack.mk +define Package/$(PKG_NAME)-src/extra_provides + echo 'libc.so.6' +endef diff --git a/lang/golang/golang/Makefile b/lang/golang/golang/Makefile index aec0aeaa66fa5..0a3b5c472e029 100644 --- a/lang/golang/golang/Makefile +++ b/lang/golang/golang/Makefile @@ -1,464 +1,34 @@ +# This is a dummy go package that allows packages to use default go version by +# setting PKG_BUILD_DEPENDS:=golang/host, instead of specifying a concrete +# version, e.g. PKG_BUILD_DEPENDS:=golang1.25/host # -# Copyright (C) 2018-2023 Jeffery To -# -# This is free software, licensed under the GNU General Public License v2. -# See /LICENSE for more information. -# +# SPDX-License-Identifier: GPL-2.0-only include $(TOPDIR)/rules.mk - -GO_VERSION_MAJOR_MINOR:=1.25 -GO_VERSION_PATCH:=5 +include ../golang-values.mk PKG_NAME:=golang -PKG_VERSION:=$(GO_VERSION_MAJOR_MINOR)$(if $(GO_VERSION_PATCH),.$(GO_VERSION_PATCH)) +PKG_VERSION:=$(GO_DEFAULT_VERSION) PKG_RELEASE:=1 -GO_SOURCE_URLS:=https://dl.google.com/go/ \ - https://mirrors.ustc.edu.cn/golang/ \ - https://mirrors.nju.edu.cn/golang/ - -PKG_SOURCE:=go$(PKG_VERSION).src.tar.gz -PKG_SOURCE_URL:=$(GO_SOURCE_URLS) -PKG_HASH:=22a5fd0a91efcd28a1b0537106b9959b2804b61f59c3758b51e8e5429c1a954f - -PKG_MAINTAINER:=Jeffery To -PKG_LICENSE:=BSD-3-Clause -PKG_LICENSE_FILES:=LICENSE -PKG_CPE_ID:=cpe:/a:golang:go - -PKG_BUILD_DEPENDS:=golang/host -PKG_BUILD_DIR:=$(BUILD_DIR)/go-$(PKG_VERSION) -PKG_BUILD_PARALLEL:=1 -PKG_BUILD_FLAGS:=no-mips16 - -PKG_GO_PREFIX:=/usr -PKG_GO_VERSION_ID:=$(GO_VERSION_MAJOR_MINOR) - -HOST_BUILD_DIR:=$(BUILD_DIR_HOST)/go-$(PKG_VERSION) -HOST_BUILD_PARALLEL:=1 - -HOST_GO_PREFIX:=$(STAGING_DIR_HOSTPKG) -HOST_GO_VERSION_ID:=cross -HOST_GO_ROOT:=$(HOST_GO_PREFIX)/lib/go-$(HOST_GO_VERSION_ID) - -HOST_GO_VALID_OS_ARCH:= \ - android_386 android_amd64 android_arm android_arm64 \ - freebsd_386 freebsd_amd64 freebsd_arm freebsd_arm64 \ - linux_386 linux_amd64 linux_arm linux_arm64 \ - openbsd_386 openbsd_amd64 openbsd_arm openbsd_arm64 \ - netbsd_386 netbsd_amd64 netbsd_arm netbsd_arm64 \ - windows_386 windows_amd64 windows_arm windows_arm64 \ - \ - plan9_386 plan9_amd64 plan9_arm \ - \ - darwin_amd64 darwin_arm64 \ - ios_amd64 ios_arm64 \ - \ - dragonfly_amd64 \ - illumos_amd64 \ - solaris_amd64 \ - \ - aix_ppc64 \ - js_wasm \ - wasip1_wasm \ - \ - freebsd_riscv64 \ - openbsd_riscv64 \ - \ - linux_ppc64 linux_ppc64le \ - linux_mips linux_mipsle linux_mips64 linux_mips64le \ - linux_loong64 linux_riscv64 linux_s390x \ - \ - openbsd_mips64 - -BOOTSTRAP_SOURCE:=go1.4-bootstrap-20171003.tar.gz -BOOTSTRAP_SOURCE_URL:=$(GO_SOURCE_URLS) -BOOTSTRAP_HASH:=f4ff5b5eb3a3cae1c993723f3eab519c5bae18866b5e5f96fe1102f0cb5c3e52 - -BOOTSTRAP_BUILD_DIR:=$(HOST_BUILD_DIR)/.go_bootstrap - -BOOTSTRAP_GO_VALID_OS_ARCH:= \ - darwin_386 darwin_amd64 \ - dragonfly_386 dragonfly_amd64 \ - freebsd_386 freebsd_amd64 freebsd_arm \ - linux_386 linux_amd64 linux_arm \ - netbsd_386 netbsd_amd64 netbsd_arm \ - openbsd_386 openbsd_amd64 \ - plan9_386 plan9_amd64 \ - solaris_amd64 \ - windows_386 windows_amd64 - -BOOTSTRAP_1_17_SOURCE:=go1.17.13.src.tar.gz -BOOTSTRAP_1_17_SOURCE_URL:=$(GO_SOURCE_URLS) -BOOTSTRAP_1_17_HASH:=a1a48b23afb206f95e7bbaa9b898d965f90826f6f1d1fc0c1d784ada0cd300fd - -BOOTSTRAP_1_17_BUILD_DIR:=$(HOST_BUILD_DIR)/.go_bootstrap_1.17 +PKG_MAINTAINER:=George Sapkin -BOOTSTRAP_1_20_SOURCE:=go1.20.14.src.tar.gz -BOOTSTRAP_1_20_SOURCE_URL:=$(GO_SOURCE_URLS) -BOOTSTRAP_1_20_HASH:=1aef321a0e3e38b7e91d2d7eb64040666cabdcc77d383de3c9522d0d69b67f4e - -BOOTSTRAP_1_20_BUILD_DIR:=$(HOST_BUILD_DIR)/.go_bootstrap_1.20 - -BOOTSTRAP_1_22_SOURCE:=go1.22.6.src.tar.gz -BOOTSTRAP_1_22_SOURCE_URL:=$(GO_SOURCE_URLS) -BOOTSTRAP_1_22_HASH:=9e48d99d519882579917d8189c17e98c373ce25abaebb98772e2927088992a51 - -BOOTSTRAP_1_22_BUILD_DIR:=$(HOST_BUILD_DIR)/.go_bootstrap_1.22 +HOST_BUILD_DEPENDS:=golang$(PKG_VERSION)/host +PKG_HOST_ONLY:=1 include $(INCLUDE_DIR)/host-build.mk include $(INCLUDE_DIR)/package.mk -include ../golang-compiler.mk -include ../golang-package.mk - -PKG_UNPACK:=$(HOST_TAR) -C "$(PKG_BUILD_DIR)" --strip-components=1 -xzf "$(DL_DIR)/$(PKG_SOURCE)" -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)" -BOOTSTRAP_1_17_UNPACK:=$(HOST_TAR) -C "$(BOOTSTRAP_1_17_BUILD_DIR)" --strip-components=1 -xzf "$(DL_DIR)/$(BOOTSTRAP_1_17_SOURCE)" -BOOTSTRAP_1_20_UNPACK:=$(HOST_TAR) -C "$(BOOTSTRAP_1_20_BUILD_DIR)" --strip-components=1 -xzf "$(DL_DIR)/$(BOOTSTRAP_1_20_SOURCE)" -BOOTSTRAP_1_22_UNPACK:=$(HOST_TAR) -C "$(BOOTSTRAP_1_22_BUILD_DIR)" --strip-components=1 -xzf "$(DL_DIR)/$(BOOTSTRAP_1_22_SOURCE)" - -# don't strip ELF executables in test data -RSTRIP:=: -STRIP:=: - -ifeq ($(GO_TARGET_SPECTRE_SUPPORTED),1) - PKG_CONFIG_DEPENDS+=CONFIG_GOLANG_SPECTRE -endif - -define Package/golang/Default -$(call GoPackage/GoSubMenu) - TITLE:=Go programming language - URL:=https://go.dev/ - DEPENDS:=$(GO_ARCH_DEPENDS) -endef -define Package/golang/Default/description -The Go programming language is an open source project to make -programmers more productive. - -Go is expressive, concise, clean, and efficient. Its concurrency -mechanisms make it easy to write programs that get the most out of -multicore and networked machines, while its novel type system enables -flexible and modular program construction. Go compiles quickly to -machine code yet has the convenience of garbage collection and the power -of run-time reflection. It's a fast, statically typed, compiled language -that feels like a dynamically typed, interpreted language. -endef - -# go tool requires source present: -# https://github.com/golang/go/issues/4635 define Package/golang -$(call Package/golang/Default) - TITLE+= (compiler) - DEPENDS+= +golang-src -endef - -define Package/golang/description -$(call Package/golang/Default/description) - -This package provides an assembler, compiler, linker, and compiled -libraries for the Go programming language. -endef - -define Package/golang/config - source "$(SOURCE)/Config.in" -endef - -define Package/golang-doc -$(call Package/golang/Default) - TITLE+= (documentation) -endef - -define Package/golang-doc/description -$(call Package/golang/Default/description) - -This package provides the documentation for the Go programming language. -endef - -define Package/golang-src -$(call Package/golang/Default) - TITLE+= (source files) - DEPENDS+= +libstdcpp +libtiff -endef - -define Package/golang-src/description -$(call Package/golang/Default/description) - -This package provides the Go programming language source files needed -for cross-compilation. -endef - - -# Bootstrap - -BOOTSTRAP_ROOT_DIR:=$(call qstrip,$(CONFIG_GOLANG_EXTERNAL_BOOTSTRAP_ROOT)) - -ifeq ($(BOOTSTRAP_ROOT_DIR),) - BOOTSTRAP_ROOT_DIR:=$(BOOTSTRAP_BUILD_DIR) - - define Download/golang-bootstrap - FILE:=$(BOOTSTRAP_SOURCE) - URL:=$(BOOTSTRAP_SOURCE_URL) - HASH:=$(BOOTSTRAP_HASH) - endef - $(eval $(call Download,golang-bootstrap)) - - define Bootstrap/Prepare - mkdir -p "$(BOOTSTRAP_BUILD_DIR)" && $(BOOTSTRAP_UNPACK) ; - endef - Hooks/HostPrepare/Post+=Bootstrap/Prepare - - $(eval $(call GoCompiler/AddProfile,Bootstrap,$(BOOTSTRAP_BUILD_DIR),,bootstrap,$(GO_HOST_OS_ARCH))) -endif - - -# Bootstrap 1.17 - -define Download/golang-bootstrap-1.17 - FILE:=$(BOOTSTRAP_1_17_SOURCE) - URL:=$(BOOTSTRAP_1_17_SOURCE_URL) - HASH:=$(BOOTSTRAP_1_17_HASH) -endef -$(eval $(call Download,golang-bootstrap-1.17)) - -define Bootstrap-1.17/Prepare - mkdir -p "$(BOOTSTRAP_1_17_BUILD_DIR)" && $(BOOTSTRAP_1_17_UNPACK) ; -endef -Hooks/HostPrepare/Post+=Bootstrap-1.17/Prepare - -$(eval $(call GoCompiler/AddProfile,Bootstrap-1.17,$(BOOTSTRAP_1_17_BUILD_DIR),,bootstrap-1.17,$(GO_HOST_OS_ARCH))) - - -# Bootstrap 1.20 - -define Download/golang-bootstrap-1.20 - FILE:=$(BOOTSTRAP_1_20_SOURCE) - URL:=$(BOOTSTRAP_1_20_SOURCE_URL) - HASH:=$(BOOTSTRAP_1_20_HASH) -endef -$(eval $(call Download,golang-bootstrap-1.20)) - -define Bootstrap-1.20/Prepare - mkdir -p "$(BOOTSTRAP_1_20_BUILD_DIR)" && $(BOOTSTRAP_1_20_UNPACK) ; -endef -Hooks/HostPrepare/Post+=Bootstrap-1.20/Prepare - -$(eval $(call GoCompiler/AddProfile,Bootstrap-1.20,$(BOOTSTRAP_1_20_BUILD_DIR),,bootstrap-1.20,$(GO_HOST_OS_ARCH))) - - -# Bootstrap 1.22 - -define Download/golang-bootstrap-1.22 - FILE:=$(BOOTSTRAP_1_22_SOURCE) - URL:=$(BOOTSTRAP_1_22_SOURCE_URL) - HASH:=$(BOOTSTRAP_1_22_HASH) -endef -$(eval $(call Download,golang-bootstrap-1.22)) - -define Bootstrap-1.22/Prepare - mkdir -p "$(BOOTSTRAP_1_22_BUILD_DIR)" && $(BOOTSTRAP_1_22_UNPACK) ; -endef -Hooks/HostPrepare/Post+=Bootstrap-1.22/Prepare - -$(eval $(call GoCompiler/AddProfile,Bootstrap-1.22,$(BOOTSTRAP_1_22_BUILD_DIR),,bootstrap-1.22,$(GO_HOST_OS_ARCH))) - -# Host - -ifeq ($(GO_HOST_PIE_SUPPORTED),1) - HOST_GO_ENABLE_PIE:=1 -endif - -# when using GO_LDFLAGS to set buildmode=pie, the PIE install suffix -# does not apply (we also delete the std lib during Host/Install) - -$(eval $(call GoCompiler/AddProfile,Host,$(HOST_BUILD_DIR),$(HOST_GO_PREFIX),$(HOST_GO_VERSION_ID),$(GO_HOST_OS_ARCH),$(HOST_GO_INSTALL_SUFFIX))) - -HOST_GO_VARS= \ - GOHOSTARCH="$(GO_HOST_ARCH)" \ - GOCACHE="$(GO_BUILD_CACHE_DIR)" \ - GOENV=off \ - CC="$(HOSTCC_NOCACHE)" \ - CXX="$(HOSTCXX_NOCACHE)" - -define Host/Configure - $(call GoCompiler/Bootstrap/CheckHost,$(BOOTSTRAP_GO_VALID_OS_ARCH)) - $(call GoCompiler/Host/CheckHost,$(HOST_GO_VALID_OS_ARCH)) - - mkdir -p "$(GO_BUILD_CACHE_DIR)" + TITLE:=Go programming language (dummy package) + BUILDONLY:=1 endef define Host/Compile - $(call GoCompiler/Bootstrap/Make, \ - $(HOST_GO_VARS) \ - CC="$(HOSTCC_NOCACHE) -std=gnu17" \ - ) - - $(call GoCompiler/Bootstrap-1.17/Make, \ - GOROOT_BOOTSTRAP="$(BOOTSTRAP_ROOT_DIR)" \ - $(HOST_GO_VARS) \ - ) - - $(call GoCompiler/Bootstrap-1.20/Make, \ - GOROOT_BOOTSTRAP="$(BOOTSTRAP_1_17_BUILD_DIR)" \ - $(HOST_GO_VARS) \ - ) - - $(call GoCompiler/Bootstrap-1.22/Make, \ - GOROOT_BOOTSTRAP="$(BOOTSTRAP_1_20_BUILD_DIR)" \ - $(HOST_GO_VARS) \ - ) - - $(call GoCompiler/Host/Make, \ - GOROOT_BOOTSTRAP="$(BOOTSTRAP_1_22_BUILD_DIR)" \ - $(if $(HOST_GO_ENABLE_PIE),GO_LDFLAGS="-buildmode pie") \ - $(HOST_GO_VARS) \ - ) endef -# if host and target os/arch are the same, -# when go compiles a program, it will use the host std lib -# so remove it now and force go to rebuild std for target later define Host/Install - $(call Host/Uninstall) - - $(call GoCompiler/Host/Install/Bin,) - $(call GoCompiler/Host/Install/Src,) - - $(call GoCompiler/Host/Install/BinLinks,) - - rm -rf "$(HOST_GO_ROOT)/pkg/$(GO_HOST_OS_ARCH)$(if $(HOST_GO_INSTALL_SUFFIX),_$(HOST_GO_INSTALL_SUFFIX))" - - $(INSTALL_DIR) "$(HOST_GO_ROOT)/openwrt" - $(INSTALL_BIN) ./files/go-gcc-helper "$(HOST_GO_ROOT)/openwrt/" - $(LN) go-gcc-helper "$(HOST_GO_ROOT)/openwrt/gcc" - $(LN) go-gcc-helper "$(HOST_GO_ROOT)/openwrt/g++" -endef - -define Host/Uninstall - rm -rf "$(HOST_GO_ROOT)/openwrt" - - $(call GoCompiler/Host/Uninstall/BinLinks,) - - $(call GoCompiler/Host/Uninstall,) endef - -# Target - -ifeq ($(GO_PKG_ENABLE_PIE),1) - PKG_GO_INSTALL_SUFFIX:=$(GO_TARGET_PIE_INSTALL_SUFFIX) -endif - -$(eval $(call GoCompiler/AddProfile,Package,$(PKG_BUILD_DIR),$(PKG_GO_PREFIX),$(PKG_GO_VERSION_ID),$(GO_OS_ARCH),$(PKG_GO_INSTALL_SUFFIX))) - -PKG_GO_ZBOOTSTRAP_MODS:= \ - s/defaultGO386 = `[^`]*`/defaultGO386 = `$(or $(GO_386),sse2)`/; \ - s/defaultGOAMD64 = `[^`]*`/defaultGOAMD64 = `$(or $(GO_AMD64),v1)`/; \ - s/defaultGOARM = `[^`]*`/defaultGOARM = `$(or $(GO_ARM),7)`/; \ - s/defaultGOARM64 = `[^`]*`/defaultGOARM64 = `$(or $(GO_ARM64),v8.0)`/; \ - s/defaultGOMIPS = `[^`]*`/defaultGOMIPS = `$(or $(GO_MIPS),hardfloat)`/; \ - s/defaultGOMIPS64 = `[^`]*`/defaultGOMIPS64 = `$(or $(GO_MIPS64),hardfloat)`/; \ - s/defaultGOPPC64 = `[^`]*`/defaultGOPPC64 = `$(or $(GO_PPC64),power8)`/; - -PKG_GO_ZBOOTSTRAP_PATH:=$(PKG_BUILD_DIR)/src/internal/buildcfg/zbootstrap.go - -PKG_GO_VARS= \ - GOHOSTARCH="$(GO_HOST_ARCH)" \ - GOCACHE="$(GO_BUILD_CACHE_DIR)" \ - GOENV=off \ - GO_GCC_HELPER_PATH="$$$$PATH" \ - CC=gcc \ - CXX=g++ \ - PKG_CONFIG=pkg-config \ - PATH="$(HOST_GO_ROOT)/openwrt:$$$$PATH" - -PKG_GO_GCFLAGS= \ - $(if $(GO_PKG_ENABLE_SPECTRE),-spectre all) - -PKG_GO_ASMFLAGS= \ - $(if $(GO_PKG_ENABLE_SPECTRE),-spectre all) - -PKG_GO_LDFLAGS= \ - -buildid '$(SOURCE_DATE_EPOCH)' \ - -linkmode external \ - -extldflags '$(patsubst -z%,-Wl$(comma)-z$(comma)%,$(TARGET_LDFLAGS))' \ - $(if $(CONFIG_NO_STRIP)$(CONFIG_DEBUG),,-s -w) - -PKG_GO_INSTALL_ARGS= \ - -buildvcs=false \ - -trimpath \ - -ldflags "all=$(PKG_GO_LDFLAGS)" \ - $(if $(PKG_GO_GCFLAGS),-gcflags "all=$(PKG_GO_GCFLAGS)") \ - $(if $(PKG_GO_ASMFLAGS),-asmflags "all=$(PKG_GO_ASMFLAGS)") \ - $(if $(filter $(GO_PKG_ENABLE_PIE),1),-buildmode pie) - -define Build/Configure - mkdir -p "$(GO_BUILD_CACHE_DIR)" -endef - -define Build/Compile - @echo "Building target Go first stage" - - $(call GoCompiler/Package/Make, \ - GOROOT_BOOTSTRAP="$(HOST_GO_ROOT)" \ - GO_GCC_HELPER_CC="$(HOSTCC)" \ - GO_GCC_HELPER_CXX="$(HOSTCXX)" \ - $(PKG_GO_VARS) \ - ) - - $(SED) '$(PKG_GO_ZBOOTSTRAP_MODS)' "$(PKG_GO_ZBOOTSTRAP_PATH)" - - ( \ - if echo 'int main() { return 0; }' | $(TARGET_CC) -o $(PKG_BUILD_DIR)/test-ldso -x c - > /dev/null 2>&1; then \ - LDSO=$$$$( \ - readelf -l $(PKG_BUILD_DIR)/test-ldso | \ - sed -n -e 's/^.*interpreter: \(.*\)[]]/\1/p' \ - ) ; \ - fi ; \ - $(SED) "s,defaultGO_LDSO = \`[^\`]*\`,defaultGO_LDSO = \`$$$$LDSO\`," "$(PKG_GO_ZBOOTSTRAP_PATH)" ; \ - ) - - @echo "Building target Go second stage" - - ( \ - cd "$(PKG_BUILD_DIR)/bin" ; \ - export $(GO_PKG_TARGET_VARS) ; \ - $(CP) go go-host ; \ - GO_GCC_HELPER_CC="$(TARGET_CC)" \ - GO_GCC_HELPER_CXX="$(TARGET_CXX)" \ - $(PKG_GO_VARS) \ - ./go-host install -a $(PKG_GO_INSTALL_ARGS) std cmd ; \ - retval="$$$$?" ; \ - rm -f go-host ; \ - exit "$$$$retval" ; \ - ) -endef - -define Package/golang/install - $(call GoCompiler/Package/Install/Bin,$(1)$(PKG_GO_PREFIX)) - $(call GoCompiler/Package/Install/BinLinks,$(1)$(PKG_GO_PREFIX)) -endef - -define Package/golang-doc/install - $(call GoCompiler/Package/Install/Doc,$(1)$(PKG_GO_PREFIX)) -endef - -define Package/golang-src/install - $(call GoCompiler/Package/Install/Src,$(1)$(PKG_GO_PREFIX)) -endef - -# src/debug contains ELF executables as test data -# and they reference these libraries -# we need to call this in Package/$(1)/extra_provides -# to pass CheckDependencies in include/package-ipkg.mk -define Package/golang-src/extra_provides - echo 'libc.so.6' -endef - - $(eval $(call HostBuild)) $(eval $(call BuildPackage,golang)) -$(eval $(call BuildPackage,golang-doc)) -$(eval $(call BuildPackage,golang-src)) diff --git a/lang/golang/golang/test.sh b/lang/golang/golang/test.sh deleted file mode 100644 index 114b427ef1528..0000000000000 --- a/lang/golang/golang/test.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -[ "$1" = golang ] || exit 0 - -go version | grep -F " go$PKG_VERSION " diff --git a/lang/golang/golang1.25/Makefile b/lang/golang/golang1.25/Makefile new file mode 100644 index 0000000000000..ea3ee26857831 --- /dev/null +++ b/lang/golang/golang1.25/Makefile @@ -0,0 +1,81 @@ +# +# Copyright (C) 2018-2023, Jeffery To +# Copyright (C) 2025-2026, George Sapkin +# +# SPDX-License-Identifier: GPL-2.0-only + +include $(TOPDIR)/rules.mk + +PKG_NAME:=golang1.25 +GO_VERSION_MAJOR_MINOR:=1.25 +GO_VERSION_PATCH:=6 +GO_BOOTSTRAP_VERSION:=bootstrap +PKG_HASH:=58cbf771e44d76de6f56d19e33b77d745a1e489340922875e46585b975c2b059 + +PKG_VERSION:=$(GO_VERSION_MAJOR_MINOR)$(if $(GO_VERSION_PATCH),.$(GO_VERSION_PATCH)) +PKG_RELEASE:=1 + +GO_SOURCE_URLS:=https://go.dev/dl/ \ + https://dl.google.com/go/ \ + https://golang.google.cn/dl/ \ + https://mirrors.nju.edu.cn/golang/ \ + https://mirrors.ustc.edu.cn/golang/ + +PKG_SOURCE:=go$(PKG_VERSION).src.tar.gz +PKG_SOURCE_URL:=$(GO_SOURCE_URLS) + +PKG_MAINTAINER:=George Sapkin +PKG_LICENSE:=BSD-3-Clause +PKG_LICENSE_FILES:=LICENSE +PKG_CPE_ID:=cpe:/a:golang:go + +PKG_BUILD_DEPENDS:=$(PKG_NAME)/host +PKG_BUILD_DIR:=$(BUILD_DIR)/go-$(PKG_VERSION) +PKG_BUILD_PARALLEL:=1 +PKG_BUILD_FLAGS:=no-mips16 + +PKG_GO_PREFIX:=/usr +PKG_GO_VERSION_ID:=$(GO_VERSION_MAJOR_MINOR) + +HOST_BUILD_DEPENDS:=golang$(if $(filter bootstrap,$(GO_BOOTSTRAP_VERSION)),-)$(GO_BOOTSTRAP_VERSION)/host +HOST_BUILD_DIR:=$(BUILD_DIR_HOST)/go-$(PKG_VERSION) +HOST_BUILD_PARALLEL:=1 + +HOST_GO_VALID_OS_ARCH:= \ + android_386 android_amd64 android_arm android_arm64 \ + freebsd_386 freebsd_amd64 freebsd_arm freebsd_arm64 \ + linux_386 linux_amd64 linux_arm linux_arm64 \ + openbsd_386 openbsd_amd64 openbsd_arm openbsd_arm64 \ + netbsd_386 netbsd_amd64 netbsd_arm netbsd_arm64 \ + windows_386 windows_amd64 windows_arm windows_arm64 \ + \ + plan9_386 plan9_amd64 plan9_arm \ + \ + darwin_amd64 darwin_arm64 \ + ios_amd64 ios_arm64 \ + \ + dragonfly_amd64 \ + illumos_amd64 \ + solaris_amd64 \ + \ + aix_ppc64 \ + js_wasm \ + wasip1_wasm \ + \ + freebsd_riscv64 \ + openbsd_riscv64 \ + \ + linux_ppc64 linux_ppc64le \ + linux_mips linux_mipsle linux_mips64 linux_mips64le \ + linux_loong64 linux_riscv64 linux_s390x \ + \ + openbsd_mips64 + +include $(INCLUDE_DIR)/host-build.mk +include $(INCLUDE_DIR)/package.mk +include ../golang-version.mk + +$(eval $(call HostBuild)) +$(eval $(call BuildPackage,$(PKG_NAME))) +$(eval $(call BuildPackage,$(PKG_NAME)-doc)) +$(eval $(call BuildPackage,$(PKG_NAME)-src)) diff --git a/lang/golang/golang1.25/test.sh b/lang/golang/golang1.25/test.sh new file mode 100644 index 0000000000000..e7c4a8122e045 --- /dev/null +++ b/lang/golang/golang1.25/test.sh @@ -0,0 +1,9 @@ +#!/bin/sh +# +# SPDX-License-Identifier: GPL-2.0-only + +case "$1" in + golang*doc|golang*src) exit ;; +esac + +go version | grep -F " go$PKG_VERSION "