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 · 11 comments
Open

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

axet opened this issue Feb 22, 2020 · 11 comments
Labels
mobile Android, iOS, and x/mobile NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@axet
Copy link

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 Android, iOS, and x/mobile label Feb 22, 2020
@hyangah
Copy link
Contributor

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
Copy link
Author

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
Copy link
Contributor

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
Copy link
Contributor

hyangah commented Feb 22, 2020

@hajimehoshi

@axet
Copy link
Author

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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]

@cagedmantis cagedmantis added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Feb 26, 2020
@fgm
Copy link

fgm commented May 26, 2020

FWIW, I used to get the same error as @hyangah but after upgrading Android Studio and reinstalling the NDK with sdkmanager ndk-bundle, I got NDK r21b and now it builds without the error.

@richard-ramos
Copy link

Using go1.18.2, and android-ndk-r23c in Ubuntu 20.04, with gcc-10 and openjdk-8, I get the same error. I need to run this command twice to build my project:

gomobile init && \
gomobile bind -v -target=android -ldflags="-s -w" $(BUILD_FLAGS) -o ./build/lib/gowaku.aar ./mobile

with the first run failing due to gcc-10: error: unrecognized command line option '-marm'; did you mean '-mabm'?

@bcmills
Copy link
Contributor

bcmills commented Jun 22, 2022

(CC @golang/android @golang/ios)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mobile Android, iOS, and x/mobile NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

8 participants