Explorar o código

package/go: ensure the toolchain is available

The toolchain is needed to build the final-stage go compiler, when it
should have CGO support.

However, in commit 0290c543dec8 (package/go: new subdirectory for go
variants), the HOST_GO_DEPENDENCIES assignment was only partially split
off to the new location; part of it was left in the ole go.mk to act as
common variables. With that commit, the go package had not been renamed,
which meant that the dependencies were still correct.

But in commit fa2536ec9401 (package/go: make host package a virtual
package), the 'go' package was renamed to 'go-src', and replaced by a
'go' virtual package.

The variables in the go-src package were properly renamed, and the
variables in the go virtual package were properly _not_ renamed. As a
consequence, the go-src package lost its dependency on the toolchain
when needed, while the go virtual package still had it.

However, that was not correct when CGO is enabled (i.e. when the target
has threads): go-src then fails to build:

    Building Go cmd/dist using [...]/host/lib/go-1.21.8. (go1.21.8 linux/amd64)
    go tool dist: cannot invoke C compiler ["[...]/host/bin/aarch64-linux-gcc"]:
    fork/exec [...]/host/bin/aarch64-linux-gcc: no such file or directory

    Go needs a system C compiler for use with cgo.
    To set a C compiler, set CC=the-compiler.
    To disable cgo, set CGO_ENABLED=0.

After some retro-thinking, the reasoning behind this was that the
toolchain would _also_ be needed when using the prebuilt go-bin, which
is indeed correct, so by having it as a dependency of the virtual
package, it would ensure the toolchain be present in both cases, when
building from scratch or when using a prebuilt go.

The oversight being that the toolchain is _also_ needed to actually
build go when CGO is enabled.

We fix this by handling the toolchain dependency for CGO by exposing it
in a variable, that can be used as a dependency in go-src, like is done
to actually enable or disable CGO support.

We still ensure that host-go still depends on it, for a future go-bin
provider.

Signed-off-by: Yann E. MORIN <yann.morin.1998@free.fr>
Yann E. MORIN hai 1 ano
pai
achega
60fc945734
Modificáronse 2 ficheiros con 7 adicións e 2 borrados
  1. 3 1
      package/go/go-src/go-src.mk
  2. 4 1
      package/go/go.mk

+ 3 - 1
package/go/go-src/go-src.mk

@@ -12,7 +12,9 @@ GO_SRC_LICENSE_FILES = LICENSE
 GO_SRC_CPE_ID_VENDOR = golang
 GO_SRC_CPE_ID_VENDOR = golang
 
 
 HOST_GO_SRC_PROVIDES = host-go
 HOST_GO_SRC_PROVIDES = host-go
-HOST_GO_SRC_DEPENDENCIES = host-go-bootstrap-stage3
+HOST_GO_SRC_DEPENDENCIES = \
+	host-go-bootstrap-stage3 \
+	$(HOST_GO_DEPENDENCIES_CGO)
 
 
 ifeq ($(BR2_PACKAGE_HOST_GO_TARGET_ARCH_SUPPORTS),y)
 ifeq ($(BR2_PACKAGE_HOST_GO_TARGET_ARCH_SUPPORTS),y)
 
 

+ 4 - 1
package/go/go.mk

@@ -83,7 +83,7 @@ HOST_GO_TARGET_ENV = \
 # any target package needing cgo support must include
 # any target package needing cgo support must include
 # 'depends on BR2_TOOLCHAIN_HAS_THREADS' in its config file.
 # 'depends on BR2_TOOLCHAIN_HAS_THREADS' in its config file.
 ifeq ($(BR2_TOOLCHAIN_HAS_THREADS),y)
 ifeq ($(BR2_TOOLCHAIN_HAS_THREADS),y)
-HOST_GO_DEPENDENCIES += toolchain
+HOST_GO_DEPENDENCIES_CGO += toolchain
 HOST_GO_CGO_ENABLED = 1
 HOST_GO_CGO_ENABLED = 1
 else
 else
 HOST_GO_CGO_ENABLED = 0
 HOST_GO_CGO_ENABLED = 0
@@ -95,6 +95,9 @@ else # !BR2_PACKAGE_HOST_GO_TARGET_ARCH_SUPPORTS
 HOST_GO_CGO_ENABLED = 1
 HOST_GO_CGO_ENABLED = 1
 endif # BR2_PACKAGE_HOST_GO_TARGET_ARCH_SUPPORTS
 endif # BR2_PACKAGE_HOST_GO_TARGET_ARCH_SUPPORTS
 
 
+# Ensure the toolchain is available, whatever the provider
+HOST_GO_DEPENDENCIES += $(HOST_GO_DEPENDENCIES_CGO)
+
 # For the convenience of host golang packages
 # For the convenience of host golang packages
 HOST_GO_HOST_ENV = \
 HOST_GO_HOST_ENV = \
 	$(HOST_GO_COMMON_ENV) \
 	$(HOST_GO_COMMON_ENV) \