Skip to contentSkip to conversation

New infrastructure for golang packages

PATCH New Angelo Compagnucci 2 participants 9 messages Dec 6, 2017

lore
Share & tools
lore
#0 lore raw

cover New infrastructure for golang packages

This series add a new pkg-golang infrastructure and converts some of the packages based on go.
I'll resend as an official patch series after receiving some comments in RFC trying to reignite the discussion.

Angelo Compagnucci (5):
package/pkg-golang: new package infrastructure docs/manual: adding documentation for the golang infrastructure package/flannel: converting to golang infrastructure package/runc: converting to golang infrastructure package/docker-containerd: converting to golang infrastructure

 docs/manual/adding-packages-golang.txt         | 114 +++++++++++++++++++++++
 docs/manual/adding-packages.txt                |   2 +
 package/Makefile.in                            |   1 +
 package/docker-containerd/docker-containerd.mk |  37 +++-----
 package/flannel/flannel.mk                     |  32 +------
 package/pkg-golang.mk                          | 121 +++++++++++++++++++++++++
 package/runc/runc.mk                           |  37 +-------
 7 files changed, 262 insertions(+), 82 deletions(-)
 create mode 100644 docs/manual/adding-packages-golang.txt
 create mode 100644 package/pkg-golang.mk
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/5 package/pkg-golang: new package infrastructure

From: Angelo Compagnucci <[email protected]>

This patch adds a new infrastructure for golang based packages.

---
 package/Makefile.in   |   1 +
 package/pkg-golang.mk | 121 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 122 insertions(+)
 create mode 100644 package/pkg-golang.mk
package/Makefile.in +1 -0
index a1a5316..60d98d0 100644
@@ -429,3 +429,4 @@ include package/pkg-kconfig.mk
 include package/pkg-rebar.mk
 include package/pkg-kernel-module.mk
 include package/pkg-waf.mk
+include package/pkg-golang.mk
package/pkg-golang.mk new file +121 -0

121 lines not on this page · raw message

Signature · 1 line
2.7.4
#2 lore raw

PATCH 2/5 docs/manual: adding documentation for the golang infrastructure

In reply to Angelo Compagnucci

From: Angelo Compagnucci <[email protected]>

This patch adds the documentation for the golang infrastructure.

---
 docs/manual/adding-packages-golang.txt | 114 +++++++++++++++++++++++++++++++++
 docs/manual/adding-packages.txt        |   2 +
 2 files changed, 116 insertions(+)
 create mode 100644 docs/manual/adding-packages-golang.txt
