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: go build ignores installed packages in GOPATH #26983

Open
yuzhichang opened this Issue Aug 14, 2018 · 10 comments

Comments

Projects
None yet
7 participants
@yuzhichang

yuzhichang commented Aug 14, 2018

Please answer these questions before submitting your issue. Thanks!

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

go version go1.11rc1 linux/amd64

Does this issue reproduce with the latest release?

Yes.

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

GOARCH="amd64"
GOBIN=""
GOCACHE="/home/abclab/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/abclab/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
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-build545148080=/tmp/go-build -gno-record-gcc-switches"

What did you do?

  1. Build and install https://github.com/infinivision/vectodb.
    Note this is cgo wrapper of some C++ code, and requires custom build script and some third-party C++ shared libraries. It cannot be built with standard "go build".
    vectodb is installed to /home/abclab/go/pkg/linux_amd64/github.com/infinivision/vectodb.a.

  2. Try build https://github.com/infinivision/filesyncer (branch replace_dep) with build.sh. This script invokes "GO111MODULE=on go build...".
    I got the error:
    github.com/infinivision/vectodb
    /opt/rh/devtoolset-7/root/usr/libexec/gcc/x86_64-redhat-linux/7/ld: cannot find -lfaiss
    collect2: error: ld returned 1 exit status

It tried to build vectodb with standard "go build", failed with missing an third-party C++ shared library.

What did you expect to see?

"GO111MODULE=on go build..." shall reuse installed packages in GOPATH.

What did you see instead?

"GO111MODULE=on go build..." ignored vectodb.a in GOPATH, tried to build vectodb with standard "go build", and failed.

@mvdan

This comment has been minimized.

Member

mvdan commented Aug 14, 2018

The error you got is related to ld, supposedly your system's linker. Are you sure that's not the issue?

Try running go build -x to see what commands were run.

@andybons

This comment has been minimized.

Member

andybons commented Aug 14, 2018

@yuzhichang

This comment has been minimized.

yuzhichang commented Aug 15, 2018

I'm sure system's linker works since https://github.com/infinivision/vectodb (a cgo wrapper of libfaiss and vectodb.cpp) compilation uses this linker.

https://github.com/infinivision/filesyncer (branch remove_dep) "GO111MODULE=on go build -x" output:

~/go/src/github.com/infinivision/filesyncer/cmd/faceserver ~/go/src/github.com/infinivision/filesyncer
WORK=/tmp/go-build813107023
mkdir -p $WORK/b174/
cd /home/abclab/go/pkg/mod/github.com/infinivision/vectodb@v0.0.0-20180725101234-ba0c4fd4103a
CGO_LDFLAGS='"-g" "-O2" "-L/home/abclab/go/pkg/mod/github.com/infinivision/vectodb@v0.0.0-20180725101234-ba0c4fd4103a/faiss" "-lboost_thread" "-lboost_filesystem" "-lboost_system" "-lglog" "-lgflags" "-lfaiss" "-lopenblas" "-lgomp" "-lstdc++"' /usr/local/go/pkg/tool/linux_amd64/cgo -objdir $WORK/b174/ -importpath github.com/infinivision/vectodb -- -I $WORK/b174/ -g -O2 ./vectodb.go
cd $WORK
gcc -fno-caret-diagnostics -c -x c - || true
gcc -Qunused-arguments -c -x c - || true
gcc -fdebug-prefix-map=a=b -c -x c - || true
gcc -gno-record-gcc-switches -c -x c - || true
cd $WORK/b174
TERM='dumb' gcc -I /home/abclab/go/pkg/mod/github.com/infinivision/vectodb@v0.0.0-20180725101234-ba0c4fd4103a -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b174=/tmp/go-build -gno-record-gcc-switches -I ./ -g -O2 -o ./_x001.o -c _cgo_export.c
TERM='dumb' gcc -I /home/abclab/go/pkg/mod/github.com/infinivision/vectodb@v0.0.0-20180725101234-ba0c4fd4103a -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b174=/tmp/go-build -gno-record-gcc-switches -I ./ -g -O2 -o ./_x002.o -c vectodb.cgo2.c
cd $WORK
g++ -fno-caret-diagnostics -c -x c - || true
g++ -Qunused-arguments -c -x c - || true
g++ -fdebug-prefix-map=a=b -c -x c - || true
g++ -gno-record-gcc-switches -c -x c - || true
cd /home/abclab/go/pkg/mod/github.com/infinivision/vectodb@v0.0.0-20180725101234-ba0c4fd4103a
TERM='dumb' g++ -I . -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b174=/tmp/go-build -gno-record-gcc-switches -I $WORK/b174/ -g -O2 -I/home/abclab/go/pkg/mod/github.com/infinivision/vectodb@v0.0.0-20180725101234-ba0c4fd4103a -o $WORK/b174/_x003.o -c vectodb.cpp
cd $WORK/b174
TERM='dumb' gcc -I /home/abclab/go/pkg/mod/github.com/infinivision/vectodb@v0.0.0-20180725101234-ba0c4fd4103a -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b174=/tmp/go-build -gno-record-gcc-switches -I ./ -g -O2 -o ./_cgo_main.o -c _cgo_main.c
cd /home/abclab/go/pkg/mod/github.com/infinivision/vectodb@v0.0.0-20180725101234-ba0c4fd4103a
TERM='dumb' g++ -I . -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b174=/tmp/go-build -gno-record-gcc-switches -o $WORK/b174/_cgo_.o $WORK/b174/_cgo_main.o $WORK/b174/_x001.o $WORK/b174/_x002.o $WORK/b174/_x003.o -g -O2 -L/home/abclab/go/pkg/mod/github.com/infinivision/vectodb@v0.0.0-20180725101234-ba0c4fd4103a/faiss -lboost_thread -lboost_filesystem -lboost_system -lglog -lgflags -lfaiss -lopenblas -lgomp -lstdc++
# github.com/infinivision/vectodb
/opt/rh/devtoolset-7/root/usr/libexec/gcc/x86_64-redhat-linux/7/ld: cannot find -lfaiss
collect2: error: ld returned 1 exit status

