1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-24 04:16:27 +02:00

158 lines
3.9 KiB
Markdown
Raw Normal View History

2017-09-10 17:07:28 -03:00
---
title: Builds
series: customization
hideFromIndex: true
weight: 30
2017-09-10 17:07:28 -03:00
---
Builds can be customized in multiple ways.
You can specify for which `GOOS`, `GOARCH` and `GOARM` binaries are built
(goreleaser will generate a matrix of all combinations), and you can changed
2018-09-05 10:38:33 -03:00
the name of the binary, flags, environment variables, hooks and etc.
2017-09-10 17:07:28 -03:00
Here is a commented `builds` section with all fields specified:
2017-09-10 17:07:28 -03:00
```yml
# .goreleaser.yml
builds:
# You can have multiple builds defined as a yaml list
2017-09-10 17:07:28 -03:00
-
# ID of the build.
# Defaults to the project name.
id: "my-build"
# Path to project's (sub)directory containing Go code.
# This is the working directory for the Go build command(s).
# Default is `.`.
dir: go
2017-09-10 17:07:28 -03:00
# Path to main.go file or main package.
# Default is `.`.
2017-09-10 17:07:28 -03:00
main: ./cmd/main.go
2019-02-04 09:42:13 -02:00
# Binary name.
# Can be a path (e.g. `bin/app`) to wrap the binary in a directory.
2017-09-10 17:07:28 -03:00
# Default is the name of the project directory.
binary: program
2019-01-17 10:50:00 -02:00
# Custom flags templates.
# Default is empty.
flags:
- -tags=dev
2019-01-17 10:50:00 -02:00
- -v
2017-09-10 17:07:28 -03:00
# Custom asmflags templates.
# Default is empty.
asmflags:
- -D mysymbol
- all=-trimpath={{.Env.GOPATH}}
# Custom gcflags templates.
# Default is empty.
gcflags:
- all=-trimpath={{.Env.GOPATH}}
- ./dontoptimizeme=-N
# Custom ldflags templates.
# Default is `-s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}} -X main.builtBy=goreleaser`.
ldflags:
- -s -w -X main.build={{.Version}}
- ./usemsan=-msan
2017-09-10 17:07:28 -03:00
# Custom environment variables to be set during the builds.
# Default is empty.
2017-09-10 17:07:28 -03:00
env:
- CGO_ENABLED=0
# 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 17:07:28 -03:00
goos:
- freebsd
- windows
# GOARCH to build for.
# For more info refer to: https://golang.org/doc/install/source#environment
# Defaults are 386 and amd64.
2017-09-10 17:07:28 -03:00
goarch:
- amd64
- arm
- arm64
# 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 17:07:28 -03:00
goarm:
- 6
- 7
# GOMIPS and GOMIPS64 to build when GOARCH is mips, mips64, mipsle or mips64le.
# For more info refer to: https://golang.org/doc/install/source#environment
# Default is empty.
gomips:
- hardfloat
- softfloat
2017-09-10 17:07:28 -03:00
# List of combinations of GOOS + GOARCH + GOARM to ignore.
# Default is empty.
ignore:
- goos: darwin
goarch: 386
- goos: linux
goarch: arm
goarm: 7
- goarm: mips64
gomips: hardfloat
2017-09-10 17:07:28 -03:00
# Hooks can be used to customize the final binary,
# for example, to run generators.
# Those fields allow templates.
2017-09-10 17:07:28 -03:00
# Default is both hooks empty.
hooks:
pre: rice embed-go
post: ./script.sh
```
2018-07-08 23:57:46 -07:00
> Learn more about the [name template engine](/templates).
## 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:
2019-03-24 20:10:30 -03:00
```sh
GOVERSION=$(go version) goreleaser
```
2018-10-04 22:23:10 -03:00
## Go Modules
2019-02-26 17:17:30 -03:00
If you use Go 1.11+ with go modules or vgo, when GoReleaser runs it may
2018-10-04 22:23:10 -03:00
try to download the dependencies. Since several builds run in parallel, it is
very likely to fail.
You can solve this by running `go mod download` before calling `goreleaser` or
2018-10-04 22:23:10 -03:00
by adding a [hook][] doing that on your `.goreleaser.yaml` file:
```yaml
before:
hooks:
- go mod download
2018-10-04 22:23:10 -03:00
# rest of the file...
```
[hook]: /hooks
## Define Build Tag
GoReleaser uses `git describe` to get the build tag. You can set
a different build tag using the environment variable `GORELEASER_CURRENT_TAG`.
This is useful in scenarios where two tags point to the same commit.