golang / go

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

x/mobile/cmd/gomobile: bind fails with interface syntax #27297

Open forsaken628 opened 6 years ago

forsaken628 commented 6 years ago

Please answer these questions before submitting your issue. Thanks!

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

go version go1.11 darwin/amd64 gomobile version +bceb7ef Wed Aug 8 22:10:59 2018 +0000 (android,ios); androidSDK=

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/michael/Library/Caches/go-build" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="darwin" GOOS="darwin" GOPATH="/Users/michael/Projects/golang" GOPROXY="" GORACE="" GOROOT="/usr/local/Cellar/go/1.11/libexec" GOTMPDIR="" GOTOOLDIR="/usr/local/Cellar/go/1.11/libexec/pkg/tool/darwin_amd64" GCCGO="gccgo" CC="clang" CXX="clang++" 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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/bd/rnhtmc553vvcm_ty8nt2tv4c0000gn/T/go-build433537712=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I'm try to build v2ray for ios app.

gomobile bind -target=ios v2ray.com/core

fail:

gomobile: darwin-arm: go build -tags ios -buildmode=c-archive -o /var/folders/bd/rnhtmc553vvcm_ty8nt2tv4c0000gn/T/gomobile-work-288847091/core-arm.a gobind failed: exit status 2
# gobind
/var/folders/bd/rnhtmc553vvcm_ty8nt2tv4c0000gn/T/gomobile-work-288847091/src/gobind/go_coremain.go:1258:9: cannot use (*proxycore_OutboundHandler)(_res_ref) (type *proxycore_OutboundHandler) as type core.OutboundHandler in assignment:
        *proxycore_OutboundHandler does not implement core.OutboundHandler (missing Dispatch method)
/var/folders/bd/rnhtmc553vvcm_ty8nt2tv4c0000gn/T/gomobile-work-288847091/src/gobind/go_coremain.go:1273:9: cannot use (*proxycore_OutboundHandler)(_res_ref) (type *proxycore_OutboundHandler) as type core.OutboundHandler in assignment:
        *proxycore_OutboundHandler does not implement core.OutboundHandler (missing Dispatch method)

a simplified case like this

package hello

//import "context"
//
//type A interface {
//  Run(ctx context.Context)
//}
//
//type BB interface {
//  GetA() A
//}

//------- or -------

type C bool

type A interface {
    AA() C
}

type BB interface {
    AAA() A
}
gomobile bind -target=ios v2ray.com/core/hello

result

gomobile: darwin-arm: go build -tags ios -buildmode=c-archive -o /var/folders/bd/rnhtmc553vvcm_ty8nt2tv4c0000gn/T/gomobile-work-922396824/hello-arm.a gobind failed: exit status 2
# gobind
/var/folders/bd/rnhtmc553vvcm_ty8nt2tv4c0000gn/T/gomobile-work-922396824/src/gobind/go_hellomain.go:55:9: cannot use (*proxyhello_A)(_res_ref) (type *proxyhello_A) as type hello.A in assignment:
        *proxyhello_A does not implement hello.A (missing AA method)

What did you expect to see?

Success build

xfxdev commented 5 years ago

same problem:(

wseternal commented 5 years ago

in the interface method signature: AA() C, C (return value type) is not supported by gobind. use bool directly, instead of define a new type C.

you can add -work parameter to the gobind commandline to keep the temporary workspace contents when error occurred, then check the corresponding .go file and try to search "skip" keyword for detail error information.