My point is, vectodb compilation uses custom build script, filesyncer cannot build that package with standard "GO111MODULE=on go build". There shall be some way to tell filesyncer that fact.

At filesyncer master branch, there's following line in Gopkg.toml:
ignored = ["github.com/infinivision/vectodb"]
So that filesyncer compilation reuses installed vectodb in GOPATH instead of trying to build it.

@andybons

This comment has been minimized.

Member

andybons commented Aug 15, 2018

@ianlancetaylor

This comment has been minimized.

Contributor

ianlancetaylor commented Aug 16, 2018

There is some difference in the build ID between your installed package and the computation of the build ID done when building filesyncer. The go tool has to decide when a package is out of date, and has to rebuild the package when it is out of date. This works poorly with a package that can not be built with go build.

It might possibly help to treat this package as a binary-only package after you build it. See https://golang.org/cmd/go/#hdr-File_types . I haven't tried this so I don't know whether it will work.

@yuzhichang

This comment has been minimized.

yuzhichang commented Aug 16, 2018

vectodb was built from git revision ba0c4fd4103ad3957bedf12d00b1c6b43fafa0bc, and installed as /home/abclab/go/pkg/linux_amd64/github.com/infinivision/vectodb.a.
In filesyncer go.mod, github.com/infinivision/vectodb v0.0.0-20180725101234-ba0c4fd4103a refers to just that tip revision.
Why installed package and the computation of the build ID when building filesyncer differ?

@rsc

This comment has been minimized.

Contributor

rsc commented Aug 18, 2018

It cannot be built with standard "go build".

How does it get built?

@rsc

This comment has been minimized.

Contributor

rsc commented Aug 18, 2018

Also you have not said explicitly that GO111MODULE=off go build works. Does it?
If so, then probably you just need to run your install script with GO111MODULE=on as well.
If not, then this is not a modules bug and we should unlabel it modules.

@yuzhichang

This comment has been minimized.

yuzhichang commented Aug 18, 2018

vectodb uses custom build script SConstruct. It invokes gcc and "go build".

It works if both vectodb and filesyncer use GO111MODULE=off go build. That's what vectodb master and filesyncer master just do.

I edited vectodb and filesyncer to both use GO111MODULE=on go build. See vectodb master branch and filesyncer remove_dep branch on github.
Then I run SConstruct to build and install this module, and tried to build filesyncer. However filesyncer still failed with the same error(ignored vectodb.a in GOPATH, tried to build vectodb with standard "go build", and failed.)

@bcmills

This comment has been minimized.

Member

bcmills commented Oct 26, 2018

It might possibly help to treat this package as a binary-only package after you build it.

That will not work in module mode today: see #28146.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment