All of lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH v2 1/6] package/go: implement go modules integration
@ 2020-01-11  4:13 Christian Stewart
  2020-01-11  4:13 ` [Buildroot] [PATCH v2 2/6] package/runc: remove unnecessary workspace identifier Christian Stewart
                   ` (6 more replies)
  0 siblings, 7 replies; 10+ messages in thread
From: Christian Stewart @ 2020-01-11  4:13 UTC (permalink / raw)
  To: buildroot

This commit moves from the GOPATH mechanism to the new GO111MODULE approach for
Go based packages. Old Go packages compile with small tweaks. All Golang
packages currently in Buildroot have been build-tested after the change.

The Go module system replaces the GOPATH mechanism by allowing the Go tool to
work with packages correctly without a GOPATH tree.

Reference: https://github.com/golang/go/wiki/Modules

Signed-off-by: Christian Stewart <christian@paral.in>
---
 package/go/go.mk      |  6 +++++-
 package/pkg-golang.mk | 43 ++++++++++++++++++++++++++-----------------
 2 files changed, 31 insertions(+), 18 deletions(-)

diff --git a/package/go/go.mk b/package/go/go.mk
index a0f796c21b..46acda7dd0 100644
--- a/package/go/go.mk
+++ b/package/go/go.mk
@@ -15,6 +15,8 @@ HOST_GO_DEPENDENCIES = host-go-bootstrap
 HOST_GO_HOST_CACHE = $(HOST_DIR)/usr/share/host-go-cache
 HOST_GO_ROOT = $(HOST_DIR)/lib/go
 HOST_GO_TARGET_CACHE = $(HOST_DIR)/usr/share/go-cache
+# used for the Go module and build cache
+HOST_GO_GOPATH = $(DL_DIR)/go-module
 
 ifeq ($(BR2_PACKAGE_HOST_GO_TARGET_ARCH_SUPPORTS),y)
 
@@ -46,10 +48,12 @@ endif
 # For the convienience of target packages.
 HOST_GO_TOOLDIR = $(HOST_GO_ROOT)/pkg/tool/linux_$(GO_GOARCH)
 HOST_GO_TARGET_ENV = \
-	GO111MODULE=off \
+	GO111MODULE=on \
 	GOARCH=$(GO_GOARCH) \
 	GOCACHE="$(HOST_GO_TARGET_CACHE)" \
+	GOPROXY=off \
 	GOROOT="$(HOST_GO_ROOT)" \
+	GOPATH="$(HOST_GO_GOPATH)" \
 	CC="$(TARGET_CC)" \
 	CXX="$(TARGET_CXX)" \
 	GOTOOLDIR="$(HOST_GO_TOOLDIR)"
diff --git a/package/pkg-golang.mk b/package/pkg-golang.mk
index 2494ce028c..7fbf44b1c7 100644
--- a/package/pkg-golang.mk
+++ b/package/pkg-golang.mk
@@ -60,6 +60,7 @@ $(2)_WORKSPACE ?= _gopath
 
 $(2)_BUILD_OPTS += \
 	-ldflags "$$($(2)_LDFLAGS)" \
+	-mod=vendor \
 	-tags "$$($(2)_TAGS)" \
 	-trimpath \
 	-p $(PARALLEL_JOBS)
@@ -79,25 +80,34 @@ endif
 
 $(2)_INSTALL_BINS ?= $(1)
 
-# Source files in Go should be extracted in a precise folder in the hierarchy
-# of GOPATH. It usually resolves around domain/vendor/software. By default, we
-# derive domain/vendor/software from the upstream URL of the project, but we
-# allow $(2)_SRC_SUBDIR to be overridden if needed.
+# Source files in Go usually use an import path resolved around
+# domain/vendor/software. We infer domain/vendor/software from the upstream URL
+# of the project. $(2)_GOMOD can be overridden.
 $(2)_SRC_DOMAIN = $$(call domain,$$($(2)_SITE))
 $(2)_SRC_VENDOR = $$(word 1,$$(subst /, ,$$(call notdomain,$$($(2)_SITE))))
 $(2)_SRC_SOFTWARE = $$(word 2,$$(subst /, ,$$(call notdomain,$$($(2)_SITE))))
 
