github.com/fitzix/goreleaser@v0.92.0/www/content/build.md (about)

     1  ---
     2  title: Builds
     3  series: customization
     4  hideFromIndex: true
     5  weight: 30
     6  ---
     7  
     8  Builds can be customized in multiple ways.
     9  You can specify for which `GOOS`, `GOARCH` and `GOARM` binaries are built
    10  (goreleaser will generate a matrix of all combinations), and you can changed
    11  the name of the binary, flags, environment variables, hooks and etc.
    12  
    13  Here is a commented `builds` section with all fields specified:
    14  
    15  ```yml
    16  # .goreleaser.yml
    17  builds:
    18    # You can have multiple builds defined as a yaml list
    19    -
    20      # Path to main.go file or main package.
    21      # Default is `.`.
    22      main: ./cmd/main.go
    23  
    24      # Name template for the binary final name.
    25      # Default is the name of the project directory.
    26      binary: program
    27  
    28      # Set flags for custom build tags.
    29      # Default is empty.
    30      flags:
    31        - -tags=dev
    32  
    33      # Custom asmflags templates.
    34      # Default is empty.
    35      asmflags:
    36        - -D mysymbol
    37        - all=-trimpath={{.Env.GOPATH}}
    38  
    39      # Custom gcflags templates.
    40      # Default is empty.
    41      gcflags:
    42        - all=-trimpath={{.Env.GOPATH}}
    43        - ./dontoptimizeme=-N
    44  
    45      # Custom ldflags templates.
    46      # Default is `-s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}}`.
    47      ldflags:
    48       - -s -w -X main.build={{.Version}}
    49       - ./usemsan=-msan
    50  
    51      # Custom environment variables to be set during the builds.
    52      # Default is empty.
    53      env:
    54        - CGO_ENABLED=0
    55  
    56      # GOOS list to build for.
    57      # For more info refer to: https://golang.org/doc/install/source#environment
    58      # Defaults are darwin and linux.
    59      goos:
    60        - freebsd
    61        - windows
    62  
    63      # GOARCH to build for.
    64      # For more info refer to: https://golang.org/doc/install/source#environment
    65      # Defaults are 386 and amd64.
    66      goarch:
    67        - amd64
    68        - arm
    69        - arm64
    70  
    71      # GOARM to build for when GOARCH is arm.
    72      # For more info refer to: https://golang.org/doc/install/source#environment
    73      # Default is only 6.
    74      goarm:
    75        - 6
    76        - 7
    77  
    78      # List of combinations of GOOS + GOARCH + GOARM to ignore.
    79      # Default is empty.
    80      ignore:
    81        - goos: darwin
    82          goarch: 386
    83        - goos: linux
    84          goarch: arm
    85          goarm: 7
    86  
    87      # Hooks can be used to customize the final binary,
    88      # for example, to run generators.
    89      # Default is both hooks empty.
    90      hooks:
    91        pre: rice embed-go
    92        post: ./script.sh
    93  ```
    94  
    95  > Learn more about the [name template engine](/templates).
    96  
    97  ## Passing environment variables to ldflags
    98  
    99  You can do that by using `{{ .Env.VARIABLE_NAME }}` in the template, for
   100  example:
   101  
   102  ```yaml
   103  builds:
   104    - ldflags:
   105     - -s -w -X "main.goversion={{.Env.GOVERSION}}"
   106  ```
   107  
   108  Then you can run:
   109  
   110  ```console
   111  GOVERSION=$(go version) goreleaser
   112  ```
   113  
   114  ## Go Modules
   115  
   116   If you use Go 1.11 with go modules or vgo, when GoReleaser runs it may
   117   try to download the dependencies. Since several builds run in parallel, it is
   118   very likely to fail.
   119  
   120   You can solve this by running `go mod download` before calling `goreleaser` or
   121   by adding a [hook][] doing that on your `.goreleaser.yaml` file:
   122  
   123   ```yaml
   124   before:
   125     hooks:
   126     - go mod download
   127   # rest of the file...
   128   ```
   129  
   130   [hook]: /hooks