Closed
Description
The runtime.GOROOT()
function is currently implemented as follows:
- If the
GOROOT
environment variable is set, return its value. - Else, return the value that was burned into the binary at compile time.
Unfortunately, this implementation cannot be relied upon to have any semantic meaning in general.
If the intent is to know what GOROOT the binary was compiled with, then consulting the GOROOT
environment variable is wrong. Instead, the burned in value should be added to debug.BuildInfo
.
If the intent is to know the GOROOT on the current machine, then consulting the burned in value is wrong, as it cannot handle the following (non-exhaustive) scenarios:
- The binary may have been compiled on another machine, with a totally irrelevant
GOROOT
. - The go installation may have been moved since the binary was compiled.
- The
PATH
environment variable may have changed since the binary was compiled. - The current machine might not even have a go installation.
Instead, the go env GOROOT
command should be used. In particular, this change needs to be made for go/build.Default
to function properly in all cases.
Metadata
Metadata
Assignees
Type
Projects
Status
Accepted