1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-09-16 09:26:52 +02:00

support for custom build flags

This commit is contained in:
Carlos Alexandro Becker
2017-02-22 09:25:43 -03:00
parent eaaf816e59
commit b2fcbaeb49
3 changed files with 12 additions and 2 deletions

View File

@@ -169,9 +169,14 @@ build:
# Default is `main.go` # Default is `main.go`
main: ./cmd/main.go main: ./cmd/main.go
# Name of the binary. Default is the name of the project directory. # Name of the binary.
# Default is the name of the project directory.
binary_name: program binary_name: program
# Custom build tags.
# Default is empty
flags: -tags dev
# Custom ldflags. # Custom ldflags.
# Default is `-s -w` # Default is `-s -w`
ldflags: -s -w ldflags: -s -w

View File

@@ -28,6 +28,7 @@ type Build struct {
Goarch []string Goarch []string
Main string Main string
Ldflags string Ldflags string
Flags string
BinaryName string `yaml:"binary_name"` BinaryName string `yaml:"binary_name"`
Hooks Hooks Hooks Hooks
} }

View File

@@ -49,7 +49,11 @@ func build(name, goos, goarch string, ctx *context.Context) error {
return err return err
} }
} }
cmd := []string{"go", "build", "-ldflags=" + ldflags, "-o", output, ctx.Config.Build.Main} cmd := []string{"go", "build"}
if ctx.Config.Build.Flags != "" {
cmd = append(cmd, strings.Split(ctx.Config.Build.Flags, " ")...)
}
cmd = append(cmd, "-ldflags="+ldflags, "-o", output, ctx.Config.Build.Main)
if err := run(goos, goarch, cmd); err != nil { if err := run(goos, goarch, cmd); err != nil {
return err return err
} }