versionhack

package
v1.21.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 1, 2026 License: BSD-2-Clause Imports: 3 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package versionhack makes sure go/build doesn't disable module support whenever GopherJS is compiled by a different Go version than it's targeted Go version.

Under the hood, go/build relies on `go list` utility for module support; more specifically, for package location discovery. Since ReleaseTags are effectively baked into the go binary and can't be overridden, it needs to ensure that ReleaseTags set in a go/build.Context instance match the Go tool.

However, it naively assumes that the go tool version in the PATH matches the version that was used to build GopherJS and disables module support whenever ReleaseTags in the context are set to anything other than the default. This, unfortunately, isn't very helpful since gopherjs may be built by a Go version other than the PATH's default.

Luckily, even if go tool version is mismatched, it's only used for discovery of the package locations, and go/build evaluates build constraints on its own with ReleaseTags we've passed.

A better solution would've been for go/build to use go tool from GOROOT and check its version against build tags: https://github.com/golang/go/issues/46856.

Until that issue is fixed, we trick go/build into thinking that whatever ReleaseTags we've passed are indeed the default. We gain access to the variable go/build checks against using "go:linkname" directive and override its content as we wish.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL