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

x/mobile: build failing when using go modules #27234

Open
mirza-s opened this issue Aug 26, 2018 · 39 comments

Comments

@mirza-s
Copy link

@mirza-s mirza-s commented Aug 26, 2018

What version of Go are you using (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)?

GOARCH="amd64"
GOBIN="/Users/mbp/go/bin"
GOCACHE="/Users/mbp/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/mbp/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/mbp/wrk/src/libfp/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/nt/0hzfppd92jvbk99fhvnhy8ph0000gn/T/go-build526348344=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

gomobile bind -target=android .

What did you expect to see?

Normal build as when building inside GOPATH

What did you see instead?

gomobile: go build -buildmode=c-shared -o=/var/folders/nt/0hzfppd92jvbk99fhvnhy8ph0000gn/T/gomobile-work-327189385/android/src/main/jniLibs/armeabi-v7a/libgojni.so gobind failed: exit status 1
go: finding github.com/dustin/go-humanize v0.0.0-20180713052910-9f541cc9db5d
go: finding golang.org/x/mobile v0.0.0-20180808221059-bceb7ef27cc6
can't load package: package gobind: unknown import path "gobind": cannot find module providing package gobind
@hajimehoshi

This comment has been minimized.

Copy link
Contributor

@hajimehoshi hajimehoshi commented Sep 10, 2018

Hi, what's going on this?

@wangyun

This comment has been minimized.

Copy link

@wangyun wangyun commented Sep 19, 2018

I have the same issue but with some different error message:

gomobile: /home/wangyun/dev/gopath/bin/gobind -lang=go,java -outdir=/tmp/gomobile-work-948078978 testaar failed: exit status 1
unable to import bind: cannot find package "golang.org/x/mobile/bind" in any of:
/home/wangyun/dev/software/go/src/golang.org/x/mobile/bind (from $GOROOT)
/home/wangyun/dev/gopath/src/golang.org/x/mobile/bind (from $GOPATH)
unable to import bind: cannot find package "golang.org/x/mobile/bind" in any of:
/home/wangyun/dev/software/go/src/golang.org/x/mobile/bind (from $GOROOT)
/home/wangyun/dev/gopath/src/golang.org/x/mobile/bind (from $GOPATH)
unable to import bind/java: cannot find package "golang.org/x/mobile/bind/java" in any of:
/home/wangyun/dev/software/go/src/golang.org/x/mobile/bind/java (from $GOROOT)
/home/wangyun/dev/gopath/src/golang.org/x/mobile/bind/java (from $GOPATH)

I'm using go 1.11 and updated gomobile, gobind to the latest version.

@evenardo

This comment has been minimized.

Copy link

@evenardo evenardo commented Oct 10, 2018

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

@myitcv

This comment has been minimized.

Copy link
Member

@myitcv myitcv commented Nov 14, 2018

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

This comment has been minimized.

Copy link
Contributor

@eliasnaur eliasnaur commented Nov 14, 2018

@glenfordwilliams

This comment has been minimized.

Copy link

@glenfordwilliams glenfordwilliams commented Nov 28, 2018

is there work currently being done on this front?

@eliasnaur

This comment has been minimized.

Copy link
Contributor

@eliasnaur eliasnaur commented Nov 28, 2018

Not yet, at least not from my side. Partly because of time available, partly because I prefer to wait for module support to mature (GO111MODULE always on, the go/packages package feature complete and so on), but the main stumbling block is that I can't see the gomobile bind mode work as usual in module mode, at least not in its current form.
The problem is vendoring: gomobile bind generates a main package that in turn imports the packages you want to export to Java or Objective C. That works well in GOPATH mode, but not in module mode. Suppose gomobile bind in module mode generates a module containing a main package and your module as a dependency. Then, because vendored packages are only respected for the main module, any vendored packages from your module will be ignored by the go tool.
Perhaps some form of #26640 will help gomobile. Perhaps gomobile bind should work in a different way. I haven't thought that much about it.

@eliasnaur

This comment has been minimized.

Copy link
Contributor

@eliasnaur eliasnaur commented Nov 28, 2018

I started a conversation about gomobile and modules here: https://groups.google.com/forum/#!topic/golang-dev/C0ip7pFC2Oc

One question I would like you to ponder on that thread is whether it would be acceptable to require gomobile users to first generate glue code with the gobind tool and then only let the gomobile tool do the final packaging.

@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Mar 12, 2019

Change https://golang.org/cl/167180 mentions this issue: all: add go.mod

@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Mar 12, 2019

Change https://golang.org/cl/167179 mentions this issue: all: set GO111MODULE=off explicitly in bind tests

gopherbot pushed a commit to golang/mobile that referenced this issue Mar 13, 2019
Updates golang/go#27234
Updates golang/go#30228

