All of lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH] package/go: ensure the toolchain is available
@ 2024-06-20 18:21 Yann E. MORIN
  2024-06-23 21:00 ` Yann E. MORIN
  0 siblings, 1 reply; 2+ messages in thread
From: Yann E. MORIN @ 2024-06-20 18:21 UTC (permalink / raw)
  To: buildroot; +Cc: Yann E. MORIN

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>
---
 package/go/go-src/go-src.mk | 4 +++-
 package/go/go.mk            | 5 ++++-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/package/go/go-src/go-src.mk b/package/go/go-src/go-src.mk
index 1e061e20bc..0d1a9b3187 100644
--- a/package/go/go-src/go-src.mk
+++ b/package/go/go-src/go-src.mk
@@ -12,7 +12,9 @@ GO_SRC_LICENSE_FILES = LICENSE
 GO_SRC_CPE_ID_VENDOR = golang
 
 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)
 
diff --git a/package/go/go.mk b/package/go/go.mk
index 6f92893204..91a8fb828f 100644
--- a/package/go/go.mk
+++ b/package/go/go.mk
@@ -83,7 +83,7 @@ HOST_GO_TARGET_ENV = \
 # any target package needing cgo support must include
 # 'depends on BR2_TOOLCHAIN_HAS_THREADS' in its config file.
 ifeq ($(BR2_TOOLCHAIN_HAS_THREADS),y)
-HOST_GO_DEPENDENCIES += toolchain
+HOST_GO_DEPENDENCIES_CGO += toolchain
 HOST_GO_CGO_ENABLED = 1
 else
 HOST_GO_CGO_ENABLED = 0
@@ -95,6 +95,9 @@ else # !BR2_PACKAGE_HOST_GO_TARGET_ARCH_SUPPORTS
 HOST_GO_CGO_ENABLED = 1
 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
 HOST_GO_HOST_ENV = \
 	$(HOST_GO_COMMON_ENV) \
-- 
2.45.1

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-06-23 21:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-20 18:21 [Buildroot] [PATCH] package/go: ensure the toolchain is available Yann E. MORIN
2024-06-23 21:00 ` Yann E. MORIN

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.