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 #37372

Open
axet opened this issue Feb 22, 2020 · 8 comments
Open

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

axet opened this issue Feb 22, 2020 · 8 comments

Comments

@axet
Copy link

@axet axet commented Feb 22, 2020

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

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

Does this issue reproduce with the latest release?

yes

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

go env Output
x/mobile: build failing when using go modules #37048

What did you do?

gomobile failed with 'nrecognized command line option '-marm'' and second run on same code gives different output ' cannot determine module path for source directory' this issue related to previous one #37048

gcc: error: unrecognized command line option '-marm'; did you mean '-mabm'?

second run (same command: gomobile bind)

gomobile: go build -buildmode=c-shared -o=/tmp/gomobile-work-515390264/android/src/main/jniLibs/armeabi/libgojni.so ./gobind failed: exit status 1
go: cannot determine module path for source directory /tmp/gomobile-work-515390264/src (outside GOPATH, module path must be specified)

Example usage:
	'go mod init example.com/m' to initialize a v0 or v1 module
	'go mod init example.com/m/v2' to initialize a v2 module

Run 'go help mod init' for more information.

commands:

# git clone -b dev https://gitlab.com/axet/libtorrent
# gomobile bind
@gopherbot gopherbot added this to the Unreleased milestone Feb 22, 2020
@gopherbot gopherbot added the mobile label Feb 22, 2020
@hyangah

This comment has been minimized.

Copy link
Contributor

@hyangah hyangah commented Feb 22, 2020

@axet I am guessing some cgo related setup is not correct. it's strange that gomobile didn't complain or report the error and it's definitely a bug. Can you please try to run it with -x -v -work flags to see what's going on? If -work flag is supplied, the gomobile bind will not delete the temporary work directories for inspection. Check what's in the directory reported in the error message. There should be go.mod file and the error message indicates that it's not.

@axet

This comment has been minimized.

Copy link
Author

@axet axet commented Feb 22, 2020

I did clean everyging and now only first issue is present. It failed to build on first run, second run succeed. And I have no issues to build a library old GOPATH style (no cgo issues). Steps:

  git clone -b dev https://gitlab.com/axet/libtorrent
  cd libtorrent
  export GOPATH=$PWD/build
  export GOBIN=$GOPATH/bin/
  export PATH=$GOBIN:$PATH
  export ANDROID_HOME=$HOME/Android/Sdk
  export ANDROID_NDK_HOME=$ANDROID_HOME/ndk/19.2.5345600/
  go get golang.org/x/mobile/cmd/gomobile
  gomobile init
  gomobile bind
gcc: error: unrecognized command line option '-marm'; did you mean '-mabm'?
  gomobile bind

ok

@hyangah

This comment has been minimized.

Copy link
Contributor

@hyangah hyangah commented Feb 22, 2020

Thanks for the update.

Would be nice if u can provide the output in module mode i asked in my previous comment. It will be helpful for us to prepare for complete migration to modules mode near future.

@hyangah

This comment has been minimized.

Copy link
Contributor

@hyangah hyangah commented Feb 22, 2020

@axet

This comment has been minimized.

Copy link
Author

@axet axet commented Feb 22, 2020

Sure. Second issue was related to NDK r16. I know it is not supported, but I able to build using NDK r16 using GOPATH, but failed with go mod's with error above. NDK r19 works fine booth ways. Answering your question, here is output of gomobile bind -tags disable_libutp -x -v -work > output.log 2>&1.

output.log

@hyangah

This comment has been minimized.

Copy link
Contributor

@hyangah hyangah commented Feb 24, 2020

@axet thanks!

@matloob @bcmills @jayconrod It is hard to debug due to caching by go command. I observed inconsistency of gomobile bind runs possibly due to different build/package/module cache states.

Attached are the logs I captured by running gomobile bind twice back to back.

$ GOPACKAGESDRIVER=off GOPACKAGESDEBUG=true gomobile bind -tags disable_libutp -x -v -work > output1.log 2>&1
$ GOPACKAGESDRIVER=off GOPACKAGESDEBUG=true gomobile bind -tags disable_libutp -x -v -work > output2.log 2>&1

The first run failed with some cgo errors (clang: error: argument unused during compilation: '-mno-thumb' [-Werror,-Wunused-command-line-argument] ) during go list triggered by x/tools/go/packages. (output1.log)

Observed that some modules were downloaded and $GOPATH/pkg directory and GOCACHE became non-empty as a result of go command run.

The second run shows the same cgo error, but go list went further this time despite the error and succeeded with some results. And finally, the gomobile bind completed its job (output2
output1.log
output2.log

Is this unstable behavior a known bug of go list (and x/tools/go/packages)?
Is there any way to make the very first run of go list tolerate the error and go further?

my environment:

$ go version
go version devel +a50c3ffbd4 linux/amd64

# (This is 1.14rcX)


$ for x in GOPATH GOBIN ANDROID_HOME ANDROID_NDK_HOME; do printenv "${x}"; done
/tmp/build
/tmp/build/bin
/usr/local/google/home/hakim/Android/Sdk
/usr/local/google/home/hakim/Android/Sdk/ndk/19.2.5345600

@jayconrod

This comment has been minimized.

Copy link
Contributor

@jayconrod jayconrod commented Feb 24, 2020

It's weird that the cgo errors happen on one run but disappear later. They ought to either always be reported or never reported.

I don't know enough about how gomobile uses golang.org/x/tools/go/packages to comment much further than that. Does this reproduce using go list directly? How about the golang.org/x/tools/go/packages/gopackages tool?

Also, where does the -mno-thumb flag come from? I don't think anything in cmd/go or golang.org/x/tools/go/packages adds that. The output of go env would be useful (in the environment that go list is invoked with).

@hyangah

This comment has been minimized.

Copy link
Contributor

@hyangah hyangah commented Feb 24, 2020

@jayconrod
Actually the second run reported the cgo error but that didn't fail the go list.

113.046944ms for GOROOT= GOPATH=/tmp/build GO111MODULE= PWD=/usr/local/google/home/hakim/project/scratch/libtorrent go "list" "-tags=disable_libutp" "-e" "-json" "-compiled=true" "-test=false" "-export=false" "-deps=false" "-find=true" "-tags=disable_libutp" "--" ".", stderr: <<# runtime/cgo
clang: error: argument unused during compilation: '-mno-thumb' [-Werror,-Wunused-command-line-argument]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.