Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: GOARM missing from the go env command #17191

Closed
namsral opened this issue Sep 22, 2016 · 14 comments
Closed

cmd/go: GOARM missing from the go env command #17191

namsral opened this issue Sep 22, 2016 · 14 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@namsral
Copy link
Contributor

namsral commented Sep 22, 2016

Is there a reason GOARM is missing from the go env command?

Somewhat related to #9737 which would fix it for me.

What version of Go are you using (go version)?

go version go1.7.1 darwin/amd64

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/lars/Code/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/sp/5w54k4g94nnc48r5w6yxgyxw0000gn/T/go-build783462244=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"

What did you do?

Run the following command in a shell:

env GOARM=7 go env GOARM

What did you expect to see?

7\n

What did you see instead?

\n

@minux
Copy link
Member

minux commented Sep 22, 2016 via email

@quentinmit quentinmit added the NeedsFix The path to resolution is known, but the work has not been done. label Oct 3, 2016
@quentinmit quentinmit added this to the Go1.8 milestone Oct 3, 2016
@quentinmit quentinmit changed the title GOARM missing from the go env command cmd/go: GOARM missing from the go env command Oct 3, 2016
@quentinmit quentinmit self-assigned this Oct 13, 2016
@quentinmit
Copy link
Contributor

There are several other environment variables documented here:

https://golang.org/cmd/go/#hdr-Environment_variables

We should include all of them, not just GOARM and GO386

@quentinmit
Copy link
Contributor

/cc @rsc

Should we show the CGO-related environment variables when CGO_ENABLED=0?

Also, we're currently showing an environment variable called GOGCCFLAGS, but that's not actually documented as an environment variable. Should I remove that? (Presumably not, for backwards compatibility.)

@ianlancetaylor
Copy link
Contributor

go env GOGCCFLAGS is useful, so we shouldn't remove it. But it's true that it's kind of problematic. Setting the environment variable GOGCCFLAGS does nothing other than change the output of go env. But go env GOGCCFLAGS is useful to pick up the options to pass to the C compiler, which go env currently does not display in any other way.

@quentinmit
Copy link
Contributor

@ianlancetaylor AFAICT the go command does not actually read the GOGCCFLAGS environment variable. It is completely ignored if set in the environment. The actual environment variable to set is CGO_CFLAGS or CGO_CPPFLAGS, though I think those are not actually reflected in the value of GOGCCFLAGS either.

@ianlancetaylor
Copy link
Contributor

Yes, you're right. (But go env GOGCCFLAGS is still useful.)

@quentinmit
Copy link
Contributor

A few more questions that came up:

  • GCCGO contains the name of the gccgo executable to use. But whether or not gccgo is installed, it defaults to the value gccgo. I could instead print the path of the actually-found gccgo executable, but then you'd see GCCGO="" if there is no GCCGO. Is that okay?
  • There is an undocumented CGO_FFLAGS environment variable. Document and print in go env? Or omit?
  • Should GOARM and GO386 always be shown, or only if GOARCH is set to a value that they have an effect on?

@ianlancetaylor
Copy link
Contributor

I think that if we add support for go env GCCGO then it should print gccgo if there is no gccgo on PATH.

We should treat CGO_FFLAGS like CGO_CFLAGS.

My opinion is that we should always print the same set of environment variables from go env, though unfortunately that is already broken as we skip some variables on plan9.

@gopherbot
Copy link

CL https://golang.org/cl/31330 mentions this issue.

@quentinmit
Copy link
Contributor

@ianlancetaylor
So unfortunately the default value of CGO_CFLAGS cannot be printed; it normally defaults to -g -O2 but when we run go tool cgo it defaults to an empty string. If the environment variable is actually set, it is used for both go tool cgo as well as all other compiles.

So I'm left with the only option being to show the actual value of the CGO_CFLAGS environment variable, defaulting to the empty string. I don't love that because it doesn't reveal that -g -O2 is being used by default.

I think I also have to therefore not show the defaults for the other CGO_* environment variables, or else it will again cause confusion because users will think CGO_CFLAGS defaults to empty when the others do not.

Thoughts?

@ianlancetaylor
Copy link
Contributor

As far as I know, go tool cgo does not use CGO_CFLAGS at all. It simply invokes the cgo tool, and the cgo tool takes the compiler options on the command line, not in the environment (except for CGO_LDFLAGS, sigh).

Given that it seems to me that if CGO_CFLAGS is not set then showing the value as "-g -O2" is reasonable.

@ianlancetaylor
Copy link
Contributor

By the way, if any of this seems too crazy we can probably change it.

@quentinmit
Copy link
Contributor

go build uses CGO_CFLAGS when it invokes go tool cgo.

See https://github.com/golang/go/blob/master/src/cmd/go/build.go#L3208

If CGO_CFLAGS is unset, cgoCFLAGS gets the value -g -O2 and cgoexeCFLAGS gets an empty value. If CGO_CFLAGS is set, both cgoCFLAGS and cgoexeCFLAGS get the value of the environment variable. cgoexeCFLAGS is passed to go tool cgo on L3287.

@ianlancetaylor
Copy link
Contributor

ianlancetaylor commented Oct 18, 2016

When I say go build and go tool cgo I am referring to two different command line options. You are of course correct that when go build invokes the cgo tool it passes CGO_CFLAGS. Perhaps my comment will make more sense with that understanding.

@golang golang locked and limited conversation to collaborators Oct 18, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

5 participants