hyperledger / fabric-contract-api-go

Packages for the implementation of the contract API for use in Go chaincode
https://wiki.hyperledger.org/display/fabric
Apache License 2.0
221 stars 103 forks source link

Use full go version in go.mod #140

Closed bestbeforetoday closed 4 months ago

bestbeforetoday commented 4 months ago

From Go 1.21, in the absence of a toolchain line in the go.mod file, the go line is used as the minimum toolchain version. Toolchain versions must be a full Go version, including patch level.

denyeart commented 4 months ago

At least for core fabric, my plan was to add toolchain support if/when we needed to build with a specific version. Can you explain the benefit if we don't require building with a specific version? We should probably be consistent across all the fabric repositories so I just want to understand the rationale better before pulling the trigger.

bestbeforetoday commented 4 months ago

Go 1.21 and later uses toolchains. You don't add toolchain support. If no toolchain is specified in the go.mod file, the version specified by the go directive is also used as the toolchain. Toolchain versions must be a full Go version number, not just a Go language version. Although everything still seems to work OK for me as-is, CodeQL scans generate the following warning with only a go 1.21 line and no toolchain:

Invalid Go toolchain version As of Go 1.21, toolchain versions must use the 1.N.P syntax. 1.21 in go.mod does not match this syntax and there is no additional toolchain directive, which may cause some go commands to fail.

The Go documentation says that the go get command should be used to manage these go.mod entries rather than modifying them by hand. Running go get go@1.21 right now results in these go.mod entries:

go 1.21.11

toolchain go1.22.4

I don't want to require Go 1.21.11 and I don't want to recommend a minimum of Go 1.22.4 to build the code. Specifying either only the go directive or both the go and toolchain directives as 1.21.0 seems to be the best option to comply with the current Go documentation.

Running go get go@1.21.0 toolchain@none results in exactly the go.mod entries in this PR.

denyeart commented 4 months ago

Ok thanks, I'll plan on doing the same for our other repositories.

I think my other merge created conflicts in this PR...

denyeart commented 4 months ago

@bestbeforetoday Next one, could you review - https://github.com/hyperledger/fabric-chaincode-go/pull/112