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

x/vgo: build defaults to clang, but go build uses gcc #23965

Closed
mpx opened this issue Feb 20, 2018 · 8 comments
Closed

x/vgo: build defaults to clang, but go build uses gcc #23965

mpx opened this issue Feb 20, 2018 · 8 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@mpx
Copy link
Contributor

mpx commented Feb 20, 2018

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

go version go1.10 linux/amd64 vgo:2018-02-20.1

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

$ vgo env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/mark/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/mark/Prog/golang"
GORACE=""
GOROOT="/home/mark/go1.10"
GOTMPDIR=""
GOTOOLDIR="/home/mark/go1.10/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build793572054=/tmp/go-build -gno-record-gcc-switches"
VGOMODROOT=""

Differences from go1.10 to vgo:

$ diff -U0 <(go env) <(vgo env)
--- /dev/fd/63 2018-02-21 09:41:31.642358384 +1100
+++ /dev/fd/62 2018-02-21 09:41:31.642358384 +1100
@@ -14,2 +14,2 @@
-CC="gcc"
-CXX="g++"
+CC="clang"
+CXX="clang++"
@@ -23 +23,2 @@
-GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build308581873=/tmp/go-build -gno-record-gcc-switches"
+GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build660393002=/tmp/go-build -gno-record-gcc-switches"
+VGOMODROOT=""

What did you do?

vgo build with a dependency on CGO:

$ vgo build
# runtime/cgo
exec: "clang": executable file not found in $PATH

What did you expect to see?

vgo should use the same compiler as go.
zdefaultcc.go as shipped by go1.10 linux/amd64 uses gcc/g++.

Separately, perhaps zdefaultcc.go should use cc/c++ instead? It is generally available and could be clang or gcc.

@gopherbot gopherbot added this to the Unreleased milestone Feb 20, 2018
@bradfitz bradfitz modified the milestones: Unreleased, vgo Feb 21, 2018
@rogpeppe
Copy link
Contributor

I can't use vgo to compile code that uses the net package unless I use CGO_ENABLED=0 because of this issue.

@ngrilly
Copy link

ngrilly commented Feb 23, 2018

@rogpeppe As a temporary workaround, have you tried something like CC=gcc vgo build? It worked for me.

@rogpeppe
Copy link
Contributor

@ngrilly Good point! That worked, thanks.

@franciscocpg
Copy link

franciscocpg commented Feb 23, 2018

both CGO_ENABLED=0 vgo build and CC=gcc vgo build works for me.

But I'm still in doubt. Is this a bug (given that the behavior is different from actual go compiler) or is some expected situation for the new vgo implemenation?

@mpx
Copy link
Contributor Author

mpx commented Feb 24, 2018

I expect this is an oversight - zdefaultcc.go is usually generated by go tool dist. When go was duplicated for the vgo experiment it would have inherited the local configuration.

Afaik, using cc/c++ instead of gcc/clang would work in most places, but I'm not familiar with every OS that Go supports. It may be a better choice for wider distribution.

@rsc
Copy link
Contributor

rsc commented Apr 2, 2018

golang.org/x/vgo/vendor/cmd/go/internal/cfg/cfg.go has an objabi function that reads various defaults out of the Go tree source code. There should be a similar function for initializing the default CC settings. (We're avoiding invoking the go command so that there are no problems if someone installs a fake "go" command that invokes vgo.)

@rsc rsc added the NeedsFix The path to resolution is known, but the work has not been done. label Apr 2, 2018
@gopherbot
Copy link

Change https://golang.org/cl/109975 mentions this issue: cmd/go/internal/cfg: read default CC and CXX from Go source code.

elithrar added a commit to elithrar/vgo-docker-example that referenced this issue May 22, 2018
@ulrichSchreiner
Copy link

sorry to comment such an old issue, but with the commit

golang/vgo@2093985

the fix from here (https://go-review.googlesource.com/c/vgo/+/109975/4/vendor/cmd/go/internal/cfg/zdefaultcc.go)

seems to be reverted:

golang/vgo@2093985#diff-983ae2c32b0c34dc25b2df4c51b25940

--> i now get the same error as this ticket describes.

$ vgo build
# runtime/cgo
exec: "clang": executable file not found in $PATH

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

8 participants