1
0
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:
Andrey Smirnov
2025-12-08 19:56:32 +04:00
parent 9fb16fe451
commit 5e26a1d61a
3 changed files with 23 additions and 4 deletions

View File

@@ -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").