docs/manual/adding-packages-golang.txt new file +114 -0
new file mode 100644
index 0000000..3761cac
@@ -0,0 +1,114 @@
+// -*- mode:doc; -*-
+// vim: set syntax=asciidoc:
+
+=== Infrastructure for Go packages
+
+This infrastructure applies to Go packages that use the standard
+build system and use bundled dependencies.
+
+[[golang-package-tutorial]]
+
+==== +golang-package+ tutorial
+
+First, let's see how to write a +.mk+ file for a go package,
+with an example :
+
+------------------------
+01: ################################################################################
+02: #
+03: # go-foo
+04: #
+05: ################################################################################
+06:
+07: GO_FOO_VERSION = 1.0
+08: GO_FOO_SOURCE = go-foo-$(GO_FOO_VERSION).tar.xz
+09: GO_FOO_SITE = http://www.foosoftware.org/download
+10: GO_FOO_LICENSE = BSD-3-Clause
+11: GO_FOO_LICENSE_FILES = LICENSE
+12:
+13: $(eval $(golang-package))
+------------------------
+
+On line 7, we declare the version of the package.
+
+On line 8 and 9, we declare the name of the tarball (xz-ed tarball
+recommended) and the location of the tarball on the Web. Buildroot
+will automatically download the tarball from this location.
+
+On line 10 and 11, we give licensing details about the package (its
+license on line 10, and the file containing the license text on line
+11).
+
+Finally, on line 13, we invoke the +golang-package+ macro that
+generates all the Makefile rules that actually allow the package to be
+built.
+
+[[golang-package-reference]]
+
+==== +golang-package+ reference
+
+As a policy packages can freely choose their name (existing example in 
+Buildroot is +flannel+).
+
+In their +Config.in+ file, they should depend on 
++BR2_PACKAGE_HOST_GO_ARCH_SUPPORTS+ and
++BR2_PACKAGE_HOST_GO_CGO_LINKING_SUPPORTS+ cause host-go will compile when Buildroot will add the
+dependency automatically.
+
+The main macro of the Go package infrastructure is
++golang-package+. It is similar to the +generic-package+ macro.
+
+Just like the generic infrastructure, the Go infrastructure works
+by defining a number of variables before calling the +golang-package+.
+
+All the package metadata information variables that exist in the
+xref:generic-package-reference[generic package infrastructure] also
+exist in the Go infrastructure: +GO_FOO_VERSION+,
++GO_FOO_SOURCE+, +GO_FOO_PATCH+, +GO_FOO_SITE+,
++GO_FOO_SUBDIR+, +GO_FOO_DEPENDENCIES+, +GO_FOO_LICENSE+,
++GO_FOO_LICENSE_FILES+, +GO_FOO_INSTALL_STAGING+, etc.
+
+Note that:
+
+ * It is not necessary to add +go+ or +host-go+ in the
+   +GO_FOO_DEPENDENCIES+ variable of a package, since these basic
+   dependencies are automatically added as needed by the Go
+   package infrastructure.
+
+A few additional variables, specific to the Go infrastructure, can
+optionally be defined, depending on the package's needs. Many of them
+are only useful in very specific cases, typical packages will
+therefore only use a few of them, or none.
+
+* If your package need a custom GOPATH to be compiled in, you can use the
+  +GO_FOO_GOPATH+.
+
+* +GO_FOO_GO_SRC_PATH+ is the path where your source will be compiled
+  relatively to the GOPATH.
+  The golang package infrastructure tries to guess the correct 
+  sub folder to compile in but if guessing is not correct for you or your
+  package behaves differently, you can use this variable to
+  redefine the path.
+
+* +GOO_FOO_GO_LDFLAGS+ and +GO_FOO_GO_TAGS+ can be used to pass
+  respectively the LDFLAGS or the TAGS to the build command.
+  +GOO_FOO_GO_LDFLAGS+ and +GO_FOO_GO_TAGS+ will be combined into
+  the proper command line options to be passed to the compiler.
+
+* If you need to customize the install location for you binaries, you
+  can use +GOO_FOO_BINDIR+ to know where the binaries are.
+
+With the Go infrastructure, all the steps required to build and
+install the packages are already defined, and they generally work well
+for most Go-based packages. However, when required, it is still
+possible to customize what is done in any particular step:
+
+* By adding a post-operation hook (after extract, patch, configure,
+  build or install). See xref:hooks[] for details.
+
+* By overriding one of the steps. For example, even if the Go
+  infrastructure is used, if the package +.mk+ file defines its own
+  +GO_FOO_BUILD_CMDS+ variable, it will be used instead of the
+  default Go one. However, using this method should be restricted
+  to very specific cases. Do not use it in the general case.
+
docs/manual/adding-packages.txt +2 -0
index d577ff0..be7468b 100644
@@ -34,6 +34,8 @@ include::adding-packages-rebar.txt[]
 
 include::adding-packages-waf.txt[]
 
+include::adding-packages-golang.txt[]
+
 include::adding-packages-kernel-module.txt[]
 
 include::adding-packages-asciidoc.txt[]
Signature · 1 line
2.7.4
#3 lore raw

PATCH 3/5 package/flannel: converting to golang infrastructure

In reply to Angelo Compagnucci

From: Angelo Compagnucci <[email protected]>

This patch converts the flannel package to the new golang infrastructure.

---
 package/flannel/flannel.mk | 32 ++++----------------------------
 1 file changed, 4 insertions(+), 28 deletions(-)
package/flannel/flannel.mk +4 -28
index bbb2c72..6c9d9dd 100644
@@ -11,36 +11,12 @@ FLANNEL_SOURCE = $(FLANNEL_VERSION).tar.gz
 FLANNEL_LICENSE = Apache-2.0
 FLANNEL_LICENSE_FILES = LICENSE
 
-FLANNEL_DEPENDENCIES = host-go
-
-FLANNEL_MAKE_ENV = \
-	$(HOST_GO_TARGET_ENV) \
-	GOBIN="$(@D)/bin" \
-	GOPATH="$(@D)/gopath" \
-	CGO_ENABLED=1
-
-FLANNEL_GLDFLAGS = \
-	-X github.com/coreos/flannel/version.Version=$(FLANNEL_VERSION)
-
-ifeq ($(BR2_STATIC_LIBS),y)
-FLANNEL_GLDFLAGS += -extldflags '-static'
-endif
-
-define FLANNEL_CONFIGURE_CMDS
-	# Put sources at prescribed GOPATH location.
-	mkdir -p $(@D)/gopath/src/github.com/coreos
-	ln -s $(@D) $(@D)/gopath/src/github.com/coreos/flannel
-endef
-
-define FLANNEL_BUILD_CMDS
-	cd $(@D) && $(FLANNEL_MAKE_ENV) $(HOST_DIR)/bin/go \
-		build -v -o $(@D)/bin/flanneld -ldflags "$(FLANNEL_GLDFLAGS)" .
-endef
+FLANNEL_GO_LDFLAGS = -X github.com/coreos/flannel/version.Version=$(FLANNEL_VERSION)
 
+# Install flannel to its well known location.
 define FLANNEL_INSTALL_TARGET_CMDS
-	# Install flannel to its well known location.
-	$(INSTALL) -D -m 0755 $(@D)/bin/flanneld $(TARGET_DIR)/opt/bin/flanneld
+	$(INSTALL) -D -m 0755 $(FLANNEL_BINDIR)/flannel $(TARGET_DIR)/opt/bin/flanneld
 	$(INSTALL) -D -m 0755 $(@D)/dist/mk-docker-opts.sh $(TARGET_DIR)/opt/bin/mk-docker-opts.sh
 endef
 
-$(eval $(generic-package))
+$(eval $(golang-package))
Signature · 1 line
2.7.4
#4 lore raw

PATCH 4/5 package/runc: converting to golang infrastructure

In reply to Angelo Compagnucci

From: Angelo Compagnucci <[email protected]>

This patch converts the runc package to the new golang infrastructure.

---
 package/runc/runc.mk | 37 +++++--------------------------------
 1 file changed, 5 insertions(+), 32 deletions(-)
package/runc/runc.mk +5 -32
index fb3fec2..f497b6d 100644
@@ -9,42 +9,15 @@ RUNC_SITE = $(call github,opencontainers,runc,$(RUNC_VERSION))
 RUNC_LICENSE = Apache-2.0
 RUNC_LICENSE_FILES = LICENSE
 
-RUNC_DEPENDENCIES = host-go
+RUNC_GOPATH = Godeps/_workspace
 
-RUNC_GOPATH = "$(@D)/Godeps/_workspace"
-RUNC_MAKE_ENV = $(HOST_GO_TARGET_ENV) \
-	CGO_ENABLED=1 \
-	GOBIN="$(@D)/bin" \
-	GOPATH="$(RUNC_GOPATH)" \
-	PATH=$(BR_PATH)
+RUNC_GO_LDFLAGS = -X main.gitCommit=$(RUNC_VERSION)
 
-RUNC_GLDFLAGS = \
-	-X main.gitCommit=$(RUNC_VERSION)
-
-ifeq ($(BR2_STATIC_LIBS),y)
-RUNC_GLDFLAGS += -extldflags '-static'
-endif
-
-RUNC_GOTAGS = cgo static_build
+RUNC_GO_TAGS = cgo static_build
 
 ifeq ($(BR2_PACKAGE_LIBSECCOMP),y)
-RUNC_GOTAGS += seccomp
+RUNC_GO_TAGS += seccomp
 RUNC_DEPENDENCIES += libseccomp host-pkgconf
 endif
 
-define RUNC_CONFIGURE_CMDS
-	mkdir -p $(RUNC_GOPATH)/src/github.com/opencontainers
-	ln -s $(@D) $(RUNC_GOPATH)/src/github.com/opencontainers/runc
-endef
-
-define RUNC_BUILD_CMDS
-	cd $(@D) && $(RUNC_MAKE_ENV) $(HOST_DIR)/bin/go \
-		build -v -o $(@D)/bin/runc \
-		-tags "$(RUNC_GOTAGS)" -ldflags "$(RUNC_GLDFLAGS)" .
-endef
-
-define RUNC_INSTALL_TARGET_CMDS
-	$(INSTALL) -D -m 0755 $(@D)/bin/runc $(TARGET_DIR)/usr/bin/runc
-endef
-
-$(eval $(generic-package))
+$(eval $(golang-package))
Signature · 1 line
2.7.4
#5 lore raw

PATCH 5/5 package/docker-containerd: converting to golang infrastructure

In reply to Angelo Compagnucci

From: Angelo Compagnucci <[email protected]>

This patch converts the docker-containerd package to the new golang infrastructure.

---
 package/docker-containerd/docker-containerd.mk | 37 +++++++++++---------------
 1 file changed, 15 insertions(+), 22 deletions(-)
package/docker-containerd/docker-containerd.mk +15 -22
index ffbadb0..34e7674 100644
@@ -9,39 +9,32 @@ DOCKER_CONTAINERD_SITE = $(call github,docker,containerd,$(DOCKER_CONTAINERD_VER
 DOCKER_CONTAINERD_LICENSE = Apache-2.0
 DOCKER_CONTAINERD_LICENSE_FILES = LICENSE.code
 
-DOCKER_CONTAINERD_DEPENDENCIES = host-go
+DOCKER_CONTAINERD_GOPATH = vendor
 
-DOCKER_CONTAINERD_GOPATH = "$(@D)/vendor"
-DOCKER_CONTAINERD_MAKE_ENV = $(HOST_GO_TARGET_ENV) \
-	CGO_ENABLED=1 \
-	GOBIN="$(@D)/bin" \
-	GOPATH="$(DOCKER_CONTAINERD_GOPATH)"
-
-DOCKER_CONTAINERD_GLDFLAGS = \
+DOCKER_CONTAINERD_GO_LDFLAGS = \
 	-X github.com/docker/containerd.GitCommit=$(DOCKER_CONTAINERD_VERSION)
 
-ifeq ($(BR2_STATIC_LIBS),y)
-DOCKER_CONTAINERD_GLDFLAGS += -extldflags '-static'
-endif
-
-define DOCKER_CONTAINERD_CONFIGURE_CMDS
-	mkdir -p $(DOCKER_CONTAINERD_GOPATH)/src/github.com/docker
-	ln -s $(@D) $(DOCKER_CONTAINERD_GOPATH)/src/github.com/docker/containerd
-	mkdir -p $(DOCKER_CONTAINERD_GOPATH)/src/github.com/opencontainers
-	ln -s $(RUNC_SRCDIR) $(DOCKER_CONTAINERD_GOPATH)/src/github.com/opencontainers/runc
+define DOCKER_CONTAINERD_LINK_DIR
+	ln -sf $(@D) $(@D)/$(DOCKER_CONTAINERD_GOPATH)/src/github.com/docker/containerd
+	mkdir -p $(@D)/$(DOCKER_CONTAINERD_GOPATH)/src/github.com/opencontainers
+	ln -s $(RUNC_SRCDIR) $(@D)/$(DOCKER_CONTAINERD_GOPATH)/src/github.com/opencontainers/runc
 endef
 
+DOCKER_CONTAINERD_POST_CONFIGURE_HOOKS += DOCKER_CONTAINERD_LINK_DIR
+
 define DOCKER_CONTAINERD_BUILD_CMDS
 	$(foreach d,ctr containerd containerd-shim,\
-		cd $(@D); $(DOCKER_CONTAINERD_MAKE_ENV) $(HOST_DIR)/bin/go build \
-			-v -o $(@D)/bin/$(d) -ldflags "$(DOCKER_CONTAINERD_GLDFLAGS)" ./$(d)$(sep))
+		cd $(@D)/$(DOCKER_CONTAINERD_GOPATH)/src/github.com/docker/containerd; \
+		$(DOCKER_CONTAINERD_GO_ENV) \
+		$(DOCKER_CONTAINERD_GO) \
+		$(DOCKER_CONTAINERD_BUILD_OPTS) ./$(d)$(sep))
 endef
 
 define DOCKER_CONTAINERD_INSTALL_TARGET_CMDS
 	ln -fs runc $(TARGET_DIR)/usr/bin/docker-runc
-	$(INSTALL) -D -m 0755 $(@D)/bin/containerd $(TARGET_DIR)/usr/bin/docker-containerd
-	$(INSTALL) -D -m 0755 $(@D)/bin/containerd-shim $(TARGET_DIR)/usr/bin/containerd-shim
+	$(INSTALL) -D -m 0755 $(@D)/$(DOCKER_CONTAINERD_BINDIR)/containerd $(TARGET_DIR)/usr/bin/docker-containerd
+	$(INSTALL) -D -m 0755 $(@D)/$(DOCKER_CONTAINERD_BINDIR)/containerd-shim $(TARGET_DIR)/usr/bin/containerd-shim
 	ln -fs containerd-shim $(TARGET_DIR)/usr/bin/docker-containerd-shim
 endef
 
-$(eval $(generic-package))
+$(eval $(golang-package))
Signature · 1 line
2.7.4
#6 lore raw

cover New infrastructure for golang packages

In reply to Angelo Compagnucci

Hi Angelo,

I unfortunately probably won't have time to look at your patches tonight, however:

Quoted 4 lines · Angelo Compagnucci

This series add a new pkg-golang infrastructure and converts some of the packages based on go.
I'll resend as an official patch series after receiving some comments in RFC trying to reignite the discussion.

Is there any difference with v5? There doesn't seem to be a patch revision log
in any of the patches...

Regards,
Arnout

Quoted 19 lines

Angelo Compagnucci (5):
package/pkg-golang: new package infrastructure docs/manual: adding documentation for the golang infrastructure package/flannel: converting to golang infrastructure package/runc: converting to golang infrastructure package/docker-containerd: converting to golang infrastructure

 docs/manual/adding-packages-golang.txt         | 114 +++++++++++++++++++++++
 docs/manual/adding-packages.txt                |   2 +
 package/Makefile.in                            |   1 +
 package/docker-containerd/docker-containerd.mk |  37 +++-----
 package/flannel/flannel.mk                     |  32 +------
 package/pkg-golang.mk                          | 121 +++++++++++++++++++++++++
 package/runc/runc.mk                           |  37 +-------
 7 files changed, 262 insertions(+), 82 deletions(-)
 create mode 100644 docs/manual/adding-packages-golang.txt
 create mode 100644 package/pkg-golang.mk
Signature · 6 lines
Arnout Vandecappelle                          arnout at mind be
Senior Embedded Software Architect            +32-16-286500
Essensium/Mind                                http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium           BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint:  7493 020B C7E3 8618 8DEC 222C 82EB F404 F9AC 0DDF
#7 lore raw

cover New infrastructure for golang packages

Dear Arnout,

Il 06 dic 2017 10:39 PM, "Arnout Vandecappelle" <[email protected]> ha scritto:

Hi Angelo,

I unfortunately probably won't have time to look at your patches tonight,
however:

Quoted 4 lines · Angelo Compagnucci

This series add a new pkg-golang infrastructure and converts some of the packages based on go.
I'll resend as an official patch series after receiving some comments in RFC trying to reignite the discussion.

Is there any difference with v5?

No differences, I just sent this patch series as anon RFC cause I think it's in shape to be accepted.

There doesn't seem to be a patch revision log
in any of the patches...

Right, not good. I'll do in this series if needed.

Thanks!

Regards,
Arnout

Quoted 9 lines

Angelo Compagnucci (5):
package/pkg-golang: new package infrastructure docs/manual: adding documentation for the golang infrastructure package/flannel: converting to golang infrastructure package/runc: converting to golang infrastructure package/docker-containerd: converting to golang infrastructure

 docs/manual/adding-packages-golang.txt         | 114

+++++++++++++++++++++++

Quoted 5 lines
 docs/manual/adding-packages.txt                |   2 +
 package/Makefile.in                            |   1 +
 package/docker-containerd/docker-containerd.mk |  37 +++-----
 package/flannel/flannel.mk                     |  32 +------
 package/pkg-golang.mk                          | 121

+++++++++++++++++++++++++

Quoted 5 lines
 package/runc/runc.mk                           |  37 +-------
 7 files changed, 262 insertions(+), 82 deletions(-)
 create mode 100644 docs/manual/adding-packages-golang.txt
 create mode 100644 package/pkg-golang.mk

--

Arnout Vandecappelle                          arnout at mind be
Senior Embedded Software Architect            +32-16-286500
Essensium/Mind                                http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium           BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint:  7493 020B C7E3 8618 8DEC 222C 82EB F404 F9AC 0DDF

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.busybox.net/pipermail/buildroot/attachments/20171206/8ff0f6f2/attachment.html>

#8 lore raw

cover New infrastructure for golang packages

Quoted 5 lines · Angelo Compagnucci

There doesn't seem to be a patch revision log
in any of the patches...

Right, not good. I'll do in this series if needed.

Don't bother - it's generally pretty difficult to reconstruct history after the
fact. Just do it for your future submissions.

Regards,
Arnout

Signature · 6 lines
Arnout Vandecappelle                          arnout at mind be
Senior Embedded Software Architect            +32-16-286500
Essensium/Mind                                http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium           BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint:  7493 020B C7E3 8618 8DEC 222C 82EB F404 F9AC 0DDF