Skip to content

x/mobile: gomobile bind triggers a CC compilation with the wrong compiler #49502

Closed
@bmteller

Description

@bmteller

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

go version go1.16.2 linux/amd64

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

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.16.2"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/workspace/mobile/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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2276006800=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Ran gomobile bind -target android -androidapi 30 -javapkg io.teller github.com/tellerhq/quic-droid-edge/mobile/pkg/droid

What did you expect to see?

Success

What did you see instead?

gomobile: err: exit status 2: stderr: go: downloading github.com/segmentio/ksuid v1.0.3
go: downloading go.uber.org/zap v1.16.0
go: downloading google.golang.org/protobuf v1.27.1
go: downloading github.com/lucas-clemente/quic-go v0.22.1
go: downloading go.uber.org/multierr v1.5.0
go: downloading go.uber.org/atomic v1.6.0
go: downloading github.com/cheekybits/genny v1.0.0
go: downloading golang.org/x/net v0.0.0-20210428140749-89ef3d95e781
go: downloading golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
go: downloading github.com/marten-seemann/qtls-go1-16 v0.1.4
# runtime/cgo
gcc: error: unrecognized command line option '-marm'; did you mean '-mabm'?

If I explicitly set a target architecture using gomobile bind -target android/arm64 -androidapi 30 -javapkg io.teller github.com/tellerhq/quic-droid-edge/mobile/pkg/droid then I get a slightly different error.

gomobile: err: exit status 2: stderr: go: downloading github.com/segmentio/ksuid v1.0.3
go: downloading go.uber.org/zap v1.16.0
go: downloading github.com/lucas-clemente/quic-go v0.22.1
go: downloading google.golang.org/protobuf v1.27.1
go: downloading go.uber.org/multierr v1.5.0
go: downloading go.uber.org/atomic v1.6.0
go: downloading github.com/cheekybits/genny v1.0.0
go: downloading golang.org/x/net v0.0.0-20210428140749-89ef3d95e781
go: downloading golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
go: downloading github.com/marten-seemann/qtls-go1-16 v0.1.4
# runtime/cgo
gcc_android.c:6:10: fatal error: android/log.h: No such file or directory
 #include <android/log.h>
          ^~~~~~~~~~~~~~~
compilation terminated.

If I run the command a second time then it succeeds. However, if delete the contents of $GOPATH/pkg/mod/ and reinstall gomobile and run gomobile bind again I get the same failure.

if I run GOOS=android GOARCH=arm64 CC=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android30-clang CXX=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android30-clang++ CGO_ENABLED=1 go list -compiled=true -json github.com/tellerhq/quic-droid-edge/mobile/pkg/droid before running gomobile bind then the error is not triggered.

The error seems to be related to:

https://github.com/golang/mobile/blob/master/cmd/gomobile/bind.go#L113

pkgs, err := packages.Load(packagesConfig(targets[0]), args...)

this triggers some kind of CC compilation but the CC env variable is not set correctly at this point in time so it is unable to find android/log.h or it gets these architecture errors because the CC compiler on my box does not understand -marm but the android toolchain one does.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.mobileAndroid, iOS, and x/mobile

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions