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 tags not being passed along properly #18515

adam-p opened this issue Jan 4, 2017 · 1 comment

x/mobile: Build tags not being passed along properly #18515

adam-p opened this issue Jan 4, 2017 · 1 comment


Copy link

@adam-p adam-p commented Jan 4, 2017

gomobile build and bind are not passing along -tags properly.

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


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


What did you do?

Modify the "basic" example (example/basic/main.go) like so:

- // +build darwin linux windows
+ // +build aaa,bbb

This will require the tags aaa and bbb to be passed in order for it to build. Confirm that it initially doesn't build like so:

$ gomobile build -v -x
...resulting in something like...
gomobile: no buildable Go source files in GOPATH/src/

As expected.

Now supply the required tags. It still fails, and you can see how the tags are getting mangled.

$ gomobile build -v -x -tags "aaa bbb"
...resulting in something like...
can't load package: package no buildable Go source files in GOPATH/src/
gomobile: go build -pkgdir=GOPATH/pkg/gomobile/pkg_android_arm64 -tags="aaa,bbb" -v -x -buildmode=c-shared -o /var/folders/xh/mp5b069545n32zn6ds3dbn100000gn/T/gomobile-work-217015845/lib/arm64-v8a/ failed: exit status 1

Note the -tags="aaa,bbb".

Here's the fix diff:

diff --git a/cmd/gomobile/build.go b/cmd/gomobile/build.go
index 3ed4576..e4c4db6 100644
--- a/cmd/gomobile/build.go
+++ b/cmd/gomobile/build.go
@@ -15,7 +15,6 @@ import (
-       "strconv"

@@ -270,7 +269,7 @@ func goCmd(subcmd string, srcs []string, env []string, args ...string) error {
-               "-tags="+strconv.Quote(strings.Join(ctx.BuildTags, ",")),
+               "-tags",strings.Join(ctx.BuildTags, " "),
        if buildV {
                cmd.Args = append(cmd.Args, "-v")

So, the tags should be passed as a separate argument to exec.Command, space-separated. The =, the quoting, and the comma-joining all need to go.

After applying that patch, the code builds as expected.


We discovered this the hard way and had to hack around it by patching gomobile before building it. This can be seen here. (I'll be filing another bug for the hack below it.)

Copy link

@gopherbot gopherbot commented Jan 8, 2017

CL mentions this issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

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