1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-02-07 13:31:37 +02:00

customize ldflags

closes ##5
This commit is contained in:
Carlos Alexandro Becker 2017-01-11 20:25:52 -02:00
parent 87c5d8651b
commit e3220b8257
No known key found for this signature in database
GPG Key ID: E61E2F7DC14AB940
3 changed files with 17 additions and 8 deletions

View File

@ -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:

View File

@ -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}}"
}

View File

@ -35,16 +35,19 @@ func (Pipe) Run(config config.ProjectConfig) error {
}
func build(system, arch string, config config.ProjectConfig) error {
log.Println("Building", system+"/"+arch, "...")
ldflags := config.Build.Ldflags + " -X main.version=" + config.Git.CurrentTag
name, err := config.ArchiveName(system, arch)
if err != nil {
return err
}
output := "dist/" + name + "/" + config.BinaryName
log.Println("Building", output, "...")
log.Println("'" + ldflags + "'")
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(