aboutsummaryrefslogtreecommitdiffhomepage
path: root/goenv
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2024-10-12 11:10:21 +0200
committerAyke <[email protected]>2024-10-18 17:43:17 +0200
commitac5f84e3d7b837643507fbd2b5af44b81a61af2e (patch)
tree9112b2a7e9ec8a54e3543757d60d865ed6e3df68 /goenv
parent9583439be46fed7e5a782b384f65bb27788ba487 (diff)
downloadtinygo-ac5f84e3d7b837643507fbd2b5af44b81a61af2e.tar.gz
tinygo-ac5f84e3d7b837643507fbd2b5af44b81a61af2e.zip
builder: check for Go toolchain version used to compile TinyGo
This shows a much better error message for issues like this one: https://github.com/NixOS/nixpkgs/pull/341170#issuecomment-2359237471 The new error message would be: cannot compile with Go toolchain version go1.23 (TinyGo was built using toolchain version go1.21.4)
Diffstat (limited to 'goenv')
-rw-r--r--goenv/version.go12
1 files changed, 9 insertions, 3 deletions
diff --git a/goenv/version.go b/goenv/version.go
index 1db5a630a..cdfa278bd 100644
--- a/goenv/version.go
+++ b/goenv/version.go
@@ -34,19 +34,25 @@ func GetGorootVersion() (major, minor int, err error) {
if err != nil {
return 0, 0, err
}
+ return Parse(s)
+}
- if s == "" || s[:2] != "go" {
+// Parse parses the Go version (like "go1.3.2") in the parameter and return the
+// major and minor version: 1 and 3 in this example. If there is an error, (0,
+// 0) and an error will be returned.
+func Parse(version string) (major, minor int, err error) {
+ if version == "" || version[:2] != "go" {
return 0, 0, errors.New("could not parse Go version: version does not start with 'go' prefix")
}
- parts := strings.Split(s[2:], ".")
+ parts := strings.Split(version[2:], ".")
if len(parts) < 2 {
return 0, 0, errors.New("could not parse Go version: version has less than two parts")
}
// Ignore the errors, we don't really handle errors here anyway.
var trailing string
- n, err := fmt.Sscanf(s, "go%d.%d%s", &major, &minor, &trailing)
+ n, err := fmt.Sscanf(version, "go%d.%d%s", &major, &minor, &trailing)
if n == 2 && err == io.EOF {
// Means there were no trailing characters (i.e., not an alpha/beta)
err = nil