mirror of
https://github.com/siderolabs/kres.git
synced 2026-02-05 09:45:35 +01:00
feat: support custom build tags
Refactor make variables for build tags to allow multiple tags to be enabled in the Makefile. Allow custom build tags to be defined with respective make variables. Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
This commit is contained in:
6
Makefile
6
Makefile
@@ -1,6 +1,6 @@
|
||||
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
|
||||
#
|
||||
# Generated on 2025-12-05T15:27:03Z by kres 571923f-dirty.
|
||||
# Generated on 2025-12-08T15:47:06Z by kres 9fb16fe-dirty.
|
||||
|
||||
# common variables
|
||||
|
||||
@@ -28,10 +28,12 @@ GOLANGCILINT_VERSION ?= v2.7.1
|
||||
GOFUMPT_VERSION ?= v0.9.2
|
||||
GO_VERSION ?= 1.25.5
|
||||
GO_BUILDFLAGS ?=
|
||||
GO_BUILDTAGS ?= ,
|
||||
GO_LDFLAGS ?=
|
||||
CGO_ENABLED ?= 0
|
||||
GOTOOLCHAIN ?= local
|
||||
GOEXPERIMENT ?=
|
||||
GO_BUILDFLAGS := $(GO_BUILDFLAGS) -tags $(GO_BUILDTAGS)
|
||||
TESTPKGS ?= ./...
|
||||
KRES_IMAGE ?= ghcr.io/siderolabs/kres:latest
|
||||
CONFORMANCE_IMAGE ?= ghcr.io/siderolabs/conform:latest
|
||||
@@ -131,7 +133,7 @@ GO_LDFLAGS += -linkmode=external -extldflags '-static'
|
||||
endif
|
||||
|
||||
ifneq (, $(filter $(WITH_DEBUG), t true TRUE y yes 1))
|
||||
GO_BUILDFLAGS += -tags sidero.debug
|
||||
GO_BUILDTAGS := $(GO_BUILDTAGS)sidero.debug,
|
||||
else
|
||||
GO_LDFLAGS += -s
|
||||
endif
|
||||
|
||||
@@ -30,7 +30,7 @@ type VariableGroup struct {
|
||||
// Variable appends variable to the group.
|
||||
func (group *VariableGroup) Variable(variable *Variable) *VariableGroup {
|
||||
if slices.ContainsFunc(group.variables, func(item *Variable) bool {
|
||||
return item.name == variable.name
|
||||
return item.name == variable.name && item.operator == variable.operator
|
||||
}) {
|
||||
return group
|
||||
}
|
||||
|
||||
@@ -48,6 +48,10 @@ type Toolchain struct { //nolint:govet
|
||||
Docker struct {
|
||||
ExtraArgs []string `yaml:"extraArgs"`
|
||||
} `yaml:"docker"`
|
||||
// BuildTags are additional build tags to be optionally enabled:
|
||||
// - Makefile variable `WITH_$TAG`
|
||||
// - If variable is set, the build tag is passed to go build via `-tags` flag
|
||||
BuildTags []string `yaml:"buildTags"`
|
||||
}
|
||||
|
||||
// NewToolchain builds Toolchain with default values.
|
||||
@@ -136,6 +140,7 @@ func (toolchain *Toolchain) CompileMakefile(output *makefile.Output) error {
|
||||
|
||||
common := output.VariableGroup(makefile.VariableGroupCommon).
|
||||
Variable(makefile.OverridableVariable("GO_BUILDFLAGS", "")).
|
||||
Variable(makefile.OverridableVariable("GO_BUILDTAGS", ",")).
|
||||
Variable(makefile.OverridableVariable("GO_LDFLAGS", "")).
|
||||
Variable(makefile.OverridableVariable("CGO_ENABLED", "0")).
|
||||
Variable(makefile.OverridableVariable("GOTOOLCHAIN", "local")).
|
||||
@@ -155,12 +160,24 @@ func (toolchain *Toolchain) CompileMakefile(output *makefile.Output) error {
|
||||
|
||||
output.IfTrueCondition("WITH_DEBUG").
|
||||
Then(
|
||||
makefile.AppendVariable("GO_BUILDFLAGS", "-tags sidero.debug"),
|
||||
makefile.SimpleVariable("GO_BUILDTAGS", "$(GO_BUILDTAGS)sidero.debug,"),
|
||||
).
|
||||
Else(
|
||||
makefile.AppendVariable("GO_LDFLAGS", "-s"),
|
||||
)
|
||||
|
||||
for _, tag := range toolchain.BuildTags {
|
||||
conditionVar := "WITH_" + strings.ToUpper(tag)
|
||||
output.IfTrueCondition(conditionVar).
|
||||
Then(
|
||||
makefile.SimpleVariable("GO_BUILDTAGS", "$(GO_BUILDTAGS)"+tag+","),
|
||||
)
|
||||
}
|
||||
|
||||
common.Variable(
|
||||
makefile.AppendVariable("GO_BUILDFLAGS", "-tags $(GO_BUILDTAGS)"),
|
||||
)
|
||||
|
||||
output.Target("base").
|
||||
Depends(dag.GatherMatchingInputNames(toolchain, dag.Implements[dockerfile.Generator]())...).
|
||||
Description("Prepare base toolchain").
|
||||
|
||||
Reference in New Issue
Block a user