github.com/droot/goreleaser@v0.66.2-0.20180420030140-c2db5fb17157/docs/050-build.md (about) 1 --- 2 title: Builds 3 --- 4 5 Builds can be customized in multiple ways. You can specify for which `GOOS` and 6 `GOARCH` binaries are generated, and you can changed the name of the binary, flags, `ldflags`, hooks, etc. 7 8 Here is a commented `builds` section with all fields specified: 9 10 ```yml 11 # .goreleaser.yml 12 builds: 13 # You can have multiple builds defined as a yaml list 14 - 15 # Path to main.go file or main package. 16 # Default is `.`. 17 main: ./cmd/main.go 18 19 # Name of the binary. 20 # This is parsed with the Go template engine and the following variables 21 # are available: 22 # - Date 23 # - Commit 24 # - Tag 25 # - Version (Git tag without `v` prefix) 26 # Date format is `2006-01-02_15:04:05`. 27 # Default is the name of the project directory. 28 binary: program 29 30 # Set flags for custom build tags. 31 # Default is empty. 32 flags: -tags dev 33 34 # Custom ldflags template. 35 # This is parsed with the Go template engine and the following variables 36 # are available: 37 # - Date 38 # - Commit 39 # - Tag 40 # - Version (Git tag without `v` prefix) 41 # Date format is `2006-01-02_15:04:05`. 42 # You can use the `time` function instead of `Date`, for example: 43 # `time "2006-01-02"` too if you need custom formats 44 # 45 # Default is `-s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}}`. 46 ldflags: -s -w -X main.build={{.Version}} 47 48 # Custom environment variables to be set during the builds. 49 # Default is empty. 50 env: 51 - CGO_ENABLED=0 52 53 # GOOS list to build for. 54 # For more info refer to: https://golang.org/doc/install/source#environment 55 # Defaults are darwin and linux. 56 goos: 57 - freebsd 58 - windows 59 60 # GOARCH to build for. 61 # For more info refer to: https://golang.org/doc/install/source#environment 62 # Defaults are 386 and amd64. 63 goarch: 64 - amd64 65 - arm 66 - arm64 67 68 # GOARM to build for when GOARCH is arm. 69 # For more info refer to: https://golang.org/doc/install/source#environment 70 # Default is only 6. 71 goarm: 72 - 6 73 - 7 74 75 # List of combinations of GOOS + GOARCH + GOARM to ignore. 76 # Default is empty. 77 ignore: 78 - goos: darwin 79 goarch: 386 80 - goos: linux 81 goarch: arm 82 goarm: 7 83 84 # Hooks can be used to customize the final binary, 85 # for example, to run generators. 86 # Default is both hooks empty. 87 hooks: 88 pre: rice embed-go 89 post: ./script.sh 90 ``` 91 92 ## Passing environment variables to ldflags 93 94 You can do that by using `{{ .Env.VARIABLE_NAME }}` in the template, for 95 example: 96 97 ```yaml 98 builds: 99 - ldflags: -s -w -X "main.goversion={{.Env.GOVERSION}}" 100 ``` 101 102 Then you can run: 103 104 ```console 105 GOVERSION=$(go version) goreleaser 106 ```