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

go 1.13 compat #2133

Closed
steeve opened this issue Jul 11, 2019 · 8 comments · Fixed by #2135
Closed

go 1.13 compat #2133

steeve opened this issue Jul 11, 2019 · 8 comments · Fixed by #2135
Labels

Comments

@steeve
Copy link
Contributor

steeve commented Jul 11, 2019

What version of rules_go are you using?

master as of today

What version of gazelle are you using?

master as of today

What version of Bazel are you using?

0.25.3

What operating system and processor architecture are you using?

darwin_amd64

What did you do?

When using Go 1.13b1:

$ bazel build @bazel_gazelle//language/go/gen_std_package_list

What did you see instead?

bazel build @bazel_gazelle//language/go/gen_std_package_list --verbose_failures
DEBUG: Rule 'io_bazel_rules_go' indicated that a canonical reproducible form can be obtained by modifying arguments shallow_since = "1562800394 -0400"
DEBUG: Rule 'bazel_gazelle' indicated that a canonical reproducible form can be obtained by modifying arguments shallow_since = "1562699102 -0400"
INFO: Analyzed target @bazel_gazelle//language/go/gen_std_package_list:gen_std_package_list (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
ERROR: /private/var/tmp/_bazel_steeve/309ac22c92b055a3e3f78825fe63406b/external/bazel_gazelle/language/go/gen_std_package_list/BUILD.bazel:3:1: GoLink external/bazel_gazelle/language/go/gen_std_package_list/darwin_amd64_debug/gen_std_package_list failed (Exit 1) builder failed: error executing command
  (cd /private/var/tmp/_bazel_steeve/309ac22c92b055a3e3f78825fe63406b/sandbox/darwin-sandbox/1/execroot/co_znly_client_core && \
  exec env - \
    APPLE_SDK_PLATFORM=MacOSX \
    APPLE_SDK_VERSION_OVERRIDE=10.14 \
    CGO_ENABLED=1 \
    GOARCH=amd64 \
    GOOS=darwin \
    GOROOT=external/go_sdk \
    GOROOT_FINAL=GOROOT \
    PATH=external/local_config_cc:/bin:/usr/bin \
    XCODE_VERSION_OVERRIDE=10.2.1.10E1001 \
  bazel-out/host/bin/external/go_sdk/builder link -sdk external/go_sdk -installsuffix darwin_amd64 -tags core_build_snapshot -package_list bazel-out/host/bin/external/go_sdk/packages.txt -o bazel-out/darwin-dbg/bin/external/bazel_gazelle/language/go/gen_std_package_list/darwin_amd64_debug/gen_std_package_list -main bazel-out/darwin-dbg/bin/external/bazel_gazelle/language/go/gen_std_package_list/darwin_amd64_debug/gen_std_package_list%/github.com/bazelbuild/bazel-gazelle/language/go/gen_std_package_list.a -p github.com/bazelbuild/bazel-gazelle/language/go/gen_std_package_list -- -extld external/local_config_cc/cc_wrapper.sh '-buildid=redacted' -extldflags '-fobjc-link-runtime -headerpad_max_install_names -no-canonical-prefixes -mmacosx-version-min=10.14')
Execution platform: @bazel_tools//platforms:host_platform

Use --sandbox_debug to see verbose messages from the sandbox: builder failed: error executing command
  (cd /private/var/tmp/_bazel_steeve/309ac22c92b055a3e3f78825fe63406b/sandbox/darwin-sandbox/1/execroot/co_znly_client_core && \
  exec env - \
    APPLE_SDK_PLATFORM=MacOSX \
    APPLE_SDK_VERSION_OVERRIDE=10.14 \
    CGO_ENABLED=1 \
    GOARCH=amd64 \
    GOOS=darwin \
    GOROOT=external/go_sdk \
    GOROOT_FINAL=GOROOT \
    PATH=external/local_config_cc:/bin:/usr/bin \
    XCODE_VERSION_OVERRIDE=10.2.1.10E1001 \
  bazel-out/host/bin/external/go_sdk/builder link -sdk external/go_sdk -installsuffix darwin_amd64 -tags core_build_snapshot -package_list bazel-out/host/bin/external/go_sdk/packages.txt -o bazel-out/darwin-dbg/bin/external/bazel_gazelle/language/go/gen_std_package_list/darwin_amd64_debug/gen_std_package_list -main bazel-out/darwin-dbg/bin/external/bazel_gazelle/language/go/gen_std_package_list/darwin_amd64_debug/gen_std_package_list%/github.com/bazelbuild/bazel-gazelle/language/go/gen_std_package_list.a -p github.com/bazelbuild/bazel-gazelle/language/go/gen_std_package_list -- -extld external/local_config_cc/cc_wrapper.sh '-buildid=redacted' -extldflags '-fobjc-link-runtime -headerpad_max_install_names -no-canonical-prefixes -mmacosx-version-min=10.14')
Execution platform: @bazel_tools//platforms:host_platform

Use --sandbox_debug to see verbose messages from the sandbox
runtime.main_main·f: function main is undeclared in the main package
link: error running subcommand: exit status 2
Target @bazel_gazelle//language/go/gen_std_package_list:gen_std_package_list failed to build
INFO: Elapsed time: 0.415s, Critical Path: 0.27s
INFO: 0 processes.
FAILED: Build did NOT complete successfully
@steeve
Copy link
Contributor Author

steeve commented Jul 11, 2019

If I do:

