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

Closed
axet opened this issue Feb 5, 2020 · 11 comments
Closed

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

axet opened this issue Feb 5, 2020 · 11 comments

Comments

@axet
Copy link

@axet axet commented Feb 5, 2020

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

go version go1.13.7 linux/amd64

Does this issue reproduce with the latest release?

yes

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

go env Output
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/axet/.cache/go-build"
GOENV="/home/axet/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/axet/.go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/snap/go/5243"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/snap/go/5243/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/axet/local/libtorrent/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-build037966773=/tmp/go-build -gno-record-gcc-switches"

What did you do?

gomobile failed with "replacement module directory path ... cannot have version"

Probably because gomobile does not support 'go.mod replace command'. Full log:

# git clone -b dev https://gitlab.com/axet/libtorrent
# gomobile bind
gomobile: go build -buildmode=c-shared -o=/tmp/gomobile-work-296787665/android/src/main/jniLibs/armeabi-v7a/libgojni.so ./gobind failed: exit status 1
go: errors parsing go.mod:
/tmp/gomobile-work-296787665/src/go.mod:181: replacement module directory path "/home/axet/.go/pkg/mod/gitlab.com/axet/torrent@v0.0.0-20200205141541-92b4b9e7387e" cannot have version

It also failed with "proper" version like "v0.14.0" or "libtorrent-0.14.0"

@odeke-em odeke-em changed the title [golang/go] x/mobile: build failing when using go modules x/mobile: build failing when using go modules Feb 5, 2020
@gopherbot gopherbot added this to the Unreleased milestone Feb 5, 2020
@gopherbot gopherbot added the mobile label Feb 5, 2020
@odeke-em
Copy link
Member

@odeke-em odeke-em commented Feb 5, 2020

Thank you for the report @axet!

Kindly cc-ing @bcmills @jayconrod.

@bcmills
Copy link
Member

@bcmills bcmills commented Feb 5, 2020

