golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
121.16k stars 17.37k forks source link

cmd/go: not print not-defaults arch-env #67492

Open qiulaidongfeng opened 1 month ago

qiulaidongfeng commented 1 month ago

Go version

go version devel go1.23-38d8d01d3f Sat May 18 09:38:57 2024 +0800 windows/amd64

Output of go env in your module/workspace:

no need.

What did you do?

set GOAMD64=v3 ./make.bat ..\bin\go env -changed

What did you see happen?

not print set GOAMD64=v3

What did you expect to see?

print set GOAMD64=v3

gopherbot commented 1 month ago

Change https://go.dev/cl/586241 mentions this issue: cmd/go: print not-defaults arch-env

matloob commented 1 month ago

I think the current behavior might be correct? When you run make.bat with GOAMD64=v3 you're essentially setting the default value for your go build to be v3. Then when you run env -changed, the default value is the same as the value in the environment so there should be no diff printed.

qiulaidongfeng commented 1 month ago

But I use

set GOAMD64=v1
make.bat
set GOAMD64=v3
..\bin\go env -changed

still won't print set GOAMD64=v3

qiulaidongfeng commented 1 month ago

For now, all arch-env , call EnvOrAndChanged the second parameter set now appears to be wrong, and its value is the relevant environment variable. (This means that there will be no non-default values because go will not get different values in internal/buildcfg and cmd/go/internal/cfg for the same environment variable such as GOAMD64.)

qiulaidongfeng commented 1 month ago

See https://go.dev/wiki/MinimumRequirements#amd64 , GOAMD64 default value is v1, set GOAMD64=v3 happen default value is v3 Nonconformity documentation.

matloob commented 1 month ago

Ultimately I think someone more familiar with dist and the GO microarchitecture variables should make the decision. But from my perspective the the "default" behavior is what happens when you don't change the environment.

Also we shouldn't be changing anything outside of the go command.

The behavior in

set GOAMD64=v1 make.bat set GOAMD64=v3 ..\bin\go env -changed

not printing set GOAMD64=v3 does seem incorrect. but we should be able to detect that without changing dist or the runtime

qiulaidongfeng commented 1 month ago

not printing set GOAMD64=v3 does seem incorrect. but we should be able to detect that without changing dist or the runtime

Most arch-env can, PR fix has been sent.

gopherbot commented 1 month ago

Change https://go.dev/cl/587177 mentions this issue: cmd/go: print some not-defaults arch-env

qiulaidongfeng commented 4 days ago

@matloob See https://go-review.googlesource.com/c/go/+/587177/comments/6ed22174_daf6f755?tab=comments , For now should submit https://go-review.googlesource.com/c/go/+/586241 or do other fix method?

qiulaidongfeng commented 4 days ago

I now confirm that when GOAMD64=v3, the default value of GOAMD64 is v3. If CL 586241 is going in the right direction, I can modify CL to ensure that the go command prints the default correctly and retain the current behavior of bootstrapping-when GOAMD64=v3, which defaults to v3.

matloob commented 2 days ago

I'm uncomfortable with exporting the defaultGO variables in buildcfg, but I can't think of a better way to do this. I wonder what the compiler team thinks about this. @cherrymui what do you think about exporting the defaultGO variables in buildcfg. Do you think that's okay?