Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Baruch Siach <baruch@tkos.co.il>
To: buildroot@busybox.net
Subject: [Buildroot] [PATCH v1 1/1] package/go: use host compiler when go-bootstrap unsupported
Date: Tue, 22 Jun 2021 06:10:25 +0300	[thread overview]
Message-ID: <875yy6a926.fsf@tarshish> (raw)
In-Reply-To: <20210622024337.3009417-1-christian@paral.in>

Hi Christian,

On Tue, Jun 22 2021, Christian Stewart wrote:

> All Go compiler versions > 1.4.x (old) are written in Go, and require a existing
> compiled Go version to use to build from source.
>
> https://golang.org/doc/install/source#bootstrapFromSource
>
> The process for "bootstrapping" the Go compiler in Buildroot is:
>
> 1. Compile a C/C++ cross-compiler (gcc) as the host toolchain.
> 2. Build go-bootstrap (which is Go 1.4.x and written in C)
> 3. Build go 1.16.x (written in Go) using go-bootstrap.
>
> The problem is that step 2 - build go-bootstrap - does not work on 64-bit arm.
> The Go compiler from 1.4.x is compatible with x86, x86_64, and arm (32 bit).
>
> This means that arm64 host machines will skip building Go and all go-based
> packages like Docker.
>
> This patch instead uses the host Go compiler to bootstrap host-go when
> BR2_PACKAGE_HOST_GO_BOOTSTRAP_ARCH_SUPPORTS is not set. This is similar to how
> the host GCC is used to bootstrap the Buildroot toolchain.
>
> Signed-off-by: Christian Stewart <christian@paral.in>
> ---
>  package/go-bootstrap/go-bootstrap.mk | 6 ++++++
>  package/go/Config.in.host            | 2 --
>  package/go/go.mk                     | 4 ++++
>  3 files changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/package/go-bootstrap/go-bootstrap.mk b/package/go-bootstrap/go-bootstrap.mk
> index 6710e31561..8324a67795 100644
> --- a/package/go-bootstrap/go-bootstrap.mk
> +++ b/package/go-bootstrap/go-bootstrap.mk
> @@ -17,7 +17,13 @@ GO_BOOTSTRAP_LICENSE_FILES = LICENSE
>  # host-go-bootstrap.
>  HOST_GO_BOOTSTRAP_DEPENDENCIES = toolchain
>  
> +# If we do not support this architecture with go-bootstrap, depend on the host
> +# Go compiler to bootstrap the host-go compiler instead.
> +ifeq ($(BR2_PACKAGE_HOST_GO_BOOTSTRAP_ARCH_SUPPORTS),y)
>  HOST_GO_BOOTSTRAP_ROOT = $(HOST_DIR)/lib/go-$(GO_BOOTSTRAP_VERSION)
> +else
> +HOST_GO_BOOTSTRAP_ROOT = /usr/lib/go

I think we need a check for host go existence and maybe also version under
support/dependencies/.

baruch

> +endif
>  
>  # The go build system is not compatable with ccache, so use HOSTCC_NOCCACHE
>  # here.  See https://github.com/golang/go/issues/11685.
> diff --git a/package/go/Config.in.host b/package/go/Config.in.host
> index e82ab6e81a..c07605dd02 100644
> --- a/package/go/Config.in.host
> +++ b/package/go/Config.in.host
> @@ -2,7 +2,6 @@
>  config BR2_PACKAGE_HOST_GO_TARGET_ARCH_SUPPORTS
>  	bool
>  	default y
> -	depends on BR2_PACKAGE_HOST_GO_BOOTSTRAP_ARCH_SUPPORTS
>  	depends on (BR2_arm && BR2_TOOLCHAIN_SUPPORTS_PIE) || BR2_aarch64 \
>  		|| BR2_i386 || BR2_x86_64 || BR2_powerpc64le \
>  		|| BR2_mips64 || BR2_mips64el || BR2_s390x
> @@ -22,4 +21,3 @@ config BR2_PACKAGE_HOST_GO_TARGET_CGO_LINKING_SUPPORTS
>  config BR2_PACKAGE_HOST_GO_HOST_ARCH_SUPPORTS
>  	bool
>  	default y
> -	depends on BR2_PACKAGE_HOST_GO_BOOTSTRAP_ARCH_SUPPORTS
> diff --git a/package/go/go.mk b/package/go/go.mk
> index 4252691343..5f501d2d8c 100644
> --- a/package/go/go.mk
> +++ b/package/go/go.mk
> @@ -12,7 +12,11 @@ GO_LICENSE = BSD-3-Clause
>  GO_LICENSE_FILES = LICENSE
>  GO_CPE_ID_VENDOR = golang
>  
> +# Depend on the host Go compiler if go-bootstrap is not available.
> +ifeq ($(BR2_PACKAGE_HOST_GO_BOOTSTRAP_ARCH_SUPPORTS),y)
>  HOST_GO_DEPENDENCIES = host-go-bootstrap
> +endif
> +
>  HOST_GO_GOPATH = $(HOST_DIR)/usr/share/go-path
>  HOST_GO_HOST_CACHE = $(HOST_DIR)/usr/share/host-go-cache
>  HOST_GO_ROOT = $(HOST_DIR)/lib/go


-- 
                                                     ~. .~   Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
   - baruch at tkos.co.il - tel: +972.52.368.4656, http://www.tkos.co.il -

  reply	other threads:[~2021-06-22  3:10 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-22  2:43 [Buildroot] [PATCH v1 1/1] package/go: use host compiler when go-bootstrap unsupported Christian Stewart
2021-06-22  3:10 ` Baruch Siach [this message]
2021-06-28 18:00   ` Christian Stewart
2021-07-21 20:49 ` Thomas Petazzoni
2021-07-24 20:50   ` Christian Stewart
2022-07-24 22:55   ` Christian Stewart via buildroot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=875yy6a926.fsf@tarshish \
    --to=baruch@tkos.co.il \
    --cc=buildroot@busybox.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox