Go on z/OS

Go on z/OS

Go on z/OS

This group is a space for open discussions and sharing technical information, and also provides a connection to the wider Go open source community for anyone who is interested in Go on z/OS

 View Only

Go on z/OS and the Go Toolchain

By Joon Lee posted Mon October 23, 2023 12:42 PM

  

Go on z/OS and the Go Toolchain

Go is known for its incredible backwards compatibility. A developer with a project written with Go 1.11 can fully expect that their code will run perfectly if they build it with Go 1.20. And with the release of Go 1.21, not only does Go have increased support for it's fantastic backwards compatibility, but it now has measures to better handle forward compatibility thanks to Toolchain Management.

What is the Go Toolchain?

A toolchain is a collection of software development tools. In the case of Go, it consists of the compiler, assembler, the standard library, and various other useful tools. In previous versions of Go, the toolchain was tied to the version of Go you are using. In most cases this is not an issue. However, when your project has a dependency that requires a newer version of Go, then problems start to occur. 

For example, lets say I have Go 1.19 installed and a project I am working on depends on the latest version of module A. Module A recently fixed a major bug in the new version and uses Go 1.21's newer language features like the min and max functions. 

Terminal output of a Go module being built with an incompatible version


Even though module A's go.mod specifies it is using Go 1.21, this doesn't stop my older version of Go from trying to compile module A, resulting in build errors. Note that we are not always guaranteed to get errors when building with an outdated version of Go. If your code doesn't use newer language features but still needs a newer version of Go, compiling with an older version of Go will still succeed and may lead to unexpected errors. This behavior can be frustrating to deal with and is thankfully addressed in Go 1.21. With Go 1.21 and all future releases, the toolchain now considers the go line in a module's go.mod as a minimum required version. This change also allows point releases and release candidate versions to be specified. What this means is that if you are using Go 1.21.0 but your module's go.mod says go 1.21.2, Go will switch to using 1.21.2. 

There is also a new line you can add to your go.mod - toolchain. The go line is for specifying the minimum toolchain version that other modules must have when they depend on your module, while the toolchain line is limited to just within your module.

How to set it up on z/OS

Go on z/OS does not support the automatic downloading of toolchains. Instead it supports the path mode which is enabled by setting GOTOOLCHAIN=path. This can be done by calling go env -w GOTOOLCHAIN=path. Next download and install your desired Go version(s), taking care to add the path to the Go binary to your PATH. In order for Go to detect your other installations you must rename the go binary such that it matches the format go<major>.<minor>.<patch>

In this example, I am using Go 1.21.0 and I've installed Go 1.21.1. I will walkthrough what I would do to enable the Go 1.21.1 toolchain to be used.

Here is a very simple example of toolchain management. Notice that go version is different outside the module.

Conclusion

The Go toolchain comes with useful tools for you to build and run your code. Now, with Go 1.21 you can manage the toolchain version to ensure that your project and it's dependencies can keep up to date with the latest features and fixes. Forwards compatibility is simpler to manage and developers using Go on z/OS can quickly and easily enable toolchain management in minutes with a few commands.

0 comments
19 views

Permalink