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

Comments

@mpx
Copy link
Contributor

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

This comment has been minimized.

Copy link
Contributor

commented Feb 23, 2018

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

@ngrilly

This comment has been minimized.

Copy link

commented Feb 23, 2018

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

@rogpeppe

This comment has been minimized.

Copy link
Contributor

commented Feb 23, 2018

@ngrilly Good point! That worked, thanks.

@franciscocpg

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link
Contributor Author

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

This comment has been minimized.

Copy link
Contributor

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 label Apr 2, 2018

@gopherbot

This comment has been minimized.

Copy link

commented Apr 27, 2018

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

This comment has been minimized.

Copy link

commented Jul 31, 2018

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

@golang golang locked and limited conversation to collaborators Jul 31, 2019

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
8 participants
You can’t perform that action at this time.