2023-04-10 17:57:24 -05:00
# Building from Source
2023-08-21 06:55:29 -05:00
If you'd like to build OpenTF from source, you can do so using the Go build toolchain and the options specified in this document.
2023-04-10 17:57:24 -05:00
## Prerequisites
2023-08-17 07:45:11 -05:00
1. Ensure you've installed the Go language version specified in [`.go-version` ](https://github.com/placeholderplaceholderplaceholder/opentf/blob/main/.go-version ).
2023-04-10 17:57:24 -05:00
2. Clone this repository to a location of your choice.
2023-08-21 06:55:29 -05:00
## OpenTF Build Options
2023-04-10 17:57:24 -05:00
2023-08-21 06:55:29 -05:00
OpenTF accepts certain options passed using `ldflags` at build time which control the behavior of the resulting binary.
2023-04-10 17:57:24 -05:00
### Dev Version Reporting
2023-08-21 06:55:29 -05:00
OpenTF will include a `-dev` flag when reporting its own version (ex: 1.5.0-dev) unless `version.dev` is set to `no` :
2023-04-10 17:57:24 -05:00
```
2023-08-17 07:45:11 -05:00
go build -ldflags "-w -s -X 'github.com/placeholderplaceholderplaceholder/opentf/version.dev=no'" -o bin/ .
2023-04-10 17:57:24 -05:00
```
### Experimental Features
2023-08-21 06:55:29 -05:00
Experimental features of OpenTF will be disabled unless `main.experimentsAllowed` is set to `yes` :
2023-04-10 17:57:24 -05:00
```
go build -ldflags "-w -s -X 'main.experimentsAllowed=yes'" -o bin/ .
```
## Go Options
2023-08-21 06:55:29 -05:00
For the most part, the OpenTF release process relies on the Go toolchain defaults for the target operating system and processor architecture.
2023-07-17 13:56:13 -05:00
### `CGO_ENABLED`
2023-08-21 06:55:29 -05:00
One exception is the `CGO_ENABLED` option, which is set explicitly when building OpenTF 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.
2023-04-10 17:57:24 -05:00