package/golang: new package
PATCH 1/1 package/golang: new package
From: Christian Stewart <[email protected]>
This patch adds golang, the Go compiler-and-interpreter.
We're adding a host package to get the golang cross-compiler, and a target package to get the golang interpreter on the target.
It is to be noted that golang's buildsystem is going at great length to not do anything like any other buildsystem, and is full of little tricks.
First-off, even though it generates code for the target, the host-variant does not need the toolchain; it has its own built-in code generator. Yet, building the target variant, the toolchain is indeed required. Weird...
Second, it misdetects cross-compilation: it considers that if the target CPU and the build CPU are the same, then this is not cross-compilation. Of course, this is completely stupid and wrong. So, we need to patch it to override its insane heuristic.
Third, even so, when the target CPU is the same as the build CPU, the resulting binaries will be dynamically linked, otherwise, they are statically linked. We can't even force it one way or the other... Instead, we mark it as requiring dynamic libraries, and let the golang ill buildsystem decide whether to do static or dynamic link; we can do so because any sane toolchain will always have the static variants of the libc and libpthread, which is all that golang requires anyway.
[yann.morin.1998 at free.fr:
- add architecture-specific options
- needs dynamic linking
- fix tab-space indentation in patch 0003
- fix licensing info
]
--- package/Config.in | 1 + package/golang/0001-add-no-march-option-gccp.patch | 19 +++++ .../0002-remove-unnecessary-march-ld-flag.patch | 29 +++++++ package/golang/0003-fix-make-bash-script.patch | 46 +++++++++++ package/golang/Config.in | 22 ++++++ package/golang/golang.hash | 1 + package/golang/golang.mk | 91 ++++++++++++++++++++++ 7 files changed, 209 insertions(+) create mode 100644 package/golang/0001-add-no-march-option-gccp.patch create mode 100644 package/golang/0002-remove-unnecessary-march-ld-flag.patch create mode 100644 package/golang/0003-fix-make-bash-script.patch create mode 100644 package/golang/Config.in create mode 100644 package/golang/golang.hash create mode 100644 package/golang/golang.mk
package/Config.in +1 -0
@@ -460,6 +460,7 @@ menu "Erlang libraries/modules" source "package/erlang-p1-zlib/Config.in" endmenu endif + source "package/golang/Config.in" source "package/guile/Config.in" source "package/haserl/Config.in" source "package/jamvm/Config.in"
package/golang/0001-add-no-march-option-gccp.patch new file +19 -0
@@ -0,0 +1,19 @@ +Adds an option to not add the problematic -m parameter to GCC. + +Signed-off-by: Christian Stewart <[email protected]> + +diff -Nau golang.orig/src/cmd/cgo/gcc.go golang/src/cmd/cgo/gcc.go +--- golang.orig/src/cmd/cgo/gcc.go.orig 2015-07-09 15:53:55.720794139 -0700 ++++ golang/src/cmd/cgo/gcc.go 2015-07-09 17:46:43.664496374 -0700 +@@ -736,6 +736,11 @@ + + // gccMachine returns the gcc -m flag to use, either "-m32", "-m64" or "-marm". + func (p *Package) gccMachine() []string { ++ ++ if os.Getenv("CGO_NO_EMULATION") == "1" { ++ return nil ++ } ++ + switch goarch { + case "amd64": + return []string{"-m64"}
package/golang/0002-remove-unnecessary-march-ld-flag.patch new file +29 -0
@@ -0,0 +1,29 @@ +Removes defining -m parameter to LD, which is unnecessary in buildroot. + +Signed-off-by: Christian Stewart <[email protected]> + +diff -Nau golang.orig/src/cmd/ld/lib.c golang/src/cmd/ld/lib.c +--- golang.orig/src/cmd/ld/lib.c.orig 2015-07-09 18:38:44.192359082 -0700 ++++ golang/src/cmd/ld/lib.c 2015-07-09 18:39:02.108358294 -0700 +@@ -589,20 +589,7 @@ + if(extld == nil) + extld = "gcc"; + argv[argc++] = extld; +- switch(thechar){ +- case '8': +- argv[argc++] = "-m32"; +- break; +- case '6': +- argv[argc++] = "-m64"; +- break; +- case '5': +- argv[argc++] = "-marm"; +- break; +- } +- if(!debug['s'] && !debug_s) { +- argv[argc++] = "-gdwarf-2"; +- } else { ++ if(debug['s'] || debug_s) { + argv[argc++] = "-s"; + } + if(HEADTYPE == Hdarwin)
package/golang/0003-fix-make-bash-script.patch new file +46 -0
46 lines not on this page · raw message
package/golang/Config.in new file +22 -0
@@ -0,0 +1,22 @@ +comment "golang needs a toolchain w/ threads, dynamic library" + depends on BR2_PACKAGE_GOLANG_ARCH_SUPPORTS + depends on !BR2_TOOLCHAIN_HAS_THREADS || BR2_STATIC_LIBS + +# golang only supports x86, x86_64 and ARM (LE) targets. +# For ARM, armv5 or above is required. +config BR2_PACKAGE_GOLANG_ARCH_SUPPORTS + bool + default y + depends on BR2_USE_MMU + depends on BR2_i386 || BR2_x86_64 || BR2_arm + depends on !BR2_ARM_CPU_ARMV4 + +config BR2_PACKAGE_GOLANG + bool "golang" + depends on BR2_PACKAGE_GOLANG_ARCH_SUPPORTS + depends on !BR2_STATIC_LIBS + depends on BR2_TOOLCHAIN_HAS_THREADS + help + Go compiler and cli tool. + + http://golang.org/
package/golang/golang.hash new file +1 -0
@@ -0,0 +1 @@ +sha1 460caac03379f746c473814a65223397e9c9a2f6 go1.4.2.src.tar.gz
package/golang/golang.mk new file +91 -0
91 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH 1/1 package/golang: new package
Dear Yann E. MORIN,
package/golang/golang.hash
Quoted 6 lines · Yann E. MORIN
package/golang/golang.hash new file +0
-0@@ -0,0 +1 @@
Origin of the hash?
package/golang/golang.hash line 1
Quoted 1 line
package/golang/golang.hash new file +1
-0+GOLANG_ARCH =
Defining a variable to nothing is not very useful I believe.
Quoted 18 lines
package/golang/golang.hash new file +18
-0+GOLANG_ENV = \ + CC_FOR_TARGET="$(TARGET_CC)" \ + LD_FOR_TARGET="$(TARGET_LD)" \ + GOOS=linux + +ifeq ($(BR2_i386),y) +GOLANG_ARCH = 386 +ifeq ($(BR2_X86_CPU_HAS_SSE2),y) +GOLANG_ENV += GO386=sse2 +else +GOLANG_ENV += GO386=387 +endif +endif # i386 + +ifeq ($(BR2_x86_64),y) +GOLANG_ARCH = amd64 +endif # x86_64 +
package/golang/golang.hash
Quoted 10 lines
package/golang/golang.hash new file +10
-0+# For ARM, the selection of the instruciton set is a bit unusual, +# and is decided on whether the CPU has an FPU, and which one. +ifeq ($(BR2_arm),y) +GOLANG_ARCH = arm +ifeq ($(BR2_ARM_CPU_HAS_VFPV3),y) +GOLANG_ENV += GOARM=7 +else ifeq ($(BR2_ARM_CPU_HAS_VFPV2),y) +GOLANG_ENV += GOARM=6 +else +GOLANG_ENV += GOARM=5
Are you sure using VFPV3/VFPV2 is correct here? Looking at the GOARM values, it seems really like you're trying to check if we're building for ARMv5, ARMv6 or ARMv7. So what about using BR2_ARM_CPU_ARMV5, BR2_ARM_CPU_ARMV6 and BR2_ARM_CPU_ARMV7 instead ?
package/golang/golang.hash
Quoted 6 lines
package/golang/golang.hash new file +6
-0+define GOLANG_BUILD_CMDS + cd $(@D)/src/; \ + $(GOLANG_ENV) \ + GOROOT_FINAL="/usr/lib/go" \ + GO_NO_HOST=1 \ + ./make.bash --no-banner
Indent the lines after the cd, maybe, and do not excessively split lines.
cd $(@D)/src && \ $(GOLANG_ENV) GOROOT_FINAL="/usr/lib/go" GO_NO_HOST=1 \ ./make.bash --no-banner
package/golang/golang.hash
Quoted 6 lines
package/golang/golang.hash new file +6
-0+# We must install both the src/ and include/ subdirs because they +# contain the go "runtime". +define GOLANG_INSTALL_TARGET_CMDS + $(INSTALL) -D -m 0755 $(@D)/bin/linux_$(GOLANG_ARCH)/go $(TARGET_DIR)/usr/bin/go + $(INSTALL) -D -m 0755 $(@D)/bin/linux_$(GOLANG_ARCH)/gofmt $(TARGET_DIR)/usr/bin/gofmt + rm -rf $(TARGET_DIR)/usr/lib/go/
Why this rm -rf ?
package/golang/golang.hash
Quoted 12 lines
package/golang/golang.hash new file +12
-0+ mkdir -p $(TARGET_DIR)/usr/lib/go/ + cp -a $(@D)/src $(TARGET_DIR)/usr/lib/go/ + cp -a $(@D)/include $(TARGET_DIR)/usr/lib/go/ + cp -a $(@D)/pkg $(TARGET_DIR)/usr/lib/go/ +endef + +define HOST_GOLANG_BUILD_CMDS + cd $(@D)/src/ ; \ + $(GOLANG_ENV) \ + GOROOT_FINAL="$(HOST_DIR)/usr/lib/go" \ + GO_NO_TARGET=1 \ + ./make.bash --no-banner
Ditto above.
Quoted 16 lines
package/golang/golang.hash new file +16
-0+endef + +# We must install both the src/ and include/ subdirs because they +# contain the go "runtime" +define HOST_GOLANG_INSTALL_CMDS + $(INSTALL) -D -m 0755 $(@D)/bin/host/go $(HOST_DIR)/usr/bin/go + $(INSTALL) -D -m 0755 $(@D)/bin/host/gofmt $(HOST_DIR)/usr/bin/gofmt + rm -rf $(HOST_DIR)/usr/lib/go/ + mkdir -p $(HOST_DIR)/usr/lib/go/ + cp -a $(@D)/src $(HOST_DIR)/usr/lib/go/ + cp -a $(@D)/include $(HOST_DIR)/usr/lib/go/ + cp -a $(@D)/pkg $(HOST_DIR)/usr/lib/go/ +endef + +$(eval $(generic-package)) +$(eval $(host-generic-package))
Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons Embedded Linux, Kernel and Android engineering http://free-electrons.com
PATCH 1/1 package/golang: new package
Thomas, All,
On 2015-07-29 23:12 +0200, Thomas Petazzoni spake thusly:
Quoted 9 lines · Yann E. MORIN
package/golang/golang.hash
Quoted 6 lines
package/golang/golang.hash new file +0
-0@@ -0,0 +1 @@Origin of the hash?
Right.
Quoted 3 lines
package/golang/golang.hash line 1
Quoted 1 line
package/golang/golang.hash new file +1
-0+GOLANG_ARCH =Defining a variable to nothing is not very useful I believe.
Right.
Quoted 25 lines
Quoted 25 lines
package/golang/golang.hash new file +25
-0+GOLANG_ENV = \ + CC_FOR_TARGET="$(TARGET_CC)" \ + LD_FOR_TARGET="$(TARGET_LD)" \ + GOOS=linux + +ifeq ($(BR2_i386),y) +GOLANG_ARCH = 386 +ifeq ($(BR2_X86_CPU_HAS_SSE2),y) +GOLANG_ENV += GO386=sse2 +else +GOLANG_ENV += GO386=387 +endif +endif # i386 + +ifeq ($(BR2_x86_64),y) +GOLANG_ARCH = amd64 +endif # x86_64 + +# For ARM, the selection of the instruciton set is a bit unusual, +# and is decided on whether the CPU has an FPU, and which one. +ifeq ($(BR2_arm),y) +GOLANG_ARCH = arm +ifeq ($(BR2_ARM_CPU_HAS_VFPV3),y) +GOLANG_ENV += GOARM=7 +else ifeq ($(BR2_ARM_CPU_HAS_VFPV2),y)
Quoted 8 lines
package/golang/golang.hash
Quoted 3 lines
package/golang/golang.hash new file +3
-0+GOLANG_ENV += GOARM=6 +else +GOLANG_ENV += GOARM=5Are you sure using VFPV3/VFPV2 is correct here? Looking at the GOARM values, it seems really like you're trying to check if we're building for ARMv5, ARMv6 or ARMv7. So what about using
BR2_ARM_CPU_ARMV5,BR2_ARM_CPU_ARMV6andBR2_ARM_CPU_ARMV7instead ?
No, that really is the way it goes. See;
https://golang.org/doc/install/source#environment
---8<---
* $GOARM (for arm only; default is auto-detected if building on the target processor, 6 if not)
- This sets the ARM floating point co-processor architecture version the run-time should target. If you are compiling on the target system, its value will be auto-detected.
. GOARM=5: use software floating point; when CPU doesn't have VFP
co-processor
. GOARM=6: use VFPv1 only; default if cross compiling; usually ARM11
or better cores (VFPv2 or better is also supported)
. GOARM=7: use VFPv3; usually Cortex-A cores
---8<---
So, what it really wants to know ifs what kind of FPU it can use.
No, I never said that buildsystem was sane... :-[
Quoted 10 lines
package/golang/golang.hash
Quoted 6 lines
package/golang/golang.hash new file +6
-0+define GOLANG_BUILD_CMDS + cd $(@D)/src/; \ + $(GOLANG_ENV) \ + GOROOT_FINAL="/usr/lib/go" \ + GO_NO_HOST=1 \ + ./make.bash --no-bannerIndent the lines after the cd, maybe, and do not excessively split lines.
Quoted 3 lines
cd $(@D)/src && \ $(GOLANG_ENV) GOROOT_FINAL="/usr/lib/go" GO_NO_HOST=1 \ ./make.bash --no-banner
OK.
Quoted 8 lines
package/golang/golang.hash
Quoted 6 lines
package/golang/golang.hash new file +6
-0+# We must install both the src/ and include/ subdirs because they +# contain the go "runtime". +define GOLANG_INSTALL_TARGET_CMDS + $(INSTALL) -D -m 0755 $(@D)/bin/linux_$(GOLANG_ARCH)/go $(TARGET_DIR)/usr/bin/go + $(INSTALL) -D -m 0755 $(@D)/bin/linux_$(GOLANG_ARCH)/gofmt $(TARGET_DIR)/usr/bin/gofmt + rm -rf $(TARGET_DIR)/usr/lib/go/Why this rm -rf ?
To remove any pre-existing intall, in case one does golang-reinstall or golang-rebuild...
Regards,
Yann E. MORIN.
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------. | Yann E. MORIN | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: | | +33 662 376 056 | Software Designer | \ / CAMPAIGN | ___ | | +33 223 225 172 `------------.-------: X AGAINST | \e/ There is no | | http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL | v conspiracy. | '------------------------------^-------^------------------^--------------------'
PATCH 1/1 package/golang: new package
Dear Yann E. MORIN,
Quoted 16 lines · Yann E. MORIN
Quoted 4 lines
Are you sure using VFPV3/VFPV2 is correct here? Looking at the GOARM values, it seems really like you're trying to check if we're building for ARMv5, ARMv6 or ARMv7. So what about using
BR2_ARM_CPU_ARMV5,BR2_ARM_CPU_ARMV6andBR2_ARM_CPU_ARMV7instead ?No, that really is the way it goes. See;
https://golang.org/doc/install/source#environment---8<---
* $GOARM (for arm only; default is auto-detected if building on the target processor, 6 if not)- This sets the ARM floating point co-processor architecture version the run-time should target. If you are compiling on the target system, its value will be auto-detected.
Quoted 8 lines
. GOARM=5: use software floating point; when CPU doesn't have VFP
co-processor
. GOARM=6: use VFPv1 only; default if cross compiling; usually ARM11
or better cores (VFPv2 or better is also supported)
. GOARM=7: use VFPv3; usually Cortex-A cores
---8<---So, what it really wants to know ifs what kind of FPU it can use.
Alright, then a short comment above this might be useful.
Quoted 11 lines
Quoted 8 lines
package/golang/golang.mk line 63
Quoted 6 lines
package/golang/golang.mk new file +6
-0+# We must install both the src/ and include/ subdirs because they +# contain the go "runtime". +define GOLANG_INSTALL_TARGET_CMDS + $(INSTALL) -D -m 0755 $(@D)/bin/linux_$(GOLANG_ARCH)/go $(TARGET_DIR)/usr/bin/go + $(INSTALL) -D -m 0755 $(@D)/bin/linux_$(GOLANG_ARCH)/gofmt $(TARGET_DIR)/usr/bin/gofmt + rm -rf $(TARGET_DIR)/usr/lib/go/Why this rm -rf ?
To remove any pre-existing intall, in case one does golang-reinstall or golang-rebuild...
We're not doing this for any other package, so why should we be doing this for golang?
Thomas
Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons Embedded Linux, Kernel and Android engineering http://free-electrons.com
PATCH 1/1 package/golang: new package
Thomas,
We're not doing this for any other package, so why should we be doing
Quoted 2 lines
this for golang?
Because it's very critical that Go have the exact same src, include, and pkg tree in that location. If we don't ensure any previous files have been cleared out it WILL cause major problems down the line.
Also, the empty variable declaration was because GOLANG_ARCH is set further down in the file. Sure, the line itself is technically useless, but the idea was to make sure it existed before setting it further down the line. I know that's not necessary in Make. It could be removed.
Best,
Christian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.busybox.net/pipermail/buildroot/attachments/20150729/365957ab/attachment.html>
PATCH 1/1 package/golang: new package
Christian, all,
On 2015-07-29 22:28 +0000, Christian Stewart spake thusly:
Quoted 7 lines
Quoted 3 lines
We're not doing this for any other package, so why should we be doing this for golang?
Because it's very critical that Go have the exact same src, include, and pkg tree in that location. If we don't ensure any previous files have been cleared out it WILL cause major problems down the line.
But Thomas is right: we're not doing it for other packages, even if they have the same requirements.
In fact, Buildroot only guarantees everything is perfect when building from scratch. Any cycle of build-modify-build has never been guaranteed to produce the same results as just the last build alone would give.
So, I concur with Thomas: we need not ensre cleanliness, and should assume that directory is clean. Hence there's no reason to remove it beforehand.
Regards,
Yann E. MORIN.
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------. | Yann E. MORIN | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: | | +33 662 376 056 | Software Designer | \ / CAMPAIGN | ___ | | +33 223 225 172 `------------.-------: X AGAINST | \e/ There is no | | http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL | v conspiracy. | '------------------------------^-------^------------------^--------------------'