rules_go breaks with incompatible_require_linker_input_cc_api

Created on 16 Nov 2020  路  11Comments  路  Source: bazelbuild/rules_go

(See https://github.com/kythe/kythe/issues/4760)

What version of rules_go are you using?

v0.24.7

What version of gazelle are you using?

v0.22.2

What version of Bazel are you using?

3.7.0

Does this issue reproduce with the latest releases of all the above?

yes

What did you do?

bazel test --incompatible_require_linker_input_cc_api //kythe/...

What did you expect to see?

A successful build.

What did you see instead?

ERROR: /usr/local/google/home/shahms/.cache/bazel/_bazel_shahms/f0c8a49cbf1bfaa82de86be744427f4b/external/com_github_jmhodges_levigo/BUILD.bazel:9:11: in go_library rule @com_github_jmhodges_levigo//:levigo:
Traceback (most recent call last):
        File "/usr/local/google/home/shahms/.cache/bazel/_bazel_shahms/f0c8a49cbf1bfaa82de86be744427f4b/external/io_bazel_rules_go/go/private/rules/library.bzl", line 38, column 25, in _go_library_impl
                archive = go.archive(go, source)
        File "/usr/local/google/home/shahms/.cache/bazel/_bazel_shahms/f0c8a49cbf1bfaa82de86be744427f4b/external/io_bazel_rules_go/go/private/actions/archive.bzl", line 82, column 28, in emit_archive
                cgo = cgo_configure(
        File "/usr/local/google/home/shahms/.cache/bazel/_bazel_shahms/f0c8a49cbf1bfaa82de86be744427f4b/external/io_bazel_rules_go/go/private/rules/cgo.bzl", line 112, column 31, in cgo_configure
                cc_libs = _cc_libs(d)
        File "/usr/local/google/home/shahms/.cache/bazel/_bazel_shahms/f0c8a49cbf1bfaa82de86be744427f4b/external/io_bazel_rules_go/go/private/rules/cgo.bzl", line 191, column 67, in _cc_libs
                libraries_to_link = as_iterable(target[CcInfo].linking_context.libraries_to_link)
Error: 'LinkingContext' value has no field or method 'libraries_to_link'
bug cgo

Most helpful comment

@mrmeku This seems to be working on master and on the 0.25 branch. The fix cannot be backported to the 0.24 branch because the minimum supported version of Bazel (2.2.0) did not support this API.

All 11 comments

Strangely, rules_go is green in Bazel downstream. Do we lack test coverage for this?
https://buildkite.com/bazel/bazel-at-head-plus-downstream/builds/1767

We see these failures for two very straightforward cgo-using targets:
@com_github_jmhodges_levigo//:levigo

load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

go_library(
    name = "levigo",
    srcs = [
        "batch.go",
        "cache.go",
        "comparator.go",
        "conv.go",
        "db.go",
        "doc.go",
        "env.go",
        "filterpolicy.go",
        "iterator.go",
        "options.go",
        "version.go",
    ],
    cdeps = ["@com_github_google_leveldb//:leveldb"],
    cgo = True,
    importpath = "github.com/jmhodges/levigo",
    visibility = ["//visibility:public"],
)

@com_github_google_brotli_go_cbrotli//:cbrotli

load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

go_library(
    name = "cbrotli",
    srcs = [
        "reader.go",
        "writer.go",
    ],
    cdeps = [
        "@org_brotli//:brotlidec",
        "@org_brotli//:brotlienc",
    ],
    cgo = True,
    importpath = "github.com/google/brotli/go/cbrotli",
)

The cc_library targets on which they depend are similarly straightforward. Poking at the rules_go tests a bit, it seems like this case should be covered.

Looks like https://github.com/bazelbuild/rules_go/commit/3f47128dd00917a5a139868766f9ece59f9f4103 fixed the problem, but it's not yet included in a release.
@jayconrod When is the next rules_go release?

@meteorcloudy The next minor release is scheduled for mid-December. I couldn't include this change in a patch release because it increased the minimum supported version of Bazel.

Is this needed sooner? I haven't had time to look into this yet beyond basic triage, so I'm not sure what the state of the flag is.

The flag is flipped and will be included in the 4.0 Bazel LTS release (which is probably going out in Dec). We caught the problem in downstream for Kythe, it's better to have a rules_go version that people can upgrade to for 4.0.

In the meantime, @shahms do you want to wait for the rules_go release or can you ping it to a specific commit?

@meteorcloudy Ok cool. I'll pull in the rules_go release as much as I can, but the earliest it could go out is ~2 weeks from now.

Confirmed that @com_github_google_brotli_go//cbrotli is broken with rules_go v0.24.7 but passes at master when --incompatible_require_linker_input_cc_api is set. Since this was fixed in #2683, I'll close this issue.

@meteorcloudy Generally prefer to wait for a rules_go release, but willing to pin to a git commit if you need. Thanks!

@shahms If you can pin rules_go to a commit, we can still test Bazel@HEAD with Kythe in downstream so that we can catch other potential breakages for you. ;)

@jayconrod I believe this bug should be reopened. On bazel 4.0 (which flips --incompatible_require_linker_input_cc_api to true by default) this bug is replicated. And I've confirmed manually setting the flag to false fixes the bug.

@mrmeku This seems to be working on master and on the 0.25 branch. The fix cannot be backported to the 0.24 branch because the minimum supported version of Bazel (2.2.0) did not support this API.

Was this page helpful?
0 / 5 - 0 ratings