$ go tool nm bazel-out/host/bin/external/bazel_gazelle/language/go/gen_std_package_list/darwin_amd64_stripped/gen_std_package_list%/github.com/bazelbuild/bazel-gazelle/language/go/gen_std_package_list.a | grep main
    1b29 T github.com/bazelbuild/bazel-gazelle/language/go/gen_std_package_list.main
    4373 R github.com/bazelbuild/bazel-gazelle/language/go/gen_std_package_list.main.stkobj
    35c6 ? go.info.github.com/bazelbuild/bazel-gazelle/language/go/gen_std_package_list.main
    3ab5 ? go.isstmt.github.com/bazelbuild/bazel-gazelle/language/go/gen_std_package_list.main
    29b6 ? go.loc.github.com/bazelbuild/bazel-gazelle/language/go/gen_std_package_list.main
    3835 ? go.range.github.com/bazelbuild/bazel-gazelle/language/go/gen_std_package_list.main

Perhaps it's linked to the -main arg ?

@steeve
Copy link
Contributor Author

steeve commented Jul 11, 2019

I can repro with stock go:

$ cat main.go
package main

func main() {
	println("1")
}
$ go1.13beta1 tool compile -p mytest.com/pkg -pack main.go
$ go1.13beta1 tool link main.a
runtime.main_main·f: function main is undeclared in the main package
$ go tool nm main.a
         U
     409 R gclocals·33cdeccccebe80329f1fdbee7f5874cb
     411 R gclocals·9fb7f0986f647f17cb53dda1484e0f7a
     3be ? go.cuinfo.packagename.mytest.com/pkg
     3c5 ? go.info.mytest.com/pkg.main
     3e6 ? go.isstmt.mytest.com/pkg.main
     3c5 ? go.loc.mytest.com/pkg.main
     3e6 ? go.range.mytest.com/pkg.main
     3c2 R go.string."1"
     3c3 R go.string."1\n"
         U gofile../Users/steeve/go/src/github.com/steeve/test/main.go
     3f1 ? mytest.com/pkg..inittask
     345 T mytest.com/pkg.main <-------------------------------------------------------
         U runtime.morestack_noctxt
         U runtime.printlock
         U runtime.printstring
         U runtime.printunlock

Removing -p makes it work:

$ go1.13beta1 tool compile -pack main.go
$ go1.13beta1 tool link main.a
$ go tool nm main.a
         U
     39b ? %22%22..inittask
     2ef T %22%22.main <-------------------------------------------------------
     3b3 R gclocals·33cdeccccebe80329f1fdbee7f5874cb
     3bb R gclocals·9fb7f0986f647f17cb53dda1484e0f7a
     368 ? go.cuinfo.packagename.
     36f ? go.info.%22%22.main
     390 ? go.isstmt.%22%22.main
     36f ? go.loc.%22%22.main
     390 ? go.range.%22%22.main
     36c R go.string."1"
     36d R go.string."1\n"
         U gofile../Users/steeve/go/src/github.com/steeve/test/main.go
         U runtime.morestack_noctxt
         U runtime.printlock
         U runtime.printstring
         U runtime.printunlock

@steeve
Copy link
Contributor Author

steeve commented Jul 11, 2019

Adding packagefile main=main.a to the importcfg doesn't cut it

@steeve
Copy link
Contributor Author

steeve commented Jul 11, 2019

On go 1.12:

$ go tool nm main.a
         U
     3b6 T %22%22.init
     493 B %22%22.initdone·
     33d T %22%22.main
     493 R gclocals·33cdeccccebe80329f1fdbee7f5874cb
     49b R gclocals·9fb7f0986f647f17cb53dda1484e0f7a
     45f ? go.info.%22%22.init
     433 ? go.info.%22%22.main
     480 ? go.isstmt.%22%22.init
     454 ? go.isstmt.%22%22.main
     45f ? go.loc.%22%22.init
     433 ? go.loc.%22%22.main
     480 ? go.range.%22%22.init
     454 ? go.range.%22%22.main
     430 R go.string."1"
     431 R go.string."1\n"
         U gofile../Users/steeve/go/src/github.com/znly/gna/main.go
         U gofile..<autogenerated>
         U runtime.morestack_noctxt
         U runtime.printlock
         U runtime.printstring
         U runtime.printunlock
         U runtime.throwinit

@jayconrod
Copy link
Contributor

Thanks for analyzing this. This looks like a bug in rules_go. I'll fix it before go1.13 is officially released, but probably not before rules_go 0.19.0 is released.

@steeve
Copy link
Contributor Author

steeve commented Jul 11, 2019

Thank you !

@steeve
Copy link
Contributor Author

steeve commented Jul 11, 2019

@jayconrod how would you go about fixing it? have gazelle generate importpath = "main" ?

@jayconrod
Copy link
Contributor

I won't be able to look at it today, but I think go_binary and go_test will indicate somehow when calling go.archive that it's a main package. That will override -p. No user-facing change should be needed.

jayconrod pushed a commit that referenced this issue Jul 13, 2019
Go 1.13 is stricter on the package path passed to go tool compile -p.
This means that go_library passed in go_binary.embed fails to declare a
main.main function, as they now retain their original import path. Fix
that by adding a is_main boolean to the GoLibrary provider, which will
tell wether a library is supposed to be a main package; that is,
compiled from within a go_binary.

Fixes #2133
jayconrod pushed a commit to jayconrod/rules_go that referenced this issue Aug 23, 2019
)

Go 1.13 is stricter on the package path passed to go tool compile -p.
This means that go_library passed in go_binary.embed fails to declare a
main.main function, as they now retain their original import path. Fix
that by adding a is_main boolean to the GoLibrary provider, which will
tell wether a library is supposed to be a main package; that is,
compiled from within a go_binary.

Fixes bazel-contrib#2133
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants