From: Angelo Compagnucci <angelo@amarulasolutions.com>
To: buildroot@busybox.net
Subject: [Buildroot] [PATCH v3 1/7] package/pkg-golang: new package infrastructure
Date: Wed, 7 Mar 2018 23:19:33 +0100 [thread overview]
Message-ID: <1520461179-31679-2-git-send-email-angelo@amarulasolutions.com> (raw)
In-Reply-To: <1520461179-31679-1-git-send-email-angelo@amarulasolutions.com>
This patch adds a new infrastructure for golang based packages.
Signed-off-by: Angelo Compagnucci <angelo@amarulasolutions.com>
---
Changes:
v2 -> v3:
* If GOBIN variable is already present in environment it
will used by the go command for compiling and fails
with the error
"cannot install cross-compiled binaries when GOBIN is set"
v1 -> v2:
* Renamed GOBIN to GO_BIN for clarity
package/Makefile.in | 1 +
package/pkg-golang.mk | 123 ++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 124 insertions(+)
create mode 100644 package/pkg-golang.mk
diff --git a/package/Makefile.in b/package/Makefile.in
index e387ce6..379af5d 100644
--- a/package/Makefile.in
+++ b/package/Makefile.in
@@ -441,3 +441,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
diff --git a/package/pkg-golang.mk b/package/pkg-golang.mk
new file mode 100644
index 0000000..370db07
--- /dev/null
+++ b/package/pkg-golang.mk
@@ -0,0 +1,123 @@
+################################################################################
+# Golang package infrastructure
+#
+# This file implements an infrastructure that eases development of
+# package .mk files for Go packages. It should be used for all
+# packages that are written in go.
+#
+# See the Buildroot documentation for details on the usage of this
+# infrastructure
+#
+#
+# In terms of implementation, this golang infrastructure requires
+# the .mk file to only specify metadata information about the
+# package: name, version, download URL, etc.
+#
+# We still allow the package .mk file to override what the different
+# steps are doing, if needed. For example, if <PKG>_BUILD_CMDS is
+# already defined, it is used as the list of commands to perform to
+# build the package, instead of the default golang behavior. The
+# package can also define some post operation hooks.
+#
+################################################################################
+
+unexport GOBIN
+
+GO_BIN = $(HOST_DIR)/bin/go
+
+################################################################################
+# inner-golang-package -- defines how the configuration, compilation and
+# installation of a Go package should be done, implements a few hooks to
+# tune the build process for Go specificities and calls the generic package
+# infrastructure to generate the necessary make targets
+#
+# argument 1 is the lowercase package name
+# argument 2 is the uppercase package name, including a HOST_ prefix
+# for host packages
+# argument 3 is the uppercase package name, without the HOST_ prefix
+# for host packages
+# argument 4 is the type (target or host)
+################################################################################
+
+define inner-golang-package
+
+$(2)_GOPATH ?= _gopath
+$(2)_GO_ENV ?= $$(HOST_GO_TARGET_ENV) \
+ GOPATH="$$(@D)/$$($(2)_GOPATH)" \
+ CGO_ENABLED=$$(HOST_GO_CGO_ENABLED)
+
+ifeq ($(BR2_STATIC_LIBS),y)
+ $(2)_GO_LDFLAGS += -extldflags '-static'
+endif
+
+ifdef $(2)_GO_LDFLAGS
+ $(2)_BUILD_OPTS += -ldflags "$$($(2)_GO_LDFLAGS)"
+endif
+
+ifdef $(2)_GO_TAGS
+ $(2)_BUILD_OPTS += -tags "$$($(2)_GO_TAGS)"
+endif
+
+# Target packages need the Go compiler on the host.
+$(2)_DEPENDENCIES += host-go
+
+#
+# The go build/install command installs the binaries inside
+# gopath/bin/linux_GOARCH/ when cross compilation is enabled.
+# We set this variable here to be used by packages if needed.
+#
+$(2)_BINDIR = $$($(2)_GOPATH)/bin/linux_$$(GO_GOARCH)
+
+#
+# Source files in Go should be uncompressed in a precise folder in the
+# hierarchy of GOPATH. It usually resolves around domain/vendor/software.
+#
+$(2)_GO_SRC_PATH ?= $$(call domain,$($(2)_SITE))/$$(firstword $$(subst /, ,$$(call notdomain,$($(2)_SITE))))
+$(2)_SRC_PATH = $$(@D)/$$($(2)_GOPATH)/src/$$($(2)_GO_SRC_PATH)/$(1)
+
+#
+# Configure step. Only define it if not already defined by the package
+# .mk file.
+#
+ifndef $(2)_CONFIGURE_CMDS
+define $(2)_CONFIGURE_CMDS
+ mkdir -p $$(@D)/$$($(2)_GOPATH)/bin
+ mkdir -p $$(@D)/$$($(2)_GOPATH)/src/$$($(2)_GO_SRC_PATH)
+ ln -sf $$(@D) $$($(2)_SRC_PATH)
+endef
+endif
+
+#
+# Build step. Only define it if not already defined by the package .mk file.
+# We use the install command instead of build command here because the
+# install command also moves the package binaries in gopath/bin/linux_GOARCH/.
+# Using the install command also leverages the go build infrastructure
+# for building and installing multiple binaries.
+#
+ifndef $(2)_BUILD_CMDS
+define $(2)_BUILD_CMDS
+ cd $$($(2)_SRC_PATH) && $$($(2)_GO_ENV) $$(GO_BIN) install -v $$($(2)_BUILD_OPTS)
+endef
+endif
+
+#
+# Target installation step. Only define it if not already defined by the
+# package .mk file.
+#
+ifndef $(2)_INSTALL_TARGET_CMDS
+define $(2)_INSTALL_TARGET_CMDS
+ $(INSTALL) -D -m 0755 $$(@D)/$$($(2)_BINDIR)/$(1) $(TARGET_DIR)/usr/bin/
+endef
+endif
+
+# Call the generic package infrastructure to generate the necessary make
+# targets
+$(call inner-generic-package,$(1),$(2),$(3),$(4))
+
+endef # inner-golang-package
+
+################################################################################
+# golang-package -- the target generator macro for Go packages
+################################################################################
+
+golang-package = $(call inner-golang-package,$(pkgname),$(call UPPERCASE,$(pkgname)),$(call UPPERCASE,$(pkgname)),target)
--
2.7.4
next prev parent reply other threads:[~2018-03-07 22:19 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-07 22:19 [Buildroot] [PATCH v3 0/7] New infrastructure for golang packages Angelo Compagnucci
2018-03-07 22:19 ` Angelo Compagnucci [this message]
2018-03-07 22:19 ` [Buildroot] [PATCH v3 2/7] docs/manual: adding documentation for the golang infrastructure Angelo Compagnucci
2018-03-07 22:19 ` [Buildroot] [PATCH v3 3/7] package/flannel: converting to " Angelo Compagnucci
2018-03-07 22:19 ` [Buildroot] [PATCH v3 4/7] package/runc: " Angelo Compagnucci
2018-03-07 22:19 ` [Buildroot] [PATCH v3 5/7] package/docker-containerd: " Angelo Compagnucci
2018-03-30 21:53 ` Thomas Petazzoni
2018-03-07 22:19 ` [Buildroot] [PATCH v3 6/7] package/docker-engine: " Angelo Compagnucci
2018-03-07 22:19 ` [Buildroot] [PATCH v3 7/7] package/mender: new package Angelo Compagnucci
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=1520461179-31679-2-git-send-email-angelo@amarulasolutions.com \
--to=angelo@amarulasolutions.com \
--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