Change-Id: Ibe281480398ff9d8c27657f399159885a75f646e
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/167179
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
gopherbot pushed a commit to golang/mobile that referenced this issue Mar 13, 2019
Commands run:
	go mod init
	go mod edit -go=1.11
	go mod tidy
	go list -m all
	go test ./...

Updates golang/go#30228
Updates golang/go#27234

Change-Id: Ibf3b104bfaa037e1a94a5327b5a56983d9744e73
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/167180
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Mar 16, 2019

Change https://golang.org/cl/167659 mentions this issue: cmd/gomobile: explicitly disable modules

gopherbot pushed a commit to golang/mobile that referenced this issue Mar 16, 2019
Gomobile doesn't support modules.

Updates golang/go#27234

Change-Id: I426db1600eafd4a9ddc7eb239f5f264756f1ba35
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/167659
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
@mehrvarz

This comment has been minimized.

Copy link

@mehrvarz mehrvarz commented Mar 17, 2019

Hi, I use modules heavily in my projects. Unfortunately, this makes using gomobile rather difficult. When do you expect gomobile to support modules? Any updates on this?

@hajimehoshi

This comment has been minimized.

Copy link
Contributor

@hajimehoshi hajimehoshi commented Mar 17, 2019

I was wondering whether packages that use major versions like /v2 are available with go mobile or not.

anacrolix added a commit to anacrolix/torrent that referenced this issue Mar 22, 2019
@chrisprobst

This comment has been minimized.

Copy link

@chrisprobst chrisprobst commented Apr 17, 2019

We also need this feature desperately!

@balupton

This comment has been minimized.

Copy link

@balupton balupton commented Apr 18, 2019

Are there any workarounds for the meantime?

@cryptix

This comment has been minimized.

Copy link

@cryptix cryptix commented Apr 18, 2019

@balupton / @chrisprobst: I use go mod vendor then switch GO111MODULE=off and build it as a regular vendored project.

@torbenschinke

This comment has been minimized.

Copy link

@torbenschinke torbenschinke commented May 7, 2019

@balupton / @chrisprobst: We basically also use go mod vendor. However I've created a small tool (GoUp) which automates this process for us.

gopherbot pushed a commit to golang/mobile that referenced this issue Aug 14, 2019
This CL is a pure refactoring to replace go/build usage with
golang.org/x/tools/go/packages. This is a preparation for Go
modules.

Updates golang/go#27234

Change-Id: I3e6a30b962da1a64bc43a89a7f02c03d559f86d3
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/189597
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Aug 16, 2019

Change https://golang.org/cl/190477 mentions this issue: cmd/gobind: remove the workaround for go/packages

@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Aug 16, 2019

Change https://golang.org/cl/190478 mentions this issue: bind/java: make the try-bots happy

@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Aug 16, 2019

Change https://golang.org/cl/190479 mentions this issue: cmd/gobind: fix issue at build tags

@gazhayes

This comment has been minimized.

Copy link

@gazhayes gazhayes commented Aug 25, 2019

#33822 is possible related.

@hajimehoshi

This comment has been minimized.

Copy link
Contributor

@hajimehoshi hajimehoshi commented Aug 26, 2019

As #33807 says, Go with modules cannot understand reverse binding imports, starting with Java or ObjC, since they are not valid FQDNs. I think it is not obvious how to solve this. My current ideas are:

  1. Fix the Go compiler to recognize imports for reverse binding
  2. Make reverse binding valid only when GO111MODULE=off, and revisit this problem later
  3. Give up reverse binding :-/

I think 2. is the most feasible. 1. requires specification change and would be very controversial. @hyangah, @eliasnaur, what do you think?

gopherbot pushed a commit to golang/mobile that referenced this issue Aug 26, 2019
* Correctly format build tags to pass into go/packages
* Removes CGO_ENABLED=0 from a packages.Load configuration
* Calls go/packages.Load twice to work around a build cache
* staleness issue

These bugs were introduced by CL 189597.

Updates golang/go#27234.
Updates golang/go#33687.

Change-Id: I3ae6737bf53bbecda0c7e25885b9c6aea5779332
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/190479
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
@hyangah

This comment has been minimized.

Copy link
Contributor

@hyangah hyangah commented Aug 26, 2019

@hajimehoshi let's go with 2. Go with modules can understand non-url like import path but only when they are either standard packages or packages in the main module which defines the workspace.

I will take a look at 1 this week.

@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Aug 30, 2019

Change https://golang.org/cl/192599 mentions this issue: bind/java, bind/objc: do not use module for reverse binding

gopherbot pushed a commit to golang/mobile that referenced this issue Aug 30, 2019
Reverse binding is not available with Go module, and some tests
fail due to this. This CL suppresses the errors by disabling Go
modules explicitly.

Updates golang/go#27234

Change-Id: I7483c1dab468548a2efa05ca426addf5c3d97b6e
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/192599
Run-TryBot: Hajime Hoshi <hajimehoshi@gmail.com>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
@timcooijmans

This comment has been minimized.

Copy link
Contributor

@timcooijmans timcooijmans commented Sep 5, 2019

@hyangah does this mean you're still looking for a solution to allow reverse-binding? Reverse binding is a very important feature for gomobile in my opinion.

@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Oct 25, 2019

Change https://golang.org/cl/203397 mentions this issue: cmd/gobind: replace go/bind with go/packages in gen.go

gopherbot pushed a commit to golang/mobile that referenced this issue Oct 25, 2019
This is preparation to support Go module.

Updates golang/go#27234

Change-Id: I8dcaed231e877e81d2072c7c85321c0acb6a8b1b
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/203397
Run-TryBot: Hajime Hoshi <hajimehoshi@gmail.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Oct 25, 2019

Change https://golang.org/cl/203399 mentions this issue: cmd/gobind: remove go/build and go/import usages from main.go

gopherbot pushed a commit to golang/mobile that referenced this issue Oct 31, 2019
This change removes the usages of go/build and go/import, that don't
work with Go module.

Before this change:

  1) Package information is retrieved by go/packages
  2) Files for reverse bindings are generated
  3) Package information is retrieved by go/imports

After this change, only 3) will be changed:

  3) Package information is retrieved by go/packages again only when
     reverse binding is used.

This is preparation to support Go modules.

Updates golang/go#27234

Change-Id: I1997f71f23455fdd3b3c6b2643d35ec33ad147a3
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/203399
Run-TryBot: Hajime Hoshi <hajimehoshi@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Nov 3, 2019

Change https://golang.org/cl/195937 mentions this issue: cmd/gobind: add tests enabling Go modules

@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Nov 12, 2019

Change https://golang.org/cl/206737 mentions this issue: cmd/gobind: enable TestDocs tested with Go modules

@hajimehoshi

This comment has been minimized.

Copy link
Contributor

@hajimehoshi hajimehoshi commented Nov 12, 2019

As gobind should work with Go modules, now I'm working on gomobile bind.

gobind generates files at a temporary directory like [temp-dir]/src/gobind. The temp-dir is given by gomobile. To access this temporary package from Go modules, I think we need to do these items:

  • Replace go/build with go/packages as usual.
  • Create another temporary directory to emulate a Go proxy. This needs to zip the files and add go.mod files. See also packagestest implementation.
  • Give a temporary and unique module name like example.com/[random-token] to the temporary module.
  • Overwrite GOPROXY like $(go env GOPROXY),file:///[new-temporary-directory]
  • Use the temporary module name at gomobile when go building.

All are done in gomobile and gobind should not be modified from its current behavior.

@hyangah, @eliasnaur Any thoughts?

@eliasnaur

This comment has been minimized.

Copy link
Contributor

@eliasnaur eliasnaur commented Nov 12, 2019

As gobind should work with Go modules, now I'm working on gomobile bind.

gobind generates files at a temporary directory like [temp-dir]/src/gobind. The temp-dir is given by gomobile. To access this temporary package from Go modules, I think we need to do these items:

* Replace `go/build` with `go/packages` as usual.

* Create another temporary directory to emulate a Go proxy. This needs to zip the files and add `go.mod` files. See also [`packagestest` implementation](https://github.com/golang/tools/blob/master/go/packages/packagestest/modules.go#L54-L130).

Emulating a Go proxy with zip files, nice.

* Give a temporary and unique module name like `example.com/[random-token]` to the temporary module.

* Overwrite `GOPROXY` like `$(go env GOPROXY),file:///[new-temporary-directory]`

It probably doesn't matter given the random token, but perhaps swap the order so the temporary directory is first, to match the intention of gomobile bind?

* Use the temporary module name at `gomobile` when `go build`ing.

All are done in gomobile and gobind should not be modified from its current behavior.

@hyangah, @eliasnaur Any thoughts?

Sounds like a good plan to me.

@hajimehoshi

This comment has been minimized.

Copy link
Contributor

@hajimehoshi hajimehoshi commented Nov 12, 2019

Thank you!

It probably doesn't matter given the random token, but perhaps swap the order so the temporary directory is first, to match the intention of gomobile bind?

Yes. The second item and the third item will be done at the same time, so we'd need to create a temporary directory first.

@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Nov 12, 2019

Change https://golang.org/cl/206777 mentions this issue: cmd/gomobile: replace go/build with go/packages in bind

gopherbot pushed a commit to golang/mobile that referenced this issue Nov 12, 2019
This CL adds tests with Go modules enabled.

Updates golang/go#27234.

Change-Id: I8a583c929ed9151e3b3220b4e669ff572361bb0e
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/195937
Run-TryBot: Hajime Hoshi <hajimehoshi@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
You can’t perform that action at this time.