What version of the gomobile command are you using? (This seems like a duplicate of #27234.)

@axet
Copy link
Author

@axet axet commented Feb 5, 2020

Recent:

axet@axet-laptop:~$ gomobile version
gomobile version +0df4eb2 Wed Feb 5 17:02:28 2020 +0000 (android); androidSDK=/home/axet/Android/Sdk/platforms/android-29

@axet
Copy link
Author

@axet axet commented Feb 5, 2020

I probably know what is going on, If I init gomobile staying inside my library with "go.mod" directory it will fail. Doesn't matter where gomobile is located, only $PWD is matter.

export GOPATH=$HOME/.go
export PATH=$HOME/.go/bin:$PATH
export ANDROID_NDK_HOME=$ANDROID_HOME/ndk/19.2.5345600/

PWD=$HOME/local/libtorrent

go get golang.org/x/mobile/cmd/gomobile
gomobile init
ls go.mod

And now it bugged. Maybe it is not a bug, but error message a bit confusing.

@jayconrod
Copy link
Contributor

@jayconrod jayconrod commented Feb 5, 2020

@hyangah
Copy link
Contributor

@hyangah hyangah commented Feb 5, 2020

gomobile generates go.mod file based on the go list output influenced by the original go.mod. (https://github.com/golang/mobile/blob/0df4eb2385467a487d418c6358313e9e838256ae/cmd/gomobile/bind.go#L230)

It looks like the original file has

replace github.com/anacrolix/torrent v1.13.0 => gitlab.com/axet/torrent v0.0.0-20200205141541-92b4b9e7387e

and gomobile bind converted it to

replace github.com/anacrolix/torrent v1.13.0 => /usr/local/google/home/hakim/go/pkg/mod/gitlab.com/axet/torrent@v0.0.0-20200205141541-92b4b9e7387e v0.0.0-20200205141541-92b4b9e7387e

cc @hajimehoshi

@gopherbot
Copy link

@gopherbot gopherbot commented Feb 5, 2020

Change https://golang.org/cl/218057 mentions this issue: cmd/gomobile: handle modules replaced by other versioned modules

@jayconrod
Copy link
Contributor

@jayconrod jayconrod commented Feb 6, 2020

One thing to watch out for: it's not generally safe to use module directories in the module cache as replacements. Replacement modules must have a go.mod file, and a directory in the cache won't have a go.mod file if the original module didn't.

@axet
Copy link
Author

@axet axet commented Feb 12, 2020

It is closed, but still failed to compile. Same library I build using old style GOPATH no problems, go.mod build failed with two errors, first run:

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.

Should I create separate issue?

@dmitshur
Copy link
Member

@dmitshur dmitshur commented Feb 22, 2020

@axet Please do. You can refer to this issue if any of the information here is relevant. Thanks.

@gopherbot
Copy link

@gopherbot gopherbot commented Mar 29, 2020

Change https://golang.org/cl/226279 mentions this issue: cmd/gomobile: keep the module version information as much as possible

gopherbot pushed a commit to golang/mobile that referenced this issue Mar 29, 2020
Before this change, the main module specifies the module version of the
package to bind, the version might not be adopted by gomobile because
gomobile trims some dependencies information. If a dependency is not
a main module nor a replaced module, the dependency information is
omitted.

For example, if you have this go.mod in a workspace:

    module example.com/m

    requier (
        github.com/foo/bar v0.1.0-123456
    )

and then run `gomobile bind github.com/foo/bar` there, the specified
version might not be used because github.com/foo/bar is not a main nor
a replaced module.

This change keeps the dependency information as much as possible
to avoid this confusion.

Updates golang/go#37048

Change-Id: I875a1b9485438bdee336f3fc2d131775353004f5
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/226279
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
roderm added a commit to roderm/mobile that referenced this issue Sep 13, 2020
Previously, gomobile bind's go.mod generation logic assumed
replacing module was always located in the disk, but is not
always true. It's valid to replace a module(version) with
another module&version.

For example,

replace golang.org/x/tools => ../

causes:

{
        "Path": "golang.org/x/tools",
        "Version": "v0.0.0-20191017151554-a3bc800455d5",
        "Replace": {
                "Path": "../",
                "Dir": "/usr/local/google/home/hakim/go/src/golang.org/x/tools",
                "GoMod": "/usr/local/google/home/hakim/go/src/golang.org/x/tools/go.mod",
                "GoVersion": "1.11"
        },
        "Dir": "/usr/local/google/home/hakim/go/src/golang.org/x/tools",
        "GoMod": "/usr/local/google/home/hakim/go/src/golang.org/x/tools/go.mod",
        "GoVersion": "1.11"
}

replace github.com/anacrolix/torrent v1.13.0 => gitlab.com/axet/torrent v0.0.0-20200205141541-92b4b9e7387e

causes:

{
        "Path": "github.com/anacrolix/torrent",
        "Version": "v1.13.0",
        "Replace": {
                "Path": "gitlab.com/axet/torrent",
                "Version": "v0.0.0-20200205141541-92b4b9e7387e",
                "Time": "2020-02-05T14:15:41Z",
                "Dir": "/usr/local/google/home/hakim/go/pkg/mod/gitlab.com/axet/torrent@v0.0.0-20200205141541-92b4b9e7387e",
                "GoMod": "/usr/local/google/home/hakim/go/pkg/mod/cache/download/gitlab.com/axet/torrent/@v/v0.0.0-20200205141541-92b4b9e7387e.mod"
        },
        "Dir": "/usr/local/google/home/hakim/go/pkg/mod/gitlab.com/axet/torrent@v0.0.0-20200205141541-92b4b9e7387e",
        "GoMod": "/usr/local/google/home/hakim/go/pkg/mod/cache/download/gitlab.com/axet/torrent/@v/v0.0.0-20200205141541-92b4b9e7387e.mod"
}

Also, while we are here, trim down the entries added to the generated
go.mod. We need the main module, and the replaced module info.
We may want to pin golang.org/x/mobile version if possible, but I don't
know a reliable way to achieve that yet.

Fixes golang/go#37048

Change-Id: Ibd7332338c0a3c4165a642c3e86852061f6ab13b
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/218057
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Hajime Hoshi <hajimehoshi@gmail.com>
roderm added a commit to roderm/mobile that referenced this issue Sep 13, 2020
Before this change, the main module specifies the module version of the
package to bind, the version might not be adopted by gomobile because
gomobile trims some dependencies information. If a dependency is not
a main module nor a replaced module, the dependency information is
omitted.

For example, if you have this go.mod in a workspace:

    module example.com/m

    requier (
        github.com/foo/bar v0.1.0-123456
    )

and then run `gomobile bind github.com/foo/bar` there, the specified
version might not be used because github.com/foo/bar is not a main nor
a replaced module.

This change keeps the dependency information as much as possible
to avoid this confusion.

Updates golang/go#37048

Change-Id: I875a1b9485438bdee336f3fc2d131775353004f5
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/226279
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
Linked pull requests

Successfully merging a pull request may close this issue.

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