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

cmd/go: confusing "build constraints exclude all Go files" error when trying to cross-compile a package that uses CGO #29074

Open
imwaddy opened this issue Dec 3, 2018 · 5 comments
Labels
GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@imwaddy
Copy link

imwaddy commented Dec 3, 2018

go version
go version go1.10.4 linux/amd64

go env
GOARCH="amd64"
GOBIN="/home/mayurw/go/bin"
GOCACHE="/home/mayurw/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/mayurw/go"
GORACE=""
GOROOT="/usr/lib/go-1.10"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go-1.10/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build555451646=/tmp/go-build -gno-record-gcc-switches"

I executed the command
env GOOS=linux GOARCH=arm64 go build
it produced output as bolow
go build github.com/DataDog/zstd: build constraints exclude all Go files in ~/go/src/github.com/DataDog/zstd

I'm really not getting what error it is. Please provide solution to go cross compilation from linux to ARM architecture binaries..

@mvdan
Copy link
Member

mvdan commented Dec 3, 2018

You already opened this issue as DataDog/zstd#46. Please keep the discussion there, as this isn't a bug in Go.

You can't cross-compile a package that uses CGO - that's where the error comes from. You'll see the same error if you try CGO_ENABLED=0 go build.

I honestly don't know if cross compiling with CGO is a good idea, but you could try existing workarounds like https://github.com/karalabe/xgo.

@mvdan mvdan closed this as completed Dec 3, 2018
@mvdan
Copy link
Member

mvdan commented Dec 3, 2018

Actually, I think the error message here could be clearer. On a first scan of the package, there are no Go files with build constraints, so it can seem like the error is wrong. Only if one is aware of CGO does the error make sense.

Perhaps the error should somehow point at CGO instead of saying "build constraints exclude all Go files".

/cc @bcmills @ianlancetaylor

@mvdan mvdan reopened this Dec 3, 2018
@mvdan mvdan changed the title cannot cross-compile arm binary on x86 platform cmd/go: confusing "build constraints exclude all Go files" error when trying to cross-compile a package that uses CGO Dec 3, 2018
@bcmills bcmills added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. GoCommand cmd/go labels Dec 3, 2018
@bcmills bcmills added this to the Go1.13 milestone Dec 3, 2018
kondanta pushed a commit to EnvCLI/EnvCLI that referenced this issue Dec 24, 2018
I am working on seperating each module but I've stumbled upon
something that may effect this repository as well: **When the command line specifies a single main package,
build writes the resulting executable to output.
Otherwise build compiles the packages but discards the results,
serving only as a check that the packages can be built.**

Using `go build ./..` works as intended but using envcli to simulate
this function causes `src/app.go:10:2: cannot find package
"github.com/EnvCLI/EnvCLI/pkg/config" in any of:`
I am still investigating this issue but since go run src/* works I am
committing this change.

Also, golang/go#29074 there's this issue.
Signed-off-by: Taylan Dogan <doganntaylan@gmail.com>
PhilippHeuer added a commit to EnvCLI/EnvCLI that referenced this issue Mar 4, 2019
Create config package for config related operations and models.

Though I am not sure each and every function that exported used by
some other components. If they're not, I'll fix them later.
Signed-off-by: Taylan Dogan <doganntaylan@gmail.com>

Refactor docker

I am working on seperating each module but I've stumbled upon
something that may effect this repository as well: **When the command line specifies a single main package,
build writes the resulting executable to output.
Otherwise build compiles the packages but discards the results,
serving only as a check that the packages can be built.**

Using `go build ./..` works as intended but using envcli to simulate
this function causes `src/app.go:10:2: cannot find package
"github.com/EnvCLI/EnvCLI/pkg/config" in any of:`
I am still investigating this issue but since go run src/* works I am
committing this change.

Also, golang/go#29074 there's this issue.
Signed-off-by: Taylan Dogan <doganntaylan@gmail.com>

Rename /config/util to utils

Signed-off-by: Taylan Dogan <doganntaylan@gmail.com>

Refactor Updater

As I've mentioned on previous commits, "cannot find package" issue
still exists. Though plain "go build -o src/*" works for now. I still
couldn't figured out why building with envcli causes broken packages though.
Signed-off-by: Taylan Dogan <doganntaylan@gmail.com>

Quick Fix: Adding alias to import

fix: go project dir so that package imports work


refactor: aliases and removed classes


Refactor Volume Mounting in Docker

Refactor Publishing Ports in Docker

Signed-off-by: Taylan Dogan <doganntaylan@gmail.com>

Refactor SetEnvironmentVariables in Docker

Signed-off-by: Taylan Dogan <doganntaylan@gmail.com>

Refactor Check CI

Signed-off-by: Taylan Dogan <doganntaylan@gmail.com>

Change comment line on ContainerExec

Rename isCISet to setTerminalParameters


isCIEnvironment should return a boolean
@andybons andybons modified the milestones: Go1.13, Go1.14 Jul 8, 2019
@guymguym
Copy link

guymguym commented Jul 9, 2019

Hi!
Is the case I see below with go generate is the same CGO case or different?
I tried with both CGO enabled and disabled.

$ CGO_ENABLED="0" go generate
can't load package: package github.com/noobaa/noobaa-operator: build constraints exclude all Go files in ...
$ CGO_ENABLED="1" go generate
can't load package: package github.com/noobaa/noobaa-operator: build constraints exclude all Go files in ...

Thanks

@bcmills
Copy link
Contributor

bcmills commented Jul 9, 2019

@guymguym, that symptom is not this issue.

I see that the only .go source file in github.com/nooba/nooba-operator is tagged // +build tools — did you mean to pass a specific package name to go generate? (By default, go generate — like go subcommands in general — operates on the package in the current working directory.)

@hoehermann
Copy link

Hi folks
I stumbled accross this issue when trying to cross-compile a shared library implemented in go on a Linux amd64 host for a win32 target. karalabe/xgo uses docker and the machines at my hand do not support docker. However, I had success running the go compiler in wine 5.0. Maybe this helps someone else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

7 participants