Description
What version of Go are you using (go version
)?
go version go1.10.3 darwin/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="/Users/motomuohtski/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/motomuohtski/go"
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/3t/1rcsh7wn6sb3_w2nbbnp0zc80000gn/T/go-build234195255=/tmp/go-build -gno-record-gcc-switches -fno-common"
What did you do?
- Have a file
${GOPATH}/src/github.com/motomux/hellobop/src/hellobop.go
package hellobop
import "fmt"
func Hello(name string) string {
return fmt.Sprintf("Hello %s from binary-only package!", name)
}
- Have a header file
${GOPATH}/src/github.com/motomux/hellobop/hellobop_header.go
//go:binary-only-package
package hellobop
func Hello(name string) string {
}
-
Build binary by
go build -o ${GOPATH}/pkg/darwin_amd64/github.com/motomux/hellobop.a -x ./src
-
Have a test file
${GOPATH}/src/github.com/motomux/hellobop/test/helloboa_test.go
-
Run test by
go test ./test
-
Run test by
go test -race ./test
Here is the repository to reproduce the issue.
What did you expect to see?
go test -race
runs test without any error.
What did you see instead?
It's failed with the error
go build github.com/motomux/hello: missing or invalid binary-only package
Activity
[-]test: race option doesn't work to test a code with binary-only package[/-][+]cmd/go: race option doesn't work to test a code with binary-only package[/+]iamoryanmoshe commentedon Aug 8, 2018
Can you try adding a -o flag for the build (a target parameter for the output file) and run the test again please?Edit: My bad, didn't notice your'e already compiling with -o.
From the source code it seems the problem originates with the target parameter of the build.
Can you make sure the file exists?
This is the check that makes the test fail (err isn't nil)
Edit 2: can you add the -o parameter to your test line?
slrz commentedon Aug 8, 2018
The binary-only package probably needs to be compiled in race mode, too. The error is about not finding a package archive at pkg/darwin_amd64_race/…
motomux commentedon Aug 8, 2018
@slrz You are right.
After running the following commands
go test
with/without race option worksmotomux commentedon Aug 9, 2018
We don't even need to build with race option to test.
After running the following commands
go test
with/without race option works