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 · 2 comments

Comments

Projects
None yet
3 participants
@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

This comment has been minimized.

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 Dec 3, 2018

@mvdan

This comment has been minimized.

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 this to the Go1.13 milestone Dec 3, 2018

kondanta added a commit to EnvCLI/EnvCLI that referenced this issue Dec 24, 2018

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>

PhilippHeuer added a commit to EnvCLI/EnvCLI that referenced this issue Mar 4, 2019

feature: refactor the codebase into separate packages
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.