Skip to content

Commit 8dc5d4b

Browse files
glevandRisca
authored andcommitted
package/go: Build host tools with host CC
The go build system doesn't have the notion of cross compiling, but just the notion of architecture. When the host and target architectures are different it expects to be given a target cross compiler in CC_FOR_TARGET. When the architectures are the same it will use CC_FOR_TARGET for both host and target compilation. To work around this limitation build and install a set of compiler and tool binaries built with CC_FOR_TARGET set to the host compiler. Also, the go build system is not compatible with ccache, so use HOSTCC_NOCCACHE. See golang/go#11685. Fixes build errors like these: host/usr/bin/go: No such file or directory http://autobuild.buildroot.net/results/6664189a6f3a815978e8d0a1d7ef408ca47e2874/ Signed-off-by: Geoff Levand <[email protected]> Signed-off-by: Thomas Petazzoni <[email protected]>
1 parent 64388a2 commit 8dc5d4b

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

package/go/go.mk

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ endif
3535
HOST_GO_DEPENDENCIES = host-go-bootstrap
3636
HOST_GO_ROOT = $(HOST_DIR)/usr/lib/go
3737

38+
# The go build system doesn't have the notion of cross compiling, but just the
39+
# notion of architecture. When the host and target architectures are different
40+
# it expects to be given a target cross compiler in CC_FOR_TARGET. When the
41+
# architectures are the same it will use CC_FOR_TARGET for both host and target
42+
# compilation. To work around this limitation build and install a set of
43+
# compiler and tool binaries built with CC_FOR_TARGET set to the host compiler.
44+
# Also, the go build system is not compatible with ccache, so use
45+
# HOSTCC_NOCCACHE. See https://github.com/golang/go/issues/11685.
3846
HOST_GO_MAKE_ENV = \
3947
GOROOT_BOOTSTRAP=$(HOST_GO_BOOTSTRAP_ROOT) \
4048
GOROOT_FINAL=$(HOST_GO_ROOT) \
@@ -44,16 +52,29 @@ HOST_GO_MAKE_ENV = \
4452
$(if $(GO_GOARM),GOARM=$(GO_GOARM)) \
4553
GOOS=linux \
4654
CGO_ENABLED=1 \
55+
CC=$(HOSTCC_NOCCACHE)
56+
57+
HOST_GO_TARGET_CC = \
4758
CC_FOR_TARGET=$(TARGET_CC) \
4859
CXX_FOR_TARGET=$(TARGET_CXX)
4960

61+
HOST_GO_HOST_CC = \
62+
CC_FOR_TARGET=$(HOSTCC_NOCCACHE) \
63+
CXX_FOR_TARGET=$(HOSTCC_NOCCACHE)
64+
65+
HOST_GO_TMP = $(@D)/host-go-tmp
66+
5067
define HOST_GO_BUILD_CMDS
51-
cd $(@D)/src && $(HOST_GO_MAKE_ENV) ./make.bash
68+
cd $(@D)/src && $(HOST_GO_MAKE_ENV) $(HOST_GO_HOST_CC) ./make.bash
69+
mkdir -p $(HOST_GO_TMP)
70+
mv $(@D)/pkg/tool $(HOST_GO_TMP)/
71+
mv $(@D)/bin/ $(HOST_GO_TMP)/
72+
cd $(@D)/src && $(HOST_GO_MAKE_ENV) $(HOST_GO_TARGET_CC) ./make.bash
5273
endef
5374

5475
define HOST_GO_INSTALL_CMDS
55-
$(INSTALL) -D -m 0755 $(@D)/bin/go $(HOST_GO_ROOT)/bin/go
56-
$(INSTALL) -D -m 0755 $(@D)/bin/gofmt $(HOST_GO_ROOT)/bin/gofmt
76+
$(INSTALL) -D -m 0755 $(HOST_GO_TMP)/bin/go $(HOST_GO_ROOT)/bin/go
77+
$(INSTALL) -D -m 0755 $(HOST_GO_TMP)/bin/gofmt $(HOST_GO_ROOT)/bin/gofmt
5778

5879
ln -sf ../lib/go/bin/go $(HOST_DIR)/usr/bin/
5980
ln -sf ../lib/go/bin/gofmt $(HOST_DIR)/usr/bin/
@@ -62,7 +83,7 @@ define HOST_GO_INSTALL_CMDS
6283

6384
mkdir -p $(HOST_GO_ROOT)/pkg
6485
cp -a $(@D)/pkg/include $(@D)/pkg/linux_* $(HOST_GO_ROOT)/pkg/
65-
cp -a $(@D)/pkg/tool $(HOST_GO_ROOT)/pkg/
86+
cp -a $(HOST_GO_TMP)/tool $(HOST_GO_ROOT)/pkg/
6687

6788
# There is a known issue which requires the go sources to be installed
6889
# https://golang.org/issue/2775

0 commit comments

Comments
 (0)