-$(2)_SRC_SUBDIR ?= $$($(2)_SRC_DOMAIN)/$$($(2)_SRC_VENDOR)/$$($(2)_SRC_SOFTWARE)
-$(2)_SRC_PATH = $$(@D)/$$($(2)_WORKSPACE)/src/$$($(2)_SRC_SUBDIR)
-
-# Configure step. Only define it if not already defined by the package .mk
-# file.
-ifndef $(2)_CONFIGURE_CMDS
-define $(2)_CONFIGURE_CMDS
-	mkdir -p $$(dir $$($(2)_SRC_PATH))
-	ln -sf $$(@D) $$($(2)_SRC_PATH)
+$(2)_GOMOD ?= $$($(2)_SRC_DOMAIN)/$$($(2)_SRC_VENDOR)/$$($(2)_SRC_SOFTWARE)
+
+# Correctly configure the go.mod and go.sum files for the module system.
+# TODO: Perform the "go mod vendor" download step.
+# Today, we still only support modules with a vendor/ tree in the source.
+define $(2)_APPLY_EXTRACT_GOMOD
+	if [ -f $$($(2)_PKGDIR)/go.mod ]; then \
+		cp $$($(2)_PKGDIR)/go.mod $$(@D)/go.mod; \
+		if [ -f $$(@D)/go.sum ]; then \
+			rm $$(@D)/go.sum; \
+		fi; \
+	fi; \
+	if [ -f $$($(2)_PKGDIR)/go.sum ]; then \
+		cp $$($(2)_PKGDIR)/go.sum $$(@D)/go.sum; \
+	fi
+	if [ ! -f $$(@D)/go.mod ] && [ -n "$$($(2)_GOMOD)" ]; then \
+		printf "module $$($(2)_GOMOD)\n" > $$(@D)/go.mod; \
+	fi
 endef
-endif
+
+$(2)_POST_EXTRACT_HOOKS += $(2)_APPLY_EXTRACT_GOMOD
 
 # Build step. Only define it if not already defined by the package .mk
 # file.
@@ -111,13 +121,12 @@ endif
 # Build package for target
 define $(2)_BUILD_CMDS
 	$$(foreach d,$$($(2)_BUILD_TARGETS),\
-		cd $$($(2)_SRC_PATH); \
+		cd $$(@D); \
 		$$(GO_TARGET_ENV) \
-			GOPATH="$$(@D)/$$($(2)_WORKSPACE)" \
 			$$($(2)_GO_ENV) \
 			$$(GO_BIN) build -v $$($(2)_BUILD_OPTS) \
 			-o $$(@D)/bin/$$(or $$($(2)_BIN_NAME),$$(notdir $$(d))) \
-			./$$(d)
+			$$(d)
 	)
 endef
 else
-- 
2.24.1

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

* [Buildroot] [PATCH v2 2/6] package/runc: remove unnecessary workspace identifier
  2020-01-11  4:13 [Buildroot] [PATCH v2 1/6] package/go: implement go modules integration Christian Stewart
@ 2020-01-11  4:13 ` Christian Stewart
  2020-01-11  4:13 ` [Buildroot] [PATCH v2 3/6] package/docker-containerd: fix go-module package identifier/targets Christian Stewart
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: Christian Stewart @ 2020-01-11  4:13 UTC (permalink / raw)
  To: buildroot

Signed-off-by: Christian Stewart <christian@paral.in>
---
 package/runc/runc.mk | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/package/runc/runc.mk b/package/runc/runc.mk
index acf61ab160..9a237aca38 100644
--- a/package/runc/runc.mk
+++ b/package/runc/runc.mk
@@ -9,10 +9,7 @@ RUNC_SITE = $(call github,opencontainers,runc,v$(RUNC_VERSION))
 RUNC_LICENSE = Apache-2.0
 RUNC_LICENSE_FILES = LICENSE
 
-RUNC_WORKSPACE = Godeps/_workspace
-
 RUNC_LDFLAGS = -X main.gitCommit=$(RUNC_VERSION)
-
 RUNC_TAGS = cgo static_build
 
 ifeq ($(BR2_PACKAGE_LIBSECCOMP),y)
-- 
2.24.1

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

* [Buildroot] [PATCH v2 3/6] package/docker-containerd: fix go-module package identifier/targets
  2020-01-11  4:13 [Buildroot] [PATCH v2 1/6] package/go: implement go modules integration Christian Stewart
  2020-01-11  4:13 ` [Buildroot] [PATCH v2 2/6] package/runc: remove unnecessary workspace identifier Christian Stewart
@ 2020-01-11  4:13 ` Christian Stewart
  2020-01-11  4:13 ` [Buildroot] [PATCH v2 4/6] package/docker-engine: fix go-module package identifier Christian Stewart
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: Christian Stewart @ 2020-01-11  4:13 UTC (permalink / raw)
  To: buildroot

Signed-off-by: Christian Stewart <christian@paral.in>
---
 package/docker-containerd/docker-containerd.mk | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/package/docker-containerd/docker-containerd.mk b/package/docker-containerd/docker-containerd.mk
index 69068e44f8..1d090d2326 100644
--- a/package/docker-containerd/docker-containerd.mk
+++ b/package/docker-containerd/docker-containerd.mk
@@ -9,13 +9,14 @@ DOCKER_CONTAINERD_SITE = $(call github,containerd,containerd,v$(DOCKER_CONTAINER
 DOCKER_CONTAINERD_LICENSE = Apache-2.0
 DOCKER_CONTAINERD_LICENSE_FILES = LICENSE
 
-DOCKER_CONTAINERD_WORKSPACE = vendor
-
+DOCKER_CONTAINERD_GOMOD = github.com/containerd/containerd
 DOCKER_CONTAINERD_LDFLAGS = \
-	-X github.com/docker/containerd.GitCommit=$(DOCKER_CONTAINERD_VERSION)
-
-DOCKER_CONTAINERD_BUILD_TARGETS = cmd/ctr cmd/containerd cmd/containerd-shim
+	-X $(DOCKER_CONTAINERD_GOMOD).GitCommit=$(DOCKER_CONTAINERD_VERSION)
 
+DOCKER_CONTAINERD_BUILD_TARGETS = \
+	$(DOCKER_CONTAINERD_GOMOD)/cmd/ctr \
+	$(DOCKER_CONTAINERD_GOMOD)/cmd/containerd \
+	$(DOCKER_CONTAINERD_GOMOD)/cmd/containerd-shim
 DOCKER_CONTAINERD_INSTALL_BINS = containerd containerd-shim
 
 ifeq ($(BR2_PACKAGE_LIBSECCOMP),y)
-- 
2.24.1

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

* [Buildroot] [PATCH v2 4/6] package/docker-engine: fix go-module package identifier
  2020-01-11  4:13 [Buildroot] [PATCH v2 1/6] package/go: implement go modules integration Christian Stewart
  2020-01-11  4:13 ` [Buildroot] [PATCH v2 2/6] package/runc: remove unnecessary workspace identifier Christian Stewart
  2020-01-11  4:13 ` [Buildroot] [PATCH v2 3/6] package/docker-containerd: fix go-module package identifier/targets Christian Stewart
@ 2020-01-11  4:13 ` Christian Stewart
  2020-01-11  4:13 ` [Buildroot] [PATCH v2 5/6] package/docker-cli: " Christian Stewart
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: Christian Stewart @ 2020-01-11  4:13 UTC (permalink / raw)
  To: buildroot

Signed-off-by: Christian Stewart <christian@paral.in>
---
 package/docker-engine/docker-engine.mk | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/package/docker-engine/docker-engine.mk b/package/docker-engine/docker-engine.mk
index eb3a7fd29f..e44d561b45 100644
--- a/package/docker-engine/docker-engine.mk
+++ b/package/docker-engine/docker-engine.mk
@@ -11,14 +11,14 @@ DOCKER_ENGINE_LICENSE = Apache-2.0
 DOCKER_ENGINE_LICENSE_FILES = LICENSE
 
 DOCKER_ENGINE_DEPENDENCIES = host-pkgconf
-DOCKER_ENGINE_SRC_SUBDIR = github.com/docker/docker
 
 DOCKER_ENGINE_LDFLAGS = \
 	-X main.GitCommit=$(DOCKER_ENGINE_VERSION) \
 	-X main.Version=$(DOCKER_ENGINE_VERSION)
-
 DOCKER_ENGINE_TAGS = cgo exclude_graphdriver_zfs autogen
-DOCKER_ENGINE_BUILD_TARGETS = cmd/dockerd
+
+DOCKER_ENGINE_GOMOD = github.com/docker/docker
+DOCKER_ENGINE_BUILD_TARGETS = $(DOCKER_ENGINE_GOMOD)/cmd/dockerd
 
 ifeq ($(BR2_PACKAGE_LIBSECCOMP),y)
 DOCKER_ENGINE_TAGS += seccomp
-- 
2.24.1

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

* [Buildroot] [PATCH v2 5/6] package/docker-cli: fix go-module package identifier
  2020-01-11  4:13 [Buildroot] [PATCH v2 1/6] package/go: implement go modules integration Christian Stewart
                   ` (2 preceding siblings ...)
  2020-01-11  4:13 ` [Buildroot] [PATCH v2 4/6] package/docker-engine: fix go-module package identifier Christian Stewart
@ 2020-01-11  4:13 ` Christian Stewart
  2020-01-11  4:13 ` [Buildroot] [PATCH v2 6/6] package/docker-proxy: " Christian Stewart
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: Christian Stewart @ 2020-01-11  4:13 UTC (permalink / raw)
  To: buildroot

Signed-off-by: Christian Stewart <christian@paral.in>
---
 package/docker-cli/docker-cli.mk | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/package/docker-cli/docker-cli.mk b/package/docker-cli/docker-cli.mk
index 4ad30e0278..12fb563885 100644
--- a/package/docker-cli/docker-cli.mk
+++ b/package/docker-cli/docker-cli.mk
@@ -13,12 +13,13 @@ DOCKER_CLI_LICENSE_FILES = LICENSE
 
 DOCKER_CLI_DEPENDENCIES = host-pkgconf
 
-DOCKER_CLI_TAGS = autogen
-DOCKER_CLI_BUILD_TARGETS = cmd/docker
-
+DOCKER_CLI_GOMOD = github.com/docker/cli
 DOCKER_CLI_LDFLAGS = \
-	-X github.com/docker/cli/cli.GitCommit=$(DOCKER_CLI_VERSION) \
-	-X github.com/docker/cli/cli.Version=$(DOCKER_CLI_VERSION)
+	-X $(DOCKER_CLI_GOMOD).GitCommit=$(DOCKER_CLI_VERSION) \
+	-X $(DOCKER_CLI_GOMOD).Version=$(DOCKER_CLI_VERSION)
+
+DOCKER_CLI_BUILD_TARGETS = $(DOCKER_CLI_GOMOD)/cmd/docker
+DOCKER_CLI_TAGS = autogen
 
 ifeq ($(BR2_PACKAGE_DOCKER_CLI_STATIC),y)
 DOCKER_CLI_LDFLAGS += -extldflags '-static'
-- 
2.24.1

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

* [Buildroot] [PATCH v2 6/6] package/docker-proxy: fix go-module package identifier
  2020-01-11  4:13 [Buildroot] [PATCH v2 1/6] package/go: implement go modules integration Christian Stewart
                   ` (3 preceding siblings ...)
  2020-01-11  4:13 ` [Buildroot] [PATCH v2 5/6] package/docker-cli: " Christian Stewart
@ 2020-01-11  4:13 ` Christian Stewart
  2020-01-11  4:35 ` [Buildroot] [PATCH v2 1/6] package/go: implement go modules integration Christian Stewart
  2020-01-14 16:56 ` Vincent Fazio
  6 siblings, 0 replies; 10+ messages in thread
From: Christian Stewart @ 2020-01-11  4:13 UTC (permalink / raw)
  To: buildroot

Signed-off-by: Christian Stewart <christian@paral.in>
---
 package/docker-proxy/docker-proxy.mk | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/package/docker-proxy/docker-proxy.mk b/package/docker-proxy/docker-proxy.mk
index 8843266c30..41ae07da09 100644
--- a/package/docker-proxy/docker-proxy.mk
+++ b/package/docker-proxy/docker-proxy.mk
@@ -12,9 +12,7 @@ DOCKER_PROXY_LICENSE_FILES = LICENSE
 
 DOCKER_PROXY_DEPENDENCIES = host-pkgconf
 
-DOCKER_PROXY_WORKSPACE = gopath
-
-DOCKER_PROXY_BUILD_TARGETS = cmd/proxy
+DOCKER_PROXY_BUILD_TARGETS = github.com/docker/libnetwork/cmd/proxy
 
 define DOCKER_PROXY_INSTALL_TARGET_CMDS
 	$(INSTALL) -D -m 0755 $(@D)/bin/proxy $(TARGET_DIR)/usr/bin/docker-proxy
-- 
2.24.1

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

* [Buildroot] [PATCH v2 1/6] package/go: implement go modules integration
  2020-01-11  4:13 [Buildroot] [PATCH v2 1/6] package/go: implement go modules integration Christian Stewart
                   ` (4 preceding siblings ...)
  2020-01-11  4:13 ` [Buildroot] [PATCH v2 6/6] package/docker-proxy: " Christian Stewart
@ 2020-01-11  4:35 ` Christian Stewart
  2020-01-14 16:56 ` Vincent Fazio
  6 siblings, 0 replies; 10+ messages in thread
From: Christian Stewart @ 2020-01-11  4:35 UTC (permalink / raw)
  To: buildroot

All,

A couple of notes on the below...

On Fri, Jan 10, 2020 at 8:13 PM Christian Stewart <christian@paral.in> wrote:
> +# used for the Go module and build cache
> +HOST_GO_GOPATH = $(DL_DIR)/go-module

