github.com/terramate-io/tf@v0.0.0-20230830114523-fce866b4dfcd/BUILDING.md (about)

     1  # Building from Source
     2  
     3  ## Prerequisites
     4  
     5  1. Ensure you've installed the Go language version specified in [`.go-version`](https://github.com/terramate-io/tf/blob/main/.go-version).
     6  2. Clone this repository to a location of your choice.
     7  
     8  ## Terraform Build Options
     9  
    10  Terraform accepts certain options passed using `ldflags` at build time which control the behavior of the resulting binary.
    11  
    12  ### Dev Version Reporting
    13  
    14  Terraform will include a `-dev` flag when reporting its own version (ex: 1.5.0-dev) unless `version.dev` is set to `no`:
    15  
    16  ```
    17  go build -ldflags "-w -s -X 'github.com/terramate-io/tf/version.dev=no'" -o bin/ .
    18  ```
    19  
    20  ### Experimental Features
    21  
    22  Experimental features of Terraform will be disabled unless `main.experimentsAllowed` is set to `yes`:
    23  
    24  ```
    25  go build -ldflags "-w -s -X 'main.experimentsAllowed=yes'" -o bin/ .
    26  ```
    27  
    28  In the official build process for Terraform, experiments are only allowed in alpha release builds. We recommend that third-party distributors follow that convention in order to reduce user confusion.
    29  
    30  ## Go Options
    31  
    32  For the most part, the Terraform release process relies on the Go toolchain defaults for the target operating system and processor architecture.
    33  
    34  ### `CGO_ENABLED`
    35  
    36  One exception is the `CGO_ENABLED` option, which is set explicitly when building Terraform binaries. For most platforms, we build with `CGO_ENABLED=0` in order to produce a statically linked binary. For MacOS/Darwin operating systems, we build with `CGO_ENABLED=1` to avoid a platform-specific issue with DNS resolution. 
    37  
    38