golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
123.91k stars 17.65k forks source link

x/mobile: Does not work with go.mod `replace` #27324

Closed petethepig closed 5 years ago

petethepig commented 6 years ago

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

$ go version
go version go1.11 darwin/amd64

Does this issue reproduce with the latest release?

Yes

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

$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/username/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/username/.gvm/pkgsets/go1.11/global"
GOPROXY=""
GORACE=""
GOROOT="/Users/username/.gvm/gos/go1.11"
GOTMPDIR=""
GOTOOLDIR="/Users/username/.gvm/gos/go1.11/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/username/go-project/go.mod"
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/zg/ssp6j1213dg2nd1l8wmc1xs40000gn/T/go-build851930379=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I created a very basic go project that illustrates the issue: https://github.com/petethepig/gomobilebug

There's a go.mod file, notice the use of replace:

module github.com/petethepig/gomobilebug

require (
    github.com/google/netstack v0.0.0
    golang.org/x/mobile v0.0.0-20180808221059-bceb7ef27cc6 // indirect
)

replace github.com/google/netstack v0.0.0 => github.com/petethepig/netstack v0.0.0-20171026205909-b4b77f7e31f6

I run gomobile bind -v -target ios .

What did you expect to see?

I expected the command to succeed.

What did you see instead?

Instead the command throws an error:

$ gomobile bind -v -target ios .
type-checking package "." failed (/Users/username/Dev/st/example/main.go:6:2: could not import github.com/google/netstack/tcpip (type-checking package "github.com/google/netstack/tcpip" failed (/Users/username/.gvm/pkgsets/go1.11/global/pkg/mod/github.com/petethepig/netstack@v0.0.0-20171026205909-b4b77f7e31f6/tcpip/tcpip.go:25:2: could not import github.com/google/netstack/tcpip/buffer (cannot find package "github.com/google/netstack/tcpip/buffer" in any of:
    /Users/username/.gvm/gos/go1.11/src/github.com/google/netstack/tcpip/buffer (from $GOROOT)
    /Users/username/.gvm/pkgsets/go1.11/global/src/github.com/google/netstack/tcpip/buffer (from $GOPATH)))))

gomobile: /Users/username/.gvm/pkgsets/go1.11/global/bin/gobind -lang=go,objc -outdir=/var/folders/zg/ssp6j1213dg2nd1l8wmc1xs40000gn/T/gomobile-work-114613772 -tags=ios . failed: exit status 1

It seems like something somewhere fails to properly replace the paths (For example, it searches for github.com/google/netstack/tcpip/buffer package in /Users/username/.gvm/gos/go1.11/src/github.com/google/netstack/tcpip/buffer when it should be searching for it somewhere like /Users/username/.gvm/pkgsets/go1.11/global/pkg/mod/github.com/petethepig/netstack@v0.0.0-20171026205909-b4b77f7e31f6/tcpip/buffer.

Unfortunately I am not that familiar with golang codebase so I need help figuring out how to fix this.

FiloSottile commented 6 years ago

Looks like a partial duplicate of #27300.

evenardo commented 6 years ago

''' env go111module=off gomobile bind ''' it's will temporarily worked fine

myitcv commented 5 years ago

cc @eliasnaur - some time has elapsed since this issue and I'm not sufficiently up to speed to know whether mobile is now modules-aware.

eliasnaur commented 5 years ago

Gomobile has not been converted.

ons. 14. nov. 2018 06.23 skrev Paul Jolly notifications@github.com:

cc @eliasnaur https://github.com/eliasnaur - some time has elapsed since this issue and I'm not sufficiently up to speed to know whether mobile is now modules-aware.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/golang/go/issues/27324#issuecomment-438541489, or mute the thread https://github.com/notifications/unsubscribe-auth/AAgCDL9Avhhu3l2QEDJBjv3NuzrsdjKSks5uu6jegaJpZM4WQkS8 .

agnivade commented 5 years ago

Making https://github.com/golang/go/issues/27234 as the tracker issue for making gomobile module-aware. Closing this one as this just points out that gomobile is not module-aware.