The "pkg" directory will be placed here, inside which Go version
artifacts will be placed. It is not an issue that multiple packages
share the same GOPATH root.

Nothing will be placed in here with regards to Go modules at this time
since we are not downloading / extracting anything with the Go tool.

>  # For the convienience of target packages.

Spelling mistake: should be convenience.

> -# Configure step. Only define it if not already defined by the package .mk
> -# file.
> -ifndef $(2)_CONFIGURE_CMDS
> -define $(2)_CONFIGURE_CMDS
> -       mkdir -p $$(dir $$($(2)_SRC_PATH))
> -       ln -sf $$(@D) $$($(2)_SRC_PATH)

The configure step is removed. The below /could/ be done in place of
the old configure step, but I put it as a post-extract hook because it
must be done before "go mod vendor" which, although not part of this
commit, might be something we will include int he near future.

> +$(2)_GOMOD ?= $$($(2)_SRC_DOMAIN)/$$($(2)_SRC_VENDOR)/$$($(2)_SRC_SOFTWARE)
> +
> +# Correctly configure the go.mod and go.sum files for the module system.
> +# TODO: Perform the "go mod vendor" download step.
> +# Today, we still only support modules with a vendor/ tree in the source.
> +define $(2)_APPLY_EXTRACT_GOMOD

The lines below this one:

> +       if [ -f $$($(2)_PKGDIR)/go.mod ]; then \
> +               cp $$($(2)_PKGDIR)/go.mod $$(@D)/go.mod; \
> +               if [ -f $$(@D)/go.sum ]; then \
> +                       rm $$(@D)/go.sum; \
> +               fi; \
> +       fi; \
> +       if [ -f $$($(2)_PKGDIR)/go.sum ]; then \
> +               cp $$($(2)_PKGDIR)/go.sum $$(@D)/go.sum; \
> +       fi

... to this one, are unnecessary and can be removed. They copy a
"go.mod" and "go.sum" file from the package directory if they exist.
This is not used by any of the Buildroot packages today and is not
necessary to merge this patch.

> +       if [ ! -f $$(@D)/go.mod ] && [ -n "$$($(2)_GOMOD)" ]; then \
> +               printf "module $$($(2)_GOMOD)\n" > $$(@D)/go.mod; \
> +       fi

The above three lines create a go.mod file with the root module path
to inform the Go compiler of the name of the package at the root of
the source tree. These lines are necessary for those packages that
have vendor/ but no go.mod.

It's not an issue that this file will be a single line with the module
name in this case. The Go tool will understand it along with
"-mod=vendor" to mean that it should use the vendor tree.


>         $$(foreach d,$$($(2)_BUILD_TARGETS),\
> -               cd $$($(2)_SRC_PATH); \
> +               cd $$(@D); \

This should be $$($(2)_SRC_PATH) as before rather than $(@D), even
though $(@D) works, the change is not necessary.

>                 $$(GO_TARGET_ENV) \
> -                       GOPATH="$$(@D)/$$($(2)_WORKSPACE)" \
>                         $$($(2)_GO_ENV) \
>                         $$(GO_BIN) build -v $$($(2)_BUILD_OPTS) \
>                         -o $$(@D)/bin/$$(or $$($(2)_BIN_NAME),$$(notdir $$(d))) \
> -                       ./$$(d)
> +                       $$(d)

Here, we specify the Go module path to the compiler to build. This
looks like "go build github.com/myproject/mypackage".

So in summary, optional tweaks I suggest to the above before merge:

 - Use the SRC_PATH variable as mentioned above.
 - Remove the unnecessary copy of go.mod and go.sum from the Buildroot
package directory.
 - Consider creating the go.mod file in the Configure step rather than
a post-extract hook.

Best regards,
Christian

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

* [Buildroot] [PATCH v2 1/6] package/go: implement go modules integration
  2020-01-11  4:13 [Buildroot] [PATCH v2 1/6] package/go: implement go modules integration Christian Stewart
                   ` (5 preceding siblings ...)
  2020-01-11  4:35 ` [Buildroot] [PATCH v2 1/6] package/go: implement go modules integration Christian Stewart
@ 2020-01-14 16:56 ` Vincent Fazio
  2020-02-04 23:22   ` Christian Stewart
  6 siblings, 1 reply; 10+ messages in thread
From: Vincent Fazio @ 2020-01-14 16:56 UTC (permalink / raw)
  To: buildroot

Christian,

I tested this with a HOST Go package that i've got for git-lfs that I 
haven't submitted yet and it needed a couple of tweaks.

lmk your thoughts

On 1/10/20 10:13 PM, Christian Stewart wrote:
> This commit moves from the GOPATH mechanism to the new GO111MODULE approach for
> Go based packages. Old Go packages compile with small tweaks. All Golang
> packages currently in Buildroot have been build-tested after the change.
>
> The Go module system replaces the GOPATH mechanism by allowing the Go tool to
> work with packages correctly without a GOPATH tree.
>
> Reference: https://github.com/golang/go/wiki/Modules
>
> Signed-off-by: Christian Stewart <christian@paral.in>
> ---
>   package/go/go.mk      |  6 +++++-
>   package/pkg-golang.mk | 43 ++++++++++++++++++++++++++-----------------
>   2 files changed, 31 insertions(+), 18 deletions(-)
>
> diff --git a/package/go/go.mk b/package/go/go.mk
> index a0f796c21b..46acda7dd0 100644
> --- a/package/go/go.mk
> +++ b/package/go/go.mk
> @@ -15,6 +15,8 @@ HOST_GO_DEPENDENCIES = host-go-bootstrap
>   HOST_GO_HOST_CACHE = $(HOST_DIR)/usr/share/host-go-cache
>   HOST_GO_ROOT = $(HOST_DIR)/lib/go
>   HOST_GO_TARGET_CACHE = $(HOST_DIR)/usr/share/go-cache
> +# used for the Go module and build cache
> +HOST_GO_GOPATH = $(DL_DIR)/go-module
>   
>   ifeq ($(BR2_PACKAGE_HOST_GO_TARGET_ARCH_SUPPORTS),y)
>   
> @@ -46,10 +48,12 @@ endif
>   # For the convienience of target packages.
>   HOST_GO_TOOLDIR = $(HOST_GO_ROOT)/pkg/tool/linux_$(GO_GOARCH)
>   HOST_GO_TARGET_ENV = \
> -	GO111MODULE=off \
> +	GO111MODULE=on \
>   	GOARCH=$(GO_GOARCH) \
>   	GOCACHE="$(HOST_GO_TARGET_CACHE)" \
> +	GOPROXY=off \
>   	GOROOT="$(HOST_GO_ROOT)" \
> +	GOPATH="$(HOST_GO_GOPATH)" \
>   	CC="$(TARGET_CC)" \
>   	CXX="$(TARGET_CXX)" \
>   	GOTOOLDIR="$(HOST_GO_TOOLDIR)"
I did some additional factoring out here so that shared variables for 
Host and Target packages only need to be updated in one place

 ?HOST_GO_TOOLDIR = $(HOST_GO_ROOT)/pkg/tool/linux_$(GO_GOARCH)
 ?HOST_GO_TARGET_ENV = \
-?????? GO111MODULE=on \
 ??????? GOARCH=$(GO_GOARCH) \
 ??????? GOCACHE="$(HOST_GO_TARGET_CACHE)" \
 ??????? GOPROXY=off \
 ??????? GOROOT="$(HOST_GO_ROOT)" \
-?????? GOPATH="$(HOST_GO_GOPATH)" \
 ??????? CC="$(TARGET_CC)" \
 ??????? CXX="$(TARGET_CXX)" \
 ??????? GOTOOLDIR="$(HOST_GO_TOOLDIR)"
@@ -83,17 +81,18 @@ endif # BR2_PACKAGE_HOST_GO_TARGET_ARCH_SUPPORTS

 ?# The go build system is not compatible with ccache, so use
 ?# HOSTCC_NOCCACHE.? See https://github.com/golang/go/issues/11685.
+HOST_GO_HOST_ENV = \
+??????? GOCACHE=$(HOST_GO_HOST_CACHE) \
+??????? CC=$(HOSTCC_NOCCACHE) \
+??????? CXX=$(HOSTCXX_NOCCACHE)
+
 ?HOST_GO_MAKE_ENV = \
-?????? GO111MODULE=off \
-?????? GOCACHE=$(HOST_GO_HOST_CACHE) \
+?????? $(GO_HOST_ENV) \
 ??????? GOROOT_BOOTSTRAP=$(HOST_GO_BOOTSTRAP_ROOT) \
 ??????? GOROOT_FINAL=$(HOST_GO_ROOT) \
 ??????? GOROOT="$(@D)" \
 ??????? GOBIN="$(@D)/bin" \
 ??????? GOOS=linux \
-?????? CC=$(HOSTCC_NOCCACHE) \
-?????? CXX=$(HOSTCXX_NOCCACHE) \
-?????? CGO_ENABLED=$(HOST_GO_CGO_ENABLED) \
 ??????? $(HOST_GO_CROSS_ENV)

> diff --git a/package/pkg-golang.mk b/package/pkg-golang.mk
> index 2494ce028c..7fbf44b1c7 100644
> --- a/package/pkg-golang.mk
> +++ b/package/pkg-golang.mk
> @@ -60,6 +60,7 @@ $(2)_WORKSPACE ?= _gopath
>   
 ?GO_COMMON_ENV = \
 ??????? PATH=$(BR_PATH) \
 ??????? GOBIN= \
-?????? CGO_ENABLED=$(HOST_GO_CGO_ENABLED)
+?????? CGO_ENABLED=$(HOST_GO_CGO_ENABLED) \
+?????? GOPATH="$(HOST_GO_GOPATH)" \
+?????? GO111MODULE=on

 ?GO_TARGET_ENV = \
 ??????? $(HOST_GO_TARGET_ENV) \
 ??????? $(GO_COMMON_ENV)

 ?GO_HOST_ENV = \
+?????? $(HOST_GO_HOST_ENV) \
 ??????? CGO_CFLAGS="$(HOST_CFLAGS)" \
 ??????? CGO_LDFLAGS="$(HOST_LDFLAGS)" \
 ??????? $(GO_COMMON_ENV)

>   $(2)_BUILD_OPTS += \
>   	-ldflags "$$($(2)_LDFLAGS)" \
> +	-mod=vendor \
>   	-tags "$$($(2)_TAGS)" \
>   	-trimpath \
>   	-p $(PARALLEL_JOBS)
> @@ -79,25 +80,34 @@ endif
>   
>   $(2)_INSTALL_BINS ?= $(1)
>   
> -# Source files in Go should be extracted in a precise folder in the hierarchy
> -# of GOPATH. It usually resolves around domain/vendor/software. By default, we
> -# derive domain/vendor/software from the upstream URL of the project, but we
> -# allow $(2)_SRC_SUBDIR to be overridden if needed.
> +# Source files in Go usually use an import path resolved around
> +# domain/vendor/software. We infer domain/vendor/software from the upstream URL
> +# of the project. $(2)_GOMOD can be overridden.
>   $(2)_SRC_DOMAIN = $$(call domain,$$($(2)_SITE))
>   $(2)_SRC_VENDOR = $$(word 1,$$(subst /, ,$$(call notdomain,$$($(2)_SITE))))
>   $(2)_SRC_SOFTWARE = $$(word 2,$$(subst /, ,$$(call notdomain,$$($(2)_SITE))))
>   
> -$(2)_SRC_SUBDIR ?= $$($(2)_SRC_DOMAIN)/$$($(2)_SRC_VENDOR)/$$($(2)_SRC_SOFTWARE)
> -$(2)_SRC_PATH = $$(@D)/$$($(2)_WORKSPACE)/src/$$($(2)_SRC_SUBDIR)
> -
> -# Configure step. Only define it if not already defined by the package .mk
> -# file.
> -ifndef $(2)_CONFIGURE_CMDS
> -define $(2)_CONFIGURE_CMDS
> -	mkdir -p $$(dir $$($(2)_SRC_PATH))
> -	ln -sf $$(@D) $$($(2)_SRC_PATH)
> +$(2)_GOMOD ?= $$($(2)_SRC_DOMAIN)/$$($(2)_SRC_VENDOR)/$$($(2)_SRC_SOFTWARE)
> +
> +# Correctly configure the go.mod and go.sum files for the module system.
> +# TODO: Perform the "go mod vendor" download step.
> +# Today, we still only support modules with a vendor/ tree in the source.
> +define $(2)_APPLY_EXTRACT_GOMOD
> +	if [ -f $$($(2)_PKGDIR)/go.mod ]; then \
> +		cp $$($(2)_PKGDIR)/go.mod $$(@D)/go.mod; \
> +		if [ -f $$(@D)/go.sum ]; then \
> +			rm $$(@D)/go.sum; \
> +		fi; \
> +	fi; \
> +	if [ -f $$($(2)_PKGDIR)/go.sum ]; then \
> +		cp $$($(2)_PKGDIR)/go.sum $$(@D)/go.sum; \
> +	fi
> +	if [ ! -f $$(@D)/go.mod ] && [ -n "$$($(2)_GOMOD)" ]; then \
> +		printf "module $$($(2)_GOMOD)\n" > $$(@D)/go.mod; \
> +	fi
>   endef
> -endif
> +
> +$(2)_POST_EXTRACT_HOOKS += $(2)_APPLY_EXTRACT_GOMOD
>   
>   # Build step. Only define it if not already defined by the package .mk
>   # file.
> @@ -111,13 +121,12 @@ endif
>   # Build package for target
>   define $(2)_BUILD_CMDS
>   	$$(foreach d,$$($(2)_BUILD_TARGETS),\
> -		cd $$($(2)_SRC_PATH); \
> +		cd $$(@D); \
>   		$$(GO_TARGET_ENV) \
> -			GOPATH="$$(@D)/$$($(2)_WORKSPACE)" \
>   			$$($(2)_GO_ENV) \
>   			$$(GO_BIN) build -v $$($(2)_BUILD_OPTS) \
>   			-o $$(@D)/bin/$$(or $$($(2)_BIN_NAME),$$(notdir $$(d))) \
> -			./$$(d)
> +			$$(d)
>   	)
>   endef
>   else

-- 
Vincent Fazio
Embedded Software Engineer - Linux
Extreme Engineering Solutions, Inc
http://www.xes-inc.com

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

* [Buildroot] [PATCH v2 1/6] package/go: implement go modules integration
  2020-01-14 16:56 ` Vincent Fazio
@ 2020-02-04 23:22   ` Christian Stewart
  2020-02-05 16:31     ` Vincent Fazio
  0 siblings, 1 reply; 10+ messages in thread
From: Christian Stewart @ 2020-02-04 23:22 UTC (permalink / raw)
  To: buildroot

Hi Vincent,

Apologies for the delay on this-

On Tue, Jan 14, 2020 at 8:56 AM Vincent Fazio <vfazio@xes-inc.com> wrote:
> I tested this with a HOST Go package that i've got for git-lfs that I
> haven't submitted yet and it needed a couple of tweaks.
>
> lmk your thoughts

Unfortunately the format you've sent your corrections is a bit
confusing for me, and I'd like to make sure I get it right. Do you
have a copy of the .patch anywhere with your adjustments?

Best regards,
Christian

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

* [Buildroot] [PATCH v2 1/6] package/go: implement go modules integration
  2020-02-04 23:22   ` Christian Stewart
@ 2020-02-05 16:31     ` Vincent Fazio
  0 siblings, 0 replies; 10+ messages in thread
From: Vincent Fazio @ 2020-02-05 16:31 UTC (permalink / raw)
  To: buildroot

Chrisitan,

On 2/4/20 5:22 PM, Christian Stewart wrote:
> Hi Vincent,
>
> Apologies for the delay on this-
No problem, we all get busy.
> On Tue, Jan 14, 2020 at 8:56 AM Vincent Fazio <vfazio@xes-inc.com> wrote:
>> I tested this with a HOST Go package that i've got for git-lfs that I
>> haven't submitted yet and it needed a couple of tweaks.
>>
>> lmk your thoughts
> Unfortunately the format you've sent your corrections is a bit
> confusing for me, and I'd like to make sure I get it right. Do you
> have a copy of the .patch anywhere with your adjustments?

Sorry about that. Please take a look at the commit history here: 
https://gitlab.com/vfazio/buildroot/-/commits/go-modules-fixups

Some of the changes aren't directly tied to your work, but help make 
HOST and TARGET golang builds a bit easier to maintain (IMO).

Hopefully that helps.

> Best regards,
> Christian

-- 
Vincent Fazio
Embedded Software Engineer - Linux
Extreme Engineering Solutions, Inc
http://www.xes-inc.com

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

end of thread, other threads:[~2020-02-05 16:31 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-11  4:13 [Buildroot] [PATCH v2 1/6] package/go: implement go modules integration Christian Stewart
2020-01-11  4:13 ` [Buildroot] [PATCH v2 2/6] package/runc: remove unnecessary workspace identifier Christian Stewart
2020-01-11  4:13 ` [Buildroot] [PATCH v2 3/6] package/docker-containerd: fix go-module package identifier/targets Christian Stewart
2020-01-11  4:13 ` [Buildroot] [PATCH v2 4/6] package/docker-engine: fix go-module package identifier Christian Stewart
2020-01-11  4:13 ` [Buildroot] [PATCH v2 5/6] package/docker-cli: " Christian Stewart
2020-01-11  4:13 ` [Buildroot] [PATCH v2 6/6] package/docker-proxy: " Christian Stewart
2020-01-11  4:35 ` [Buildroot] [PATCH v2 1/6] package/go: implement go modules integration Christian Stewart
2020-01-14 16:56 ` Vincent Fazio
2020-02-04 23:22   ` Christian Stewart
2020-02-05 16:31     ` Vincent Fazio

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.