golang: update to 1.22.2
[feed/packages.git] / lang / golang / golang / Makefile
1 #
2 # Copyright (C) 2018-2023 Jeffery To
3 #
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
6 #
7
8 include $(TOPDIR)/rules.mk
9
10 GO_VERSION_MAJOR_MINOR:=1.22
11 GO_VERSION_PATCH:=2
12
13 PKG_NAME:=golang
14 PKG_VERSION:=$(GO_VERSION_MAJOR_MINOR)$(if $(GO_VERSION_PATCH),.$(GO_VERSION_PATCH))
15 PKG_RELEASE:=1
16
17 GO_SOURCE_URLS:=https://dl.google.com/go/ \
18 https://mirrors.ustc.edu.cn/golang/ \
19 https://mirrors.nju.edu.cn/golang/
20
21 PKG_SOURCE:=go$(PKG_VERSION).src.tar.gz
22 PKG_SOURCE_URL:=$(GO_SOURCE_URLS)
23 PKG_HASH:=374ea82b289ec738e968267cac59c7d5ff180f9492250254784b2044e90df5a9
24
25 PKG_MAINTAINER:=Jeffery To <jeffery.to@gmail.com>
26 PKG_LICENSE:=BSD-3-Clause
27 PKG_LICENSE_FILES:=LICENSE
28 PKG_CPE_ID:=cpe:/a:golang:go
29
30 PKG_BUILD_DEPENDS:=golang/host
31 PKG_BUILD_DIR:=$(BUILD_DIR)/go-$(PKG_VERSION)
32 PKG_BUILD_PARALLEL:=1
33 PKG_BUILD_FLAGS:=no-mips16
34
35 PKG_GO_PREFIX:=/usr
36 PKG_GO_VERSION_ID:=$(GO_VERSION_MAJOR_MINOR)
37 PKG_GO_ROOT:=$(PKG_GO_PREFIX)/lib/go-$(PKG_GO_VERSION_ID)
38
39 HOST_BUILD_DIR:=$(BUILD_DIR_HOST)/go-$(PKG_VERSION)
40 HOST_BUILD_PARALLEL:=1
41
42 HOST_GO_PREFIX:=$(STAGING_DIR_HOSTPKG)
43 HOST_GO_VERSION_ID:=cross
44 HOST_GO_ROOT:=$(HOST_GO_PREFIX)/lib/go-$(HOST_GO_VERSION_ID)
45
46 HOST_GO_VALID_OS_ARCH:= \
47 android_386 android_amd64 android_arm android_arm64 \
48 freebsd_386 freebsd_amd64 freebsd_arm freebsd_arm64 \
49 linux_386 linux_amd64 linux_arm linux_arm64 \
50 openbsd_386 openbsd_amd64 openbsd_arm openbsd_arm64 \
51 netbsd_386 netbsd_amd64 netbsd_arm netbsd_arm64 \
52 windows_386 windows_amd64 windows_arm windows_arm64 \
53 \
54 plan9_386 plan9_amd64 plan9_arm \
55 \
56 darwin_amd64 darwin_arm64 \
57 ios_amd64 ios_arm64 \
58 \
59 dragonfly_amd64 \
60 illumos_amd64 \
61 solaris_amd64 \
62 \
63 aix_ppc64 \
64 js_wasm \
65 wasip1_wasm \
66 \
67 freebsd_riscv64 \
68 \
69 linux_ppc64 linux_ppc64le \
70 linux_mips linux_mipsle linux_mips64 linux_mips64le \
71 linux_loong64 linux_riscv64 linux_s390x \
72 \
73 openbsd_mips64
74
75 BOOTSTRAP_SOURCE:=go1.4-bootstrap-20171003.tar.gz
76 BOOTSTRAP_SOURCE_URL:=$(GO_SOURCE_URLS)
77 BOOTSTRAP_HASH:=f4ff5b5eb3a3cae1c993723f3eab519c5bae18866b5e5f96fe1102f0cb5c3e52
78
79 BOOTSTRAP_BUILD_DIR:=$(HOST_BUILD_DIR)/.go_bootstrap
80
81 BOOTSTRAP_GO_VALID_OS_ARCH:= \
82 darwin_386 darwin_amd64 \
83 dragonfly_386 dragonfly_amd64 \
84 freebsd_386 freebsd_amd64 freebsd_arm \
85 linux_386 linux_amd64 linux_arm \
86 netbsd_386 netbsd_amd64 netbsd_arm \
87 openbsd_386 openbsd_amd64 \
88 plan9_386 plan9_amd64 \
89 solaris_amd64 \
90 windows_386 windows_amd64
91
92 BOOTSTRAP_1_17_SOURCE:=go1.17.13.src.tar.gz
93 BOOTSTRAP_1_17_SOURCE_URL:=$(GO_SOURCE_URLS)
94 BOOTSTRAP_1_17_HASH:=a1a48b23afb206f95e7bbaa9b898d965f90826f6f1d1fc0c1d784ada0cd300fd
95
96 BOOTSTRAP_1_17_BUILD_DIR:=$(HOST_BUILD_DIR)/.go_bootstrap_1.17
97
98 BOOTSTRAP_1_20_SOURCE:=go1.20.14.src.tar.gz
99 BOOTSTRAP_1_20_SOURCE_URL:=$(GO_SOURCE_URLS)
100 BOOTSTRAP_1_20_HASH:=1aef321a0e3e38b7e91d2d7eb64040666cabdcc77d383de3c9522d0d69b67f4e
101
102 BOOTSTRAP_1_20_BUILD_DIR:=$(HOST_BUILD_DIR)/.go_bootstrap_1.20
103
104 include $(INCLUDE_DIR)/host-build.mk
105 include $(INCLUDE_DIR)/package.mk
106 include ../golang-compiler.mk
107 include ../golang-package.mk
108
109 PKG_UNPACK:=$(HOST_TAR) -C "$(PKG_BUILD_DIR)" --strip-components=1 -xzf "$(DL_DIR)/$(PKG_SOURCE)"
110 HOST_UNPACK:=$(HOST_TAR) -C "$(HOST_BUILD_DIR)" --strip-components=1 -xzf "$(DL_DIR)/$(PKG_SOURCE)"
111 BOOTSTRAP_UNPACK:=$(HOST_TAR) -C "$(BOOTSTRAP_BUILD_DIR)" --strip-components=1 -xzf "$(DL_DIR)/$(BOOTSTRAP_SOURCE)"
112 BOOTSTRAP_1_17_UNPACK:=$(HOST_TAR) -C "$(BOOTSTRAP_1_17_BUILD_DIR)" --strip-components=1 -xzf "$(DL_DIR)/$(BOOTSTRAP_1_17_SOURCE)"
113 BOOTSTRAP_1_20_UNPACK:=$(HOST_TAR) -C "$(BOOTSTRAP_1_20_BUILD_DIR)" --strip-components=1 -xzf "$(DL_DIR)/$(BOOTSTRAP_1_20_SOURCE)"
114
115 # don't strip ELF executables in test data
116 RSTRIP:=:
117 STRIP:=:
118
119 ifeq ($(GO_TARGET_SPECTRE_SUPPORTED),1)
120 PKG_CONFIG_DEPENDS+=CONFIG_GOLANG_SPECTRE
121 endif
122
123 define Package/golang/Default
124 $(call GoPackage/GoSubMenu)
125 TITLE:=Go programming language
126 URL:=https://go.dev/
127 DEPENDS:=$(GO_ARCH_DEPENDS)
128 endef
129
130 define Package/golang/Default/description
131 The Go programming language is an open source project to make
132 programmers more productive.
133
134 Go is expressive, concise, clean, and efficient. Its concurrency
135 mechanisms make it easy to write programs that get the most out of
136 multicore and networked machines, while its novel type system enables
137 flexible and modular program construction. Go compiles quickly to
138 machine code yet has the convenience of garbage collection and the power
139 of run-time reflection. It's a fast, statically typed, compiled language
140 that feels like a dynamically typed, interpreted language.
141 endef
142
143 # go tool requires source present:
144 # https://github.com/golang/go/issues/4635
145 define Package/golang
146 $(call Package/golang/Default)
147 TITLE+= (compiler)
148 DEPENDS+= +golang-src
149 endef
150
151 define Package/golang/description
152 $(call Package/golang/Default/description)
153
154 This package provides an assembler, compiler, linker, and compiled
155 libraries for the Go programming language.
156 endef
157
158 define Package/golang/config
159 source "$(SOURCE)/Config.in"
160 endef
161
162 define Package/golang-doc
163 $(call Package/golang/Default)
164 TITLE+= (documentation)
165 endef
166
167 define Package/golang-doc/description
168 $(call Package/golang/Default/description)
169
170 This package provides the documentation for the Go programming language.
171 endef
172
173 define Package/golang-src
174 $(call Package/golang/Default)
175 TITLE+= (source files)
176 endef
177
178 define Package/golang-src/description
179 $(call Package/golang/Default/description)
180
181 This package provides the Go programming language source files needed
182 for cross-compilation.
183 endef
184
185
186 # Bootstrap
187
188 BOOTSTRAP_ROOT_DIR:=$(call qstrip,$(CONFIG_GOLANG_EXTERNAL_BOOTSTRAP_ROOT))
189
190 ifeq ($(BOOTSTRAP_ROOT_DIR),)
191 BOOTSTRAP_ROOT_DIR:=$(BOOTSTRAP_BUILD_DIR)
192
193 define Download/golang-bootstrap
194 FILE:=$(BOOTSTRAP_SOURCE)
195 URL:=$(BOOTSTRAP_SOURCE_URL)
196 HASH:=$(BOOTSTRAP_HASH)
197 endef
198 $(eval $(call Download,golang-bootstrap))
199
200 define Bootstrap/Prepare
201 mkdir -p "$(BOOTSTRAP_BUILD_DIR)" && $(BOOTSTRAP_UNPACK) ;
202 endef
203 Hooks/HostPrepare/Post+=Bootstrap/Prepare
204
205 $(eval $(call GoCompiler/AddProfile,Bootstrap,$(BOOTSTRAP_BUILD_DIR),,bootstrap,$(GO_HOST_OS_ARCH)))
206 endif
207
208
209 # Bootstrap 1.17
210
211 define Download/golang-bootstrap-1.17
212 FILE:=$(BOOTSTRAP_1_17_SOURCE)
213 URL:=$(BOOTSTRAP_1_17_SOURCE_URL)
214 HASH:=$(BOOTSTRAP_1_17_HASH)
215 endef
216 $(eval $(call Download,golang-bootstrap-1.17))
217
218 define Bootstrap-1.17/Prepare
219 mkdir -p "$(BOOTSTRAP_1_17_BUILD_DIR)" && $(BOOTSTRAP_1_17_UNPACK) ;
220 endef
221 Hooks/HostPrepare/Post+=Bootstrap-1.17/Prepare
222
223 $(eval $(call GoCompiler/AddProfile,Bootstrap-1.17,$(BOOTSTRAP_1_17_BUILD_DIR),,bootstrap-1.17,$(GO_HOST_OS_ARCH)))
224
225
226 # Bootstrap 1.20
227
228 define Download/golang-bootstrap-1.20
229 FILE:=$(BOOTSTRAP_1_20_SOURCE)
230 URL:=$(BOOTSTRAP_1_20_SOURCE_URL)
231 HASH:=$(BOOTSTRAP_1_20_HASH)
232 endef
233 $(eval $(call Download,golang-bootstrap-1.20))
234
235 define Bootstrap-1.20/Prepare
236 mkdir -p "$(BOOTSTRAP_1_20_BUILD_DIR)" && $(BOOTSTRAP_1_20_UNPACK) ;
237 endef
238 Hooks/HostPrepare/Post+=Bootstrap-1.20/Prepare
239
240 $(eval $(call GoCompiler/AddProfile,Bootstrap-1.20,$(BOOTSTRAP_1_20_BUILD_DIR),,bootstrap-1.20,$(GO_HOST_OS_ARCH)))
241
242 # Host
243
244 ifeq ($(GO_HOST_PIE_SUPPORTED),1)
245 HOST_GO_ENABLE_PIE:=1
246 endif
247
248 # when using GO_LDFLAGS to set buildmode=pie, the PIE install suffix
249 # does not apply (we also delete the std lib during Host/Install)
250
251 $(eval $(call GoCompiler/AddProfile,Host,$(HOST_BUILD_DIR),$(HOST_GO_PREFIX),$(HOST_GO_VERSION_ID),$(GO_HOST_OS_ARCH),$(HOST_GO_INSTALL_SUFFIX)))
252
253 HOST_GO_VARS= \
254 GOHOSTARCH="$(GO_HOST_ARCH)" \
255 GOCACHE="$(GO_BUILD_CACHE_DIR)" \
256 GOENV=off \
257 CC="$(HOSTCC_NOCACHE)" \
258 CXX="$(HOSTCXX_NOCACHE)"
259
260 define Host/Configure
261 $(call GoCompiler/Bootstrap/CheckHost,$(BOOTSTRAP_GO_VALID_OS_ARCH))
262 $(call GoCompiler/Host/CheckHost,$(HOST_GO_VALID_OS_ARCH))
263
264 mkdir -p "$(GO_BUILD_CACHE_DIR)"
265 endef
266
267 define Host/Compile
268 $(call GoCompiler/Bootstrap/Make, \
269 $(HOST_GO_VARS) \
270 )
271
272 $(call GoCompiler/Bootstrap-1.17/Make, \
273 GOROOT_BOOTSTRAP="$(BOOTSTRAP_ROOT_DIR)" \
274 $(HOST_GO_VARS) \
275 )
276
277 $(call GoCompiler/Bootstrap-1.20/Make, \
278 GOROOT_BOOTSTRAP="$(BOOTSTRAP_1_17_BUILD_DIR)" \
279 $(HOST_GO_VARS) \
280 )
281
282 $(call GoCompiler/Host/Make, \
283 GOROOT_BOOTSTRAP="$(BOOTSTRAP_1_20_BUILD_DIR)" \
284 $(if $(HOST_GO_ENABLE_PIE),GO_LDFLAGS="-buildmode pie") \
285 $(HOST_GO_VARS) \
286 )
287 endef
288
289 # if host and target os/arch are the same,
290 # when go compiles a program, it will use the host std lib
291 # so remove it now and force go to rebuild std for target later
292 define Host/Install
293 $(call Host/Uninstall)
294
295 $(call GoCompiler/Host/Install/Bin,)
296 $(call GoCompiler/Host/Install/Src,)
297
298 $(call GoCompiler/Host/Install/BinLinks,)
299
300 rm -rf "$(HOST_GO_ROOT)/pkg/$(GO_HOST_OS_ARCH)$(if $(HOST_GO_INSTALL_SUFFIX),_$(HOST_GO_INSTALL_SUFFIX))"
301
302 $(INSTALL_DIR) "$(HOST_GO_ROOT)/openwrt"
303 $(INSTALL_BIN) ./files/go-gcc-helper "$(HOST_GO_ROOT)/openwrt/"
304 $(LN) go-gcc-helper "$(HOST_GO_ROOT)/openwrt/gcc"
305 $(LN) go-gcc-helper "$(HOST_GO_ROOT)/openwrt/g++"
306 endef
307
308 define Host/Uninstall
309 rm -rf "$(HOST_GO_ROOT)/openwrt"
310
311 $(call GoCompiler/Host/Uninstall/BinLinks,)
312
313 $(call GoCompiler/Host/Uninstall,)
314 endef
315
316
317 # Target
318
319 ifeq ($(GO_PKG_ENABLE_PIE),1)
320 PKG_GO_INSTALL_SUFFIX:=$(GO_TARGET_PIE_INSTALL_SUFFIX)
321 endif
322
323 $(eval $(call GoCompiler/AddProfile,Package,$(PKG_BUILD_DIR),$(PKG_GO_PREFIX),$(PKG_GO_VERSION_ID),$(GO_OS_ARCH),$(PKG_GO_INSTALL_SUFFIX)))
324
325 PKG_GO_ZBOOTSTRAP_MODS:= \
326 s/defaultGO386 = `[^`]*`/defaultGO386 = `$(or $(GO_386),sse2)`/; \
327 s/defaultGOAMD64 = `[^`]*`/defaultGOAMD64 = `$(or $(GO_AMD64),v1)`/; \
328 s/defaultGOARM = `[^`]*`/defaultGOARM = `$(or $(GO_ARM),7)`/; \
329 s/defaultGOMIPS = `[^`]*`/defaultGOMIPS = `$(or $(GO_MIPS),hardfloat)`/; \
330 s/defaultGOMIPS64 = `[^`]*`/defaultGOMIPS64 = `$(or $(GO_MIPS64),hardfloat)`/; \
331 s/defaultGOPPC64 = `[^`]*`/defaultGOPPC64 = `$(or $(GO_PPC64),power8)`/;
332
333 PKG_GO_ZBOOTSTRAP_PATH:=$(PKG_BUILD_DIR)/src/internal/buildcfg/zbootstrap.go
334
335 PKG_GO_VARS= \
336 GOHOSTARCH="$(GO_HOST_ARCH)" \
337 GOCACHE="$(GO_BUILD_CACHE_DIR)" \
338 GOENV=off \
339 GO_GCC_HELPER_PATH="$$$$PATH" \
340 CC=gcc \
341 CXX=g++ \
342 PKG_CONFIG=pkg-config \
343 PATH="$(HOST_GO_ROOT)/openwrt:$$$$PATH"
344
345 PKG_GO_GCFLAGS= \
346 $(if $(GO_PKG_ENABLE_SPECTRE),-spectre all)
347
348 PKG_GO_ASMFLAGS= \
349 $(if $(GO_PKG_ENABLE_SPECTRE),-spectre all)
350
351 PKG_GO_LDFLAGS= \
352 -buildid '$(SOURCE_DATE_EPOCH)' \
353 -linkmode external \
354 -extldflags '$(patsubst -z%,-Wl$(comma)-z$(comma)%,$(TARGET_LDFLAGS))' \
355 $(if $(CONFIG_NO_STRIP)$(CONFIG_DEBUG),,-s -w)
356
357 PKG_GO_INSTALL_ARGS= \
358 -buildvcs=false \
359 -trimpath \
360 -ldflags "all=$(PKG_GO_LDFLAGS)" \
361 $(if $(PKG_GO_GCFLAGS),-gcflags "all=$(PKG_GO_GCFLAGS)") \
362 $(if $(PKG_GO_ASMFLAGS),-asmflags "all=$(PKG_GO_ASMFLAGS)") \
363 $(if $(filter $(GO_PKG_ENABLE_PIE),1),-buildmode pie)
364
365 define Build/Configure
366 mkdir -p "$(GO_BUILD_CACHE_DIR)"
367 endef
368
369 define Build/Compile
370 @echo "Building target Go first stage"
371
372 $(call GoCompiler/Package/Make, \
373 GOROOT_BOOTSTRAP="$(HOST_GO_ROOT)" \
374 GO_GCC_HELPER_CC="$(HOSTCC)" \
375 GO_GCC_HELPER_CXX="$(HOSTCXX)" \
376 $(PKG_GO_VARS) \
377 )
378
379 $(SED) '$(PKG_GO_ZBOOTSTRAP_MODS)' "$(PKG_GO_ZBOOTSTRAP_PATH)"
380
381 ( \
382 if echo 'int main() { return 0; }' | $(TARGET_CC) -o $(PKG_BUILD_DIR)/test-ldso -x c - > /dev/null 2>&1; then \
383 LDSO=$$$$( \
384 readelf -l $(PKG_BUILD_DIR)/test-ldso | \
385 sed -n -e 's/^.*interpreter: \(.*\)[]]/\1/p' \
386 ) ; \
387 fi ; \
388 $(SED) "s,defaultGO_LDSO = \`[^\`]*\`,defaultGO_LDSO = \`$$$$LDSO\`," "$(PKG_GO_ZBOOTSTRAP_PATH)" ; \
389 )
390
391 @echo "Building target Go second stage"
392
393 ( \
394 cd "$(PKG_BUILD_DIR)/bin" ; \
395 export $(GO_PKG_TARGET_VARS) ; \
396 $(CP) go go-host ; \
397 GOROOT_FINAL="$(PKG_GO_ROOT)" \
398 GO_GCC_HELPER_CC="$(TARGET_CC)" \
399 GO_GCC_HELPER_CXX="$(TARGET_CXX)" \
400 $(PKG_GO_VARS) \
401 ./go-host install -a $(PKG_GO_INSTALL_ARGS) std cmd ; \
402 retval="$$$$?" ; \
403 rm -f go-host ; \
404 exit "$$$$retval" ; \
405 )
406 endef
407
408 define Package/golang/install
409 $(call GoCompiler/Package/Install/Bin,$(1)$(PKG_GO_PREFIX))
410 $(call GoCompiler/Package/Install/BinLinks,$(1)$(PKG_GO_PREFIX))
411 endef
412
413 define Package/golang-doc/install
414 $(call GoCompiler/Package/Install/Doc,$(1)$(PKG_GO_PREFIX))
415 endef
416
417 define Package/golang-src/install
418 $(call GoCompiler/Package/Install/Src,$(1)$(PKG_GO_PREFIX))
419 endef
420
421 # src/debug contains ELF executables as test data
422 # and they reference these libraries
423 # we need to call this in Package/$(1)/extra_provides
424 # to pass CheckDependencies in include/package-ipkg.mk
425 define Package/golang-src/extra_provides
426 echo 'libc.so.6'
427 endef
428
429
430 $(eval $(call HostBuild))
431 $(eval $(call BuildPackage,golang))
432 $(eval $(call BuildPackage,golang-doc))
433 $(eval $(call BuildPackage,golang-src))