Depending on an external library which depends on an internal package

Viewed 315

I have a bazel project that depends on https://github.com/aws/aws-sdk-go-v2, and when I attempt to build my project I get the failure:

/private/var/tmp/_bazel_jason/0e236569105a6029115d2df15af0d848/external/com_github_aws_aws_sdk_go_v2_service_s3/internal/arn/BUILD.bazel:3:11: in go_library rule @com_github_aws_aws_sdk_go_v2_service_s3//internal/arn:arn: target '@com_github_aws_aws_sdk_go_v2_service_internal_s3shared//arn:arn' is not visible from target '@com_github_aws_aws_sdk_go_v2_service_s3//internal/arn:arn'. Check the visibility declaration of the former target if you think the dependency is legitimate

Based on comments in https://github.com/bazelbuild/bazel-gazelle/issues/619 I have been able to work around this by applying patches in repositories.bzl that modify the visibility clauses in the offending packages. This works, but it is hacky.

I am aware of the directive # gazelle:go_visibility, but it's not clear to me if or how this can solve my problem. I've tried using this in repositories.bzl as follows, but I still get the same error above:

 go_repository(
    name = "com_github_aws_aws_sdk_go_v2_service_s3",
    build_directives = [
        "gazelle:go_visibility @com_github_aws_aws_sdk_go_v2_service_internal_s3shared//:__subpackages__",
    ],
    importpath = "github.com/aws/aws-sdk-go-v2/service/s3",
    sum = "h1:EMihU4D4F9S/TytkQGcHSLeUHjRRjnPi0D+Xkoq6odU=",
    version = "v1.6.0",
)

I've also tried to use "gazelle:go_visibility @com_github_aws_aws_sdk_go_v2_service_internal_s3shared//arn:arn:__subpackages__" here, but that gives me an error invalid label '@com_github_aws_aws_sdk_go_v2_service_internal_s3shared//arn:arn:__subpackages__' in element 1 of attribute 'visibility' in 'go_library' rule: invalid target name 'arn:__subpackages__': target names may not contain ':'

0 Answers
Related