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

gopackagesdriver: returns roots for incompatible targets #3805

Open
jayconrod opened this issue Dec 29, 2023 · 0 comments · May be fixed by #3806
Open

gopackagesdriver: returns roots for incompatible targets #3805

jayconrod opened this issue Dec 29, 2023 · 0 comments · May be fixed by #3806

Comments

@jayconrod
Copy link
Contributor

What version of rules_go are you using?

v0.44.0, master

What version of gazelle are you using?

n/a

What version of Bazel are you using?

8.0.0-pre.20231030.2

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

yes

What operating system and processor architecture are you using?

macOS, arm64

Any other potentially useful information about your toolchain?

n/a

What did you do?

In VSCode configured to use gopackagesdriver, open any Go file.

My repository contains some platform-specific targets in our third_party (vendor) directory. We don't want bazel test //... to match those, so they're marked with target_compatible_with. For example:

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

package(default_applicable_licenses = ["//third_party/go/golang.org/x/sys:license"])

go_library(
    name = "registry",
    srcs = [
        "key.go",
        "syscall.go",
        "value.go",
        "zsyscall_windows.go",
    ],
    importpath = "golang.org/x/sys/windows/registry",
    target_compatible_with = [
        "@platforms//os:windows",
    ],
    visibility = ["//visibility:public"],
    deps = select({
        "@io_bazel_rules_go//go/platform:windows": [
            "//third_party/go/golang.org/x/sys/windows",
        ],
        "//conditions:default": [],
    }),
)

go_test(
    name = "registry_test",
    srcs = [
        "export_test.go",
        "registry_test.go",
    ],
    embed = [":registry"],
    target_compatible_with = [
        "@platforms//os:windows",
    ],
)

What did you expect to see?

No errors. VSCode should load metadata about Go packages and should support editor features like go-to-definition.

What did you see instead?

In the bottom status bar, I see the error:

packages.Load error: root package @//third_party/go/golang.org/x/sys/windows/registry:registry is missing

Analysis

This happens because the response from gopackagesdriver includes @//third_party/go/golang.org/x/sys/windows/registry:registry in the list of roots (which loading metadata for all packages), but it's not in the package list. The error message is printed by packages.Load. I think we should not include the package in the roots because it's not buildable on the host platform. bazel query does match it, but bazel build can't analyze it. There's no .pkg.json file produced for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant