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

make.bash: CC_FOR_${GOOS}_${GOARCH} not documented #51306

Closed
rittneje opened this issue Feb 21, 2022 · 4 comments
Closed

make.bash: CC_FOR_${GOOS}_${GOARCH} not documented #51306

rittneje opened this issue Feb 21, 2022 · 4 comments
Labels
Documentation FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@rittneje
Copy link

rittneje commented Feb 21, 2022

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

$ go version
1.17.7

Does this issue reproduce with the latest release?

Yes.

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

Relevant env vars (darwin):

CC=gcc
CC_FOR_TARGET=clang
CXX_FOR_TARGET=clang++
GOOS=darwin
GOARCH=amd64
GOHOSTOS=linux
GOHOSTARCH=amd64

Relevant env vars (windows):

CC=gcc
CC_FOR_TARGET=gcc
CXX_FOR_TARGET=g++
GOOS=windows
GOARCH=amd64
GOHOSTOS=linux
GOHOSTARCH=amd64

What did you do?

Ran make.bash.

What did you expect to see?

I expected it to produce a compiler that runs on darwin with clang as the default CC, and a compiler that runs on windows with gcc as the default CC.

What did you see instead?

For GOOS=darwin it tries to use CC_FOR_TARGET, and then claims that CC isn't set.

go tool dist: cannot invoke C compiler "clang": exec: "clang": executable file not found in $PATH

Go needs a system C compiler for use with cgo.
To set a C compiler, set CC=the-compiler.
To disable cgo, set CGO_ENABLED=0.

For GOOS=windows it tries to pass Windows-only flags to the Linux C compiler.

# runtime/cgo
gcc: error: unrecognized command-line option '-mthreads'; did you mean '-pthread'?
go tool dist: FAILED: /opt/go/pkg/tool/linux_amd64/go_bootstrap install -gcflags=all= -ldflags=all=-s -w std cmd: exit status 2

If I try with CGO_ENABLED=0, then the resulting compiler has CGO_ENABLED=0 by default when run on the target, which is undesirable. (#51305)

The intent of passing CC_FOR_TARGET and CXX_FOR_TARGET is to burn these default values into the resulting compiler, not to actually use them while building the compiler. For example, the pre-canned macos toolchain knows to use clang by default instead of gcc, and we want to replicate this.

@ianlancetaylor
Copy link
Contributor

The CC_FOR_TARGET environment variable should be set to a C compiler that runs on the host machine (the machine on which you are running make.bash) and generates code that runs on the target machine (the machine described by the GOOS/GOARCH settings).

You are trying to set it do something different, but that's not what it's for. To do what you want, set an environment variable like CC_FOR_DARWIN_AMD64

@rittneje
Copy link
Author

You are trying to set it do something different, but that's not what it's for. To do what you want, set an environment variable like CC_FOR_DARWIN_AMD64

Oh, yes, that is the one I was thinking of. It is currently missing from the make.bash documentation, but is mentioned in the cgo documentation. Can it be added? https://github.com/golang/go/blob/master/src/make.bash

@ianlancetaylor
Copy link
Contributor

Sure, want to send a patch?

@ianlancetaylor ianlancetaylor changed the title make.bash: cannot set default CC/CXX while cross-compiling make.bash: CC_FOR_${GOOS}_${GOARCH} not documented Feb 22, 2022
@ianlancetaylor ianlancetaylor added Documentation help wanted NeedsFix The path to resolution is known, but the work has not been done. labels Feb 22, 2022
@ianlancetaylor ianlancetaylor added this to the Backlog milestone Feb 22, 2022
uji added a commit to uji/go that referenced this issue Feb 27, 2022
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/388176 mentions this issue: make.bash: add document of CC_FOR_${GOOS}_${GOARCH}

uji added a commit to uji/go that referenced this issue Mar 1, 2022
uji added a commit to uji/go that referenced this issue Mar 1, 2022
@golang golang locked and limited conversation to collaborators Apr 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Documentation FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants