Open axet opened 4 years ago
@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.
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
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.
@hajimehoshi
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
.
@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
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).
@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]
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.
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'?
(CC @golang/android @golang/ios)
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat 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
second run (same command: gomobile bind)
commands: