Skip to content

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

Closed
@leighmcculloch

Description

@leighmcculloch

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions