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

go mod causes go get to use cgo when without modules it would not be used #27706

Closed
leighmcculloch opened this issue Sep 17, 2018 · 3 comments
Closed

Comments

@leighmcculloch
Copy link
Contributor

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

go version go1.11 linux/amd64

Does this issue reproduce with the latest release?

Yes.

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

GOARCH="amd64"
GOOS="linux"

What did you do?

Use go get in a directory that has a go.mod.

What did you expect to see?

The package to be installed.

What did you see instead?

# net                                    
exec: "gcc": executable file not found in $PATH

Reproducible example

The reproducible example will attempt to go get github.com/goreleaser/goreleaser. When it gets to the net dependency it will attempt to use gcc when a go.mod file is present in the directory. If CGO_ENABLED=0 is prepended onto the go get command it will not require gcc. Or, if there is no go.mod it will not require gcc.

1. go get without go.mod (success)

FROM debian:stretch

RUN apt-get update
RUN apt-get -y install git curl

# go - install
RUN curl https://dl.google.com/go/go1.11.linux-amd64.tar.gz | tar xz -C /usr/local
ENV GOPATH="$HOME/go"
ENV PATH="${PATH}:/usr/local/go/bin:$GOPATH/bin"

# home
ENV HOME="/root"

# working directory
WORKDIR $HOME

# install goreleaser
RUN go get github.com/goreleaser/goreleaser

Output:

Step 9/9 : RUN go get github.com/goreleaser/goreleaser
 ---> Running in d922d741415c
Removing intermediate container d922d741415c
 ---> 4b1cebf13425
Successfully built 4b1cebf13425
Successfully tagged reproduce-26307-1:latest

2. go get with go.mod (failure)

FROM debian:stretch

RUN apt-get update
RUN apt-get -y install git curl

# go - install
RUN curl https://dl.google.com/go/go1.11.linux-amd64.tar.gz | tar xz -C /usr/local
ENV GOPATH="$HOME/go"
ENV PATH="${PATH}:/usr/local/go/bin:$GOPATH/bin"

# home
ENV HOME="/root"

# working directory
WORKDIR $HOME

# install goreleaser
RUN cd $HOME && go mod init github.com/hello/world && go get github.com/goreleaser/goreleaser

Output:

Step 9/9 : RUN cd $HOME && go mod init github.com/hello/world && go get github.com/goreleaser/goreleaser
 ---> Running in 4d3ac4ccddaa                       
go: creating new go.mod: module github.com/hello/world      
go: finding github.com/goreleaser/goreleaser v0.86.1            
go: downloading github.com/goreleaser/goreleaser v0.86.1
...
go: downloading github.com/google/go-querystring v1.0.0
go: finding golang.org/x/net latest
go: downloading golang.org/x/net v0.0.0-20180911220305-26e67e76b6c3
# net
exec: "gcc": executable file not found in $PATH
The command '/bin/sh -c cd $HOME && go mod init github.com/hello/world && go get github.com/goreleaser/goreleaser' returned a non-zero code: 2

3. CGO_ENABLED=0 go get with go.mod (success)

FROM debian:stretch

RUN apt-get update
RUN apt-get -y install git curl

# go - install
RUN curl https://dl.google.com/go/go1.11.linux-amd64.tar.gz | tar xz -C /usr/local
ENV GOPATH="$HOME/go"
ENV PATH="${PATH}:/usr/local/go/bin:$GOPATH/bin"

# home
ENV HOME="/root"

# working directory
WORKDIR $HOME

# install goreleaser
RUN cd $HOME && go mod init github.com/hello/world && CGO_ENABLED=0 go get github.com/goreleaser/goreleaser

Output:

Step 9/9 : RUN cd $HOME && go mod init github.com/hello/world && CGO_ENABLED=0 go get github.com/goreleaser/goreleaser
 ---> Running in 2679e852359a                                                    
go: creating new go.mod: module github.com/hello/world                      
go: finding github.com/goreleaser/goreleaser v0.86.1   
go: downloading github.com/goreleaser/goreleaser v0.86.1
...
go: downloading github.com/google/go-querystring v1.0.0
go: finding golang.org/x/net latest
go: downloading golang.org/x/net v0.0.0-20180911220305-26e67e76b6c3
Removing intermediate container 2679e852359a
 ---> 45beab603aa4
Successfully built 45beab603aa4
Successfully tagged reproduce-26307-3:latest
@leighmcculloch
Copy link
Contributor Author

leighmcculloch commented Sep 17, 2018

Full example and output logs are available at:
https://github.com/leighmcculloch/go-issue-27706

@myitcv
Copy link
Member

myitcv commented Sep 17, 2018

Probably related to #27285 or #27303?

@bcmills
Copy link
Contributor

bcmills commented Sep 17, 2018

Dup of #26988, I think.

It's not that cgo wouldn't be used otherwise; rather, without modules the library would already be cached (i.e., included in the go toolchain's binary distribution).

@bcmills bcmills closed this as completed Sep 17, 2018
@golang golang locked and limited conversation to collaborators Sep 17, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants