github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/builder/config.go (about) 1 package builder 2 3 import ( 4 "fmt" 5 6 "github.com/tinygo-org/tinygo/compileopts" 7 "github.com/tinygo-org/tinygo/goenv" 8 ) 9 10 // NewConfig builds a new Config object from a set of compiler options. It also 11 // loads some information from the environment while doing that. For example, it 12 // uses the currently active GOPATH (from the goenv package) to determine the Go 13 // version to use. 14 func NewConfig(options *compileopts.Options) (*compileopts.Config, error) { 15 spec, err := compileopts.LoadTarget(options) 16 if err != nil { 17 return nil, err 18 } 19 20 if options.OpenOCDCommands != nil { 21 // Override the OpenOCDCommands from the target spec if specified on 22 // the command-line 23 spec.OpenOCDCommands = options.OpenOCDCommands 24 } 25 26 major, minor, err := goenv.GetGorootVersion() 27 if err != nil { 28 return nil, err 29 } 30 if major != 1 || minor < 18 || minor > 22 { 31 // Note: when this gets updated, also update the Go compatibility matrix: 32 // https://github.com/tinygo-org/tinygo-site/blob/dev/content/docs/reference/go-compat-matrix.md 33 return nil, fmt.Errorf("requires go version 1.18 through 1.22, got go%d.%d", major, minor) 34 } 35 36 return &compileopts.Config{ 37 Options: options, 38 Target: spec, 39 GoMinorVersion: minor, 40 TestConfig: options.TestConfig, 41 }, nil 42 }