2017-09-10 22:07:28 +02:00
|
|
|
---
|
2017-10-01 18:57:52 +02:00
|
|
|
title: Builds
|
2018-04-25 07:20:12 +02:00
|
|
|
series: customization
|
|
|
|
hideFromIndex: true
|
|
|
|
weight: 30
|
2017-09-10 22:07:28 +02:00
|
|
|
---
|
|
|
|
|
2017-10-01 18:57:52 +02:00
|
|
|
Builds can be customized in multiple ways. You can specify for which `GOOS` and
|
|
|
|
`GOARCH` binaries are generated, and you can changed the name of the binary, flags, `ldflags`, hooks, etc.
|
2017-09-10 22:07:28 +02:00
|
|
|
|
2017-10-01 18:57:52 +02:00
|
|
|
Here is a commented `builds` section with all fields specified:
|
2017-09-10 22:07:28 +02:00
|
|
|
|
|
|
|
```yml
|
|
|
|
# .goreleaser.yml
|
|
|
|
builds:
|
2017-10-01 18:57:52 +02:00
|
|
|
# You can have multiple builds defined as a yaml list
|
2017-09-10 22:07:28 +02:00
|
|
|
-
|
|
|
|
# Path to main.go file or main package.
|
2017-10-01 18:57:52 +02:00
|
|
|
# Default is `.`.
|
2017-09-10 22:07:28 +02:00
|
|
|
main: ./cmd/main.go
|
|
|
|
|
|
|
|
# Name of the binary.
|
2018-02-15 13:30:15 +02:00
|
|
|
# This is parsed with the Go template engine and the following variables
|
|
|
|
# are available:
|
|
|
|
# - Date
|
|
|
|
# - Commit
|
|
|
|
# - Tag
|
|
|
|
# - Version (Git tag without `v` prefix)
|
|
|
|
# Date format is `2006-01-02_15:04:05`.
|
2017-09-10 22:07:28 +02:00
|
|
|
# Default is the name of the project directory.
|
|
|
|
binary: program
|
|
|
|
|
2017-10-01 18:57:52 +02:00
|
|
|
# Set flags for custom build tags.
|
|
|
|
# Default is empty.
|
2017-09-10 22:07:28 +02:00
|
|
|
flags: -tags dev
|
|
|
|
|
2018-04-20 13:26:04 +02:00
|
|
|
# Custom asmflags template.
|
|
|
|
# This is parsed with the Go template engine and the following variables
|
|
|
|
# are available:
|
|
|
|
# - Date
|
|
|
|
# - Commit
|
|
|
|
# - Tag
|
|
|
|
# - Version (Git tag without `v` prefix)
|
|
|
|
# - Env (environment variables)
|
|
|
|
# Date format is `2006-01-02_15:04:05`.
|
|
|
|
# You can use the `time` function instead of `Date`, for example:
|
|
|
|
# `time "2006-01-02"` too if you need custom formats
|
|
|
|
#
|
|
|
|
# Default is empty.
|
|
|
|
asmflags: all=-trimpath={{.Env.GOPATH}}
|
|
|
|
|
|
|
|
# Custom gcflags template.
|
|
|
|
# This is parsed with the Go template engine and the following variables
|
|
|
|
# are available:
|
|
|
|
# - Date
|
|
|
|
# - Commit
|
|
|
|
# - Tag
|
|
|
|
# - Version (Git tag without `v` prefix)
|
|
|
|
# - Env (environment variables)
|
|
|
|
# Date format is `2006-01-02_15:04:05`.
|
|
|
|
# You can use the `time` function instead of `Date`, for example:
|
|
|
|
# `time "2006-01-02"` too if you need custom formats
|
|
|
|
#
|
|
|
|
# Default is empty.
|
|
|
|
gcflags: all=-trimpath={{.Env.GOPATH}}
|
|
|
|
|
2017-09-10 22:07:28 +02:00
|
|
|
# Custom ldflags template.
|
2017-10-01 18:57:52 +02:00
|
|
|
# This is parsed with the Go template engine and the following variables
|
2017-09-10 22:07:28 +02:00
|
|
|
# are available:
|
|
|
|
# - Date
|
|
|
|
# - Commit
|
|
|
|
# - Tag
|
2017-10-01 18:57:52 +02:00
|
|
|
# - Version (Git tag without `v` prefix)
|
2018-04-20 13:26:04 +02:00
|
|
|
# - Env (environment variables)
|
2018-04-12 20:21:17 +02:00
|
|
|
# Date format is `2006-01-02_15:04:05`.
|
|
|
|
# You can use the `time` function instead of `Date`, for example:
|
|
|
|
# `time "2006-01-02"` too if you need custom formats
|
2018-04-12 20:16:16 +02:00
|
|
|
#
|
2017-10-01 18:57:52 +02:00
|
|
|
# Default is `-s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}}`.
|
2017-09-10 22:07:28 +02:00
|
|
|
ldflags: -s -w -X main.build={{.Version}}
|
|
|
|
|
2017-10-01 18:57:52 +02:00
|
|
|
# Custom environment variables to be set during the builds.
|
|
|
|
# Default is empty.
|
2017-09-10 22:07:28 +02:00
|
|
|
env:
|
|
|
|
- CGO_ENABLED=0
|
|
|
|
|
2017-10-01 18:57:52 +02:00
|
|
|
# GOOS list to build for.
|
|
|
|
# For more info refer to: https://golang.org/doc/install/source#environment
|
|
|
|
# Defaults are darwin and linux.
|
2017-09-10 22:07:28 +02:00
|
|
|
goos:
|
|
|
|
- freebsd
|
|
|
|
- windows
|
|
|
|
|
2017-10-01 18:57:52 +02:00
|
|
|
# GOARCH to build for.
|
|
|
|
# For more info refer to: https://golang.org/doc/install/source#environment
|
|
|
|
# Defaults are 386 and amd64.
|
2017-09-10 22:07:28 +02:00
|
|
|
goarch:
|
|
|
|
- amd64
|
|
|
|
- arm
|
|
|
|
- arm64
|
|
|
|
|
2017-10-01 18:57:52 +02:00
|
|
|
# GOARM to build for when GOARCH is arm.
|
|
|
|
# For more info refer to: https://golang.org/doc/install/source#environment
|
|
|
|
# Default is only 6.
|
2017-09-10 22:07:28 +02:00
|
|
|
goarm:
|
|
|
|
- 6
|
|
|
|
- 7
|
|
|
|
|
|
|
|
# List of combinations of GOOS + GOARCH + GOARM to ignore.
|
|
|
|
# Default is empty.
|
|
|
|
ignore:
|
|
|
|
- goos: darwin
|
|
|
|
goarch: 386
|
|
|
|
- goos: linux
|
|
|
|
goarch: arm
|
|
|
|
goarm: 7
|
|
|
|
|
2017-10-01 18:57:52 +02:00
|
|
|
# Hooks can be used to customize the final binary,
|
|
|
|
# for example, to run generators.
|
2017-09-10 22:07:28 +02:00
|
|
|
# Default is both hooks empty.
|
|
|
|
hooks:
|
|
|
|
pre: rice embed-go
|
|
|
|
post: ./script.sh
|
|
|
|
```
|
2017-12-03 20:19:57 +02:00
|
|
|
|
|
|
|
## Passing environment variables to ldflags
|
|
|
|
|
|
|
|
You can do that by using `{{ .Env.VARIABLE_NAME }}` in the template, for
|
|
|
|
example:
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
builds:
|
|
|
|
- ldflags: -s -w -X "main.goversion={{.Env.GOVERSION}}"
|
|
|
|
```
|
|
|
|
|
|
|
|
Then you can run:
|
|
|
|
|
|
|
|
```console
|
|
|
|
GOVERSION=$(go version) goreleaser
|
|
|
|
```
|