diff --git a/README.md b/README.md index ea87f1c0c..d6d53b3f8 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,7 @@ repo: user/repo binary_name: my-binary build: main: ./cmd/main.go + ldflags: -s -w oses: - darwin - freebsd @@ -64,7 +65,8 @@ build: - amd64 ``` -> `oses` and `arches` should be in `GOOS`/`GOARCH`-compatible format. +> - `oses` and `arches` should be in `GOOS`/`GOARCH`-compatible format. +> - `-s -w` is the default value for `ldflags`. ### Archive customization @@ -107,7 +109,7 @@ files: > By default GoReleaser adds the binary itself, `LICENCE*`, `LICENSE*`, `README*` and `CHANGELOG*`. -### ldflags +### ldflags (main.version) GoReleaser already sets a `main.version` ldflag, so, in you `main.go` program, you can: diff --git a/config/config.go b/config/config.go index 0e37f3edd..bcdbbf22d 100644 --- a/config/config.go +++ b/config/config.go @@ -22,9 +22,10 @@ type Homebrew struct { // BuildConfig contains the build configuration section type BuildConfig struct { - Oses []string - Arches []string - Main string + Oses []string + Arches []string + Main string + Ldflags string } // GitInfo includes tags and diffs used in some point @@ -107,6 +108,9 @@ func (config *ProjectConfig) fillBasicData() { if len(config.Build.Arches) == 0 { config.Build.Arches = []string{"amd64", "386"} } + if config.Build.Ldflags == "" { + config.Build.Ldflags = "-s -w" + } if config.Archive.NameTemplate == "" { config.Archive.NameTemplate = "{{.BinaryName}}_{{.Os}}_{{.Arch}}" } diff --git a/pipeline/build/build.go b/pipeline/build/build.go index 0f73913ee..8140f782d 100644 --- a/pipeline/build/build.go +++ b/pipeline/build/build.go @@ -35,16 +35,18 @@ func (Pipe) Run(config config.ProjectConfig) error { } func build(system, arch string, config config.ProjectConfig) error { - log.Println("Building", system+"/"+arch, "...") name, err := config.ArchiveName(system, arch) if err != nil { return err } + ldflags := config.Build.Ldflags + " -X main.version=" + config.Git.CurrentTag + output := "dist/" + name + "/" + config.BinaryName + log.Println("Building", output, "...") cmd := exec.Command( "go", "build", - "-ldflags=-s -w -X main.version="+config.Git.CurrentTag, - "-o", "dist/"+name+"/"+config.BinaryName, + "-ldflags="+ldflags, + "-o", output, config.Build.Main, ) cmd.Env = append(