package/pkg-golang: simplify installing multiple binaries
cover package/pkg-golang: simplify installing multiple binaries
From: "Yann E. MORIN" <[email protected]>
Hello All!
This small series aims at simplifying the golang-package infra when a package builds multiple targets and thus installs multiple binaries.
Regards,
Yann E. MORIN.
The following changes since commit 0233c854b1845e0070179439a74b3b5245a4b01b
package/libblockdev: security bump to version 3.3.1 (2025-06-20 01:22:53 +0200)
are available as patches in this mail series,
for you to apply patches up to 424c15b5c3a2341e06b32f5481d391542c9437f8
package/pkg-golang: catch use of legacy FOO_INSTALL_BINS (2025-06-20 10:07:09 +0200)
----------------------------------------------------------------
Yann E. MORIN (4):
package/pkg-golang: simplify installing multiple binaries
package: drop default _INSTALL_BINS in golang-package package/cni-plugin: simplify installation package/pkg-golang: catch use of legacy FOO_INSTALL_BINS
docs/manual/adding-packages-golang.adoc | 26 +++++++++++----------- docs/manual/migrating.adoc | 5 +++++ .../amazon-ecr-credential-helper.mk | 1 - package/cni-plugins/cni-plugins.mk | 7 +++--- package/containerd/containerd.mk | 1 - package/delve/delve.mk | 2 -- package/docker-cli/docker-cli.mk | 2 -- package/docker-engine/docker-engine.mk | 2 -- package/mender-artifact/mender-artifact.mk | 3 --- package/moby-buildkit/moby-buildkit.mk | 4 ---- package/pkg-golang.mk | 17 ++++++++++++-- package/tailscale/tailscale.mk | 1 - 12 files changed, 36 insertions(+), 35 deletions(-)
--
____________ .-----------------.--------------------: _ :------------------. | Yann E. MORIN | Real-Time Embedded | __/ ) | /"\ ASCII RIBBON | | | Software Designer | _/ - /' | \ / CAMPAIGN | | +33 638.411.245 '--------------------: (_ `--, | X AGAINST | | yann.morin (at) orange.com |_=" ,--' | / \ HTML MAIL |
'--------------------------------------:______/_____:------------------'
____________________________________________________________________________________________________________
Ce message et ses pieces jointes peuvent contenir des informations confidentielles ou privilegiees et ne doivent donc pas etre diffuses, exploites ou copies sans autorisation. Si vous avez recu ce message par erreur, veuillez le signaler a l'expediteur et le detruire ainsi que les pieces jointes. Les messages electroniques etant susceptibles d'alteration, Orange decline toute responsabilite si ce message a ete altere, deforme ou falsifie. Merci.
This message and its attachments may contain confidential or privileged information that may be protected by law; they should not be distributed, used or copied without authorisation.
If you have received this email in error, please notify the sender and delete this message and its attachments. As emails may be altered, Orange is not liable for messages that have been modified, changed or falsified. Thank you.
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
PATCH 1/4 package/pkg-golang: simplify installing multiple binaries
From: "Yann E. MORIN" <[email protected]>
Currently, when a golang package defines multiple _BUILD_TARGETS, it has to basically repeat the same list in its _INSTALL_BINS.
When a golang package defines multiple _BUILD_TARGETS, the pkg-golang infra will forcibly use the basename (the notdir) of each target as the name of the generated binary; there is no option to set a per-target binary name.
However, the pkg-golang infra by default tries to install a binary named after the package rawname. This forces packages to basically repeat the same list as their _BUILD_TARGETS to override _INSTALL_BINS, when the list of generated binaries is already known to the infra.
We change the pkg-golang infra to better cover such a case:
- if _BUILD_TARGET is '.' (the default), keep the current scheme:
install a single binary named after the package rwaname;
- if _BUILD_TARGET is not '.', and contains a single word, use the notdir of the built target, but allow the user to override it with _BIN_NAME (the current behaviour);
- otherwise (_BUILD_TARGETS is set to more than one word), do not allow the user to set _BIN_NAME (it does not make sense), but set _INSTALL_BINS by default to the notdir of _BUILD_TARGETS.
We still allow the user to set _INSTALL_BINS in the last case, to cover the case for existing packages; those are going to be "fixed" in the following commits.
We now consider that _INSTALL_BINS is an internal implementation details that should no longer be exposed to the users, so we drop it from the documentation; we rephrase the corresponding part for _BUILD_TARGETS.
--- docs/manual/adding-packages-golang.adoc | 26 ++++++++++++------------- package/pkg-golang.mk | 11 +++++++++-- 2 files changed, 22 insertions(+), 15 deletions(-)
docs/manual/adding-packages-golang.adoc +13 -13
@@ -94,20 +94,20 @@ therefore only use a few of them, or none. defaults to +.+. We then have two cases: ** +FOO_BUILD_TARGETS+ is +.+. In this case, we assume only one binary - will be produced, and that by default we name it after the package - name. If that is not appropriate, the name of the produced binary - can be overridden using +FOO_BIN_NAME+. + will be built and installed, and by default we name it after the + package name; if that is not appropriate, the name of the binary can + be overridden using +FOO_BIN_NAME+. -** +FOO_BUILD_TARGETS+ is not +.+. In this case, we iterate over the - values to build each target, and for each produced a binary that is - the non-directory component of the target. For example if - +FOO_BUILD_TARGETS = cmd/docker cmd/dockerd+ the binaries produced - are +docker+ and +dockerd+. - -* +FOO_INSTALL_BINS+ can be used to pass the list of binaries that - should be installed in +/usr/bin+ on the target. If - +FOO_INSTALL_BINS+ is not specified, it defaults to the lower-case - name of package. +** +FOO_BUILD_TARGETS+ is not +.+. In this case, it is interpreted as a + space-separated list, and we iterate over the targets to build and + install a binary named after the non-directory component of the + target. For example if +FOO_BUILD_TARGETS = cmd/docker cmd/dockerd+, + the binaries built and installed are +docker+ and +dockerd+. If + +FOO_BUILD_TARGETS+ contains only one target, then it is possible to + override the built and installed binary by setting +FOO_BIN_NAME+, + as above; if +FOO_BUILD_TARGETS+ contains two or more targets, then + it is not possible to override the names of the installed binaries + (use a post-install hook for that). With the Go infrastructure, all the steps required to build and install the packages are already defined, and they generally work well
package/pkg-golang.mk +9 -2
@@ -61,9 +61,16 @@ $(2)_BUILD_TARGETS ?= . # after each build target building them (below in <pkg>_BUILD_CMDS). ifeq ($$($(2)_BUILD_TARGETS),.) $(2)_BIN_NAME ?= $$($(2)_RAWNAME) +$(2)_INSTALL_BINS ?= $$($(2)_BIN_NAME) +else ifeq ($$(words $$($(2)_BUILD_TARGETS)),1) +$(2)_BIN_NAME ?= $$(notdir $$($(2)_BUILD_TARGETS)) +$(2)_INSTALL_BINS ?= $$($(2)_BIN_NAME) +else +ifneq ($$($(2)_BIN_NAME),) +$$(error $(1) sets $(2)_BIN_NAME while there are multiple targets in $(2)_BUILD_TARGETS) +endif +$(2)_INSTALL_BINS ?= $$(notdir $$($(2)_BUILD_TARGETS)) endif - -$(2)_INSTALL_BINS ?= $$($(2)_RAWNAME) # Source files in Go usually use an import path resolved around # domain/vendor/software. We infer domain/vendor/software from the upstream URL
Signature · 18 lines
2.34.1 ____________________________________________________________________________________________________________ Ce message et ses pieces jointes peuvent contenir des informations confidentielles ou privilegiees et ne doivent donc pas etre diffuses, exploites ou copies sans autorisation. Si vous avez recu ce message par erreur, veuillez le signaler a l'expediteur et le detruire ainsi que les pieces jointes. Les messages electroniques etant susceptibles d'alteration, Orange decline toute responsabilite si ce message a ete altere, deforme ou falsifie. Merci. This message and its attachments may contain confidential or privileged information that may be protected by law; they should not be distributed, used or copied without authorisation. If you have received this email in error, please notify the sender and delete this message and its attachments. As emails may be altered, Orange is not liable for messages that have been modified, changed or falsified. Thank you. _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
PATCH 2/4 package: drop default _INSTALL_BINS in golang-package
In reply to [email protected]From: "Yann E. MORIN" <[email protected]>
Now that the pkg-golang infra automatically sets _INSTALL_BINS by default to the list of notdir of _BUILD_TARGETS, there is no need to do that in packages anymore.
Most packages were already using the notdir construct, so those are trivially fixed; a few had a hard-coded list that matched the built targets list, so they too are trivially fixed.
host-mender-artifact was slightly different, in that it explicitly set the _BIN_NAME to mender-artifact, which happens to be the default; it also set _INSTALL_BINS to _BIN_NAME, so again using the default. This package can also be fixed easily.
--- .../amazon-ecr-credential-helper.mk | 1 - package/containerd/containerd.mk | 1 - package/delve/delve.mk | 2 -- package/docker-cli/docker-cli.mk | 2 -- package/docker-engine/docker-engine.mk | 2 -- package/mender-artifact/mender-artifact.mk | 3 --- package/moby-buildkit/moby-buildkit.mk | 4 ---- package/tailscale/tailscale.mk | 1 - 8 files changed, 16 deletions(-)
package/amazon-ecr-credential-helper/amazon-ecr-credential-helper.mk +0 -1
@@ -15,6 +15,5 @@ AMAZON_ECR_CREDENTIAL_HELPER_SUBDIR = ecr-login AMAZON_ECR_CREDENTIAL_HELPER_GOMOD = ./cli AMAZON_ECR_CREDENTIAL_HELPER_BUILD_TARGETS = docker-credential-ecr-login -AMAZON_ECR_CREDENTIAL_HELPER_INSTALL_BINS = docker-credential-ecr-login $(eval $(golang-package))
package/containerd/containerd.mk +0 -1
@@ -20,7 +20,6 @@ CONTAINERD_BUILD_TARGETS = \ cmd/containerd-shim-runc-v2 \ cmd/ctr -CONTAINERD_INSTALL_BINS = $(notdir $(CONTAINERD_BUILD_TARGETS)) CONTAINERD_TAGS = no_aufs ifeq ($(BR2_PACKAGE_LIBAPPARMOR),y)
package/delve/delve.mk +0 -2
@@ -12,11 +12,9 @@ DELVE_DEPENDENCIES = host-pkgconf DELVE_TAGS = cgo DELVE_BUILD_TARGETS = cmd/dlv -DELVE_INSTALL_BINS = $(notdir $(DELVE_BUILD_TARGETS)) HOST_DELVE_TAGS = cgo HOST_DELVE_BUILD_TARGETS = cmd/dlv -HOST_DELVE_INSTALL_BINS = $(notdir $(HOST_DELVE_BUILD_TARGETS)) $(eval $(golang-package)) $(eval $(host-golang-package))
package/docker-cli/docker-cli.mk +0 -2
@@ -38,6 +38,4 @@ define DOCKER_CLI_FIX_VENDORING endef DOCKER_CLI_POST_EXTRACT_HOOKS += DOCKER_CLI_FIX_VENDORING -DOCKER_CLI_INSTALL_BINS = $(notdir $(DOCKER_CLI_BUILD_TARGETS)) - $(eval $(golang-package))
package/docker-engine/docker-engine.mk +0 -2
@@ -70,8 +70,6 @@ define DOCKER_ENGINE_FIX_VENDORING endef DOCKER_ENGINE_POST_EXTRACT_HOOKS += DOCKER_ENGINE_FIX_VENDORING -DOCKER_ENGINE_INSTALL_BINS = $(notdir $(DOCKER_ENGINE_BUILD_TARGETS)) - define DOCKER_ENGINE_INSTALL_INIT_SYSTEMD $(INSTALL) -D -m 0644 $(@D)/contrib/init/systemd/docker.service \ $(TARGET_DIR)/usr/lib/systemd/system/docker.service
package/mender-artifact/mender-artifact.mk +0 -3
@@ -115,7 +115,4 @@ HOST_MENDER_ARTIFACT_GO_ENV += \ HOST_MENDER_ARTIFACT_LDFLAGS = -X github.com/mendersoftware/mender-artifact/cli.Version=$(HOST_MENDER_ARTIFACT_VERSION) -HOST_MENDER_ARTIFACT_BIN_NAME = mender-artifact -HOST_MENDER_ARTIFACT_INSTALL_BINS = $(HOST_MENDER_ARTIFACT_BIN_NAME) - $(eval $(host-golang-package))
package/moby-buildkit/moby-buildkit.mk +0 -4
@@ -17,12 +17,8 @@ MOBY_BUILDKIT_BUILD_TARGETS = cmd/buildctl cmd/buildkitd MOBY_BUILDKIT_LDFLAGS = \ -X $(MOBY_BUILDKIT_GOMOD)/version.Version="$(MOBY_BUILDKIT_VERSION)" -MOBY_BUILDKIT_INSTALL_BINS = $(notdir $(MOBY_BUILDKIT_BUILD_TARGETS)) - HOST_MOBY_BUILDKIT_TAGS = cgo HOST_MOBY_BUILDKIT_BUILD_TARGETS = cmd/buildctl cmd/buildkitd -HOST_MOBY_BUILDKIT_INSTALL_BINS = $(notdir $(HOST_MOBY_BUILDKIT_BUILD_TARGETS)) - $(eval $(golang-package)) $(eval $(host-golang-package))
package/tailscale/tailscale.mk +0 -1
@@ -10,7 +10,6 @@ TAILSCALE_LICENSE = BSD-3-Clause TAILSCALE_LICENSE_FILES = LICENSE TAILSCALE_GOMOD = tailscale.com TAILSCALE_BUILD_TARGETS = cmd/tailscale cmd/tailscaled -TAILSCALE_INSTALL_BINS = tailscale tailscaled TAILSCALE_LDFLAGS = \ -X tailscale.com/version.longStamp=$(TAILSCALE_VERSION) \ -X tailscale.com/version.shortStamp=$(TAILSCALE_VERSION)
Signature · 18 lines
2.34.1 ____________________________________________________________________________________________________________ Ce message et ses pieces jointes peuvent contenir des informations confidentielles ou privilegiees et ne doivent donc pas etre diffuses, exploites ou copies sans autorisation. Si vous avez recu ce message par erreur, veuillez le signaler a l'expediteur et le detruire ainsi que les pieces jointes. Les messages electroniques etant susceptibles d'alteration, Orange decline toute responsabilite si ce message a ete altere, deforme ou falsifie. Merci. This message and its attachments may contain confidential or privileged information that may be protected by law; they should not be distributed, used or copied without authorisation. If you have received this email in error, please notify the sender and delete this message and its attachments. As emails may be altered, Orange is not liable for messages that have been modified, changed or falsified. Thank you. _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
PATCH 3/4 package/cni-plugin: simplify installation
In reply to [email protected]From: "Yann E. MORIN" <[email protected]>
In all theory, we could iterate over CNI_PLUGINS_INSTALL_BINS, which already contains the basenames $(notdir) of the binaries to install, but *_INSTALL_BINS is now an internal implementation detail, and can't be guaranteed to be stable.
Hence, iterate over the list of targets, and somewhat duplicate the install commands from the infra, using make's $(notdir) rather than calling to the shell's to call basename.
Note: we need to stop setting _INSTALL_BINS, as a following commit will check that it is not explicitly set, and fail otherwise.
--- package/cni-plugins/cni-plugins.mk | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
package/cni-plugins/cni-plugins.mk +3 -4
@@ -27,7 +27,6 @@ CNI_PLUGINS_BUILD_TARGETS = \ plugins/meta/portmap \ plugins/meta/tuning \ plugins/meta/vrf -CNI_PLUGINS_INSTALL_BINS = $(CNI_PLUGINS_BUILD_TARGETS) ifeq ($(BR2_PACKAGE_LIBAPPARMOR),y) CNI_PLUGINS_DEPENDENCIES += libapparmor
@@ -46,9 +45,9 @@ endif define CNI_PLUGINS_INSTALL_TARGET_CMDS $(INSTALL) -d -m 0755 $(TARGET_DIR)/opt/cni/bin - $(foreach d,$(CNI_PLUGINS_INSTALL_BINS),\ - $(INSTALL) -D -m 0755 $(@D)/bin/$$(basename $(d)) \ - $(TARGET_DIR)/opt/cni/bin + $(foreach d,$(CNI_PLUGINS_BUILD_TARGETS),\ + $(INSTALL) -D -m 0755 $(@D)/bin/$(notdir $(d)) \ + $(TARGET_DIR)/opt/cni/bin/$(notdir $(d)) ) endef
Signature · 18 lines
2.34.1 ____________________________________________________________________________________________________________ Ce message et ses pieces jointes peuvent contenir des informations confidentielles ou privilegiees et ne doivent donc pas etre diffuses, exploites ou copies sans autorisation. Si vous avez recu ce message par erreur, veuillez le signaler a l'expediteur et le detruire ainsi que les pieces jointes. Les messages electroniques etant susceptibles d'alteration, Orange decline toute responsabilite si ce message a ete altere, deforme ou falsifie. Merci. This message and its attachments may contain confidential or privileged information that may be protected by law; they should not be distributed, used or copied without authorisation. If you have received this email in error, please notify the sender and delete this message and its attachments. As emails may be altered, Orange is not liable for messages that have been modified, changed or falsified. Thank you. _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
PATCH 4/4 package/pkg-golang: catch use of legacy FOO_INSTALL_BINS
In reply to [email protected]From: "Yann E. MORIN" <[email protected]>
--- docs/manual/migrating.adoc | 5 +++++ package/pkg-golang.mk | 6 ++++++ 2 files changed, 11 insertions(+)
docs/manual/migrating.adoc +5 -0
@@ -222,3 +222,8 @@ from +-cargo2+ to +-cargo4+. In 2025.08, starting with systemd version 257, systemd-networkd requires kernel 5.4 or later. If you are still using a kernel older than 5.4, please update your kernel or use an alternative network manager. + +[[migrating-golang-packages]] +In 2025.08, the +FOO_INSTALL_BINS+ variable for golang packages is no longer +supported; the list of binaries to install is automatically derived from +the +FOO_BULD_TARGETS+ variable.
package/pkg-golang.mk +6 -0
@@ -40,6 +40,12 @@ GO_BIN = $(HOST_DIR)/bin/go define inner-golang-package +# Legacy +ifneq ($$($(2)_INSTALL_BINS),) +$$(error Package $(1) sets $(2)_INSTALL_BINS, which is no longer supported; \ +see the manual: https://buildroot.org/manual.html#migrating-golang-package ) +endif + $(2)_BUILD_OPTS += \ -ldflags "$$($(2)_LDFLAGS)" \ -modcacherw \
Signature · 18 lines
2.34.1 ____________________________________________________________________________________________________________ Ce message et ses pieces jointes peuvent contenir des informations confidentielles ou privilegiees et ne doivent donc pas etre diffuses, exploites ou copies sans autorisation. Si vous avez recu ce message par erreur, veuillez le signaler a l'expediteur et le detruire ainsi que les pieces jointes. Les messages electroniques etant susceptibles d'alteration, Orange decline toute responsabilite si ce message a ete altere, deforme ou falsifie. Merci. This message and its attachments may contain confidential or privileged information that may be protected by law; they should not be distributed, used or copied without authorisation. If you have received this email in error, please notify the sender and delete this message and its attachments. As emails may be altered, Orange is not liable for messages that have been modified, changed or falsified. Thank you. _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot