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

Non-public bazel visibility for parser/gen #947

Open
1 of 3 tasks
RamLavi opened this issue May 28, 2024 · 12 comments
Open
1 of 3 tasks

Non-public bazel visibility for parser/gen #947

RamLavi opened this issue May 28, 2024 · 12 comments

Comments

@RamLavi
Copy link

RamLavi commented May 28, 2024

Feature request checklist

  • There are no issues that match the desired change
  • The change is large enough it can't be addressed with a simple Pull Request
  • If this is a bug, please file a Bug Report.

Change
Please consider changing the parser/gen package's bazel visibility to //visibility:public.

parser/gen is not an internal package, so go build have no issue building code that uses the package, but parser/gen's BUILD.bazel sets the default_visibility to subpackages.

It looks like the package was made like this in the initial implementation.

The issue is that it causes error when trying to build code that uses parser/gen with bazel/gazelle, because parser/gen is not externally visible:

ERROR: /root/go/src/kubevirt.io/kubevirt/vendor/github.com/google/cel-go/parser/BUILD.bazel:7:11: no such target '//vendor/github.com/google/cel-go/parser/gen:go_default_library': target 'go_default_library' not declared in package 'vendor/github.com/google/cel-go/parser/gen' defined by /root/go/src/kubevirt.io/kubevirt/vendor/github.com/google/cel-go/parser/gen/BUILD.bazel and referenced by '//vendor/github.com/google/cel-go/parser:go_default_library'

Example
I'm using this lovely repo in order to unit test ValidatingAdmissionPolicy I'm using.
I'm importing this repo in order to implement the ExpressionAccessor interface.

Alternatives considered
Not the I know of.

@TristonianJones
Copy link
Collaborator

@RamLavi You shouldn't have any direct dependencies on parser/gen, but I hear that vendoring seems to mess with gazelle. From the gazelle docs, I see we can try # gazelle:go_visibility label which should potentially allow you to override the vendored visibility. I'm not sure if I need to update this directive in the cel-go repo or if you can manage it from your side. Honestly, happy to try both.

@RamLavi
Copy link
Author

RamLavi commented May 30, 2024

Hey thanks for the prompt reply!

@RamLavi You shouldn't have any direct dependencies on parser/gen, but I hear that vendoring seems to mess with gazelle.

It is indeed a mystery to me, my import is only in order to implement an object that complies to the ExpressionAccessor interface, so it's not clear why this visibility issue is there in the first place.
Moreover, this is not the only vendor we're importing that uses __subpackages__ visibility (github.com/onsi/ginkgo/v2 for example) and we never encountered this before.

From the gazelle docs, I see we can try # gazelle:go_visibility label which should potentially allow you to override the vendored visibility. I'm not sure if I need to update this directive in the cel-go repo or if you can manage it from your side. Honestly, happy to try both.

i think the # gazelle:go_visibility label directive needs to be done from the importing (=my) side, and I'm asking my team in order to see how they feel about it, but I also wanted to know - is there a reason for this folder to be non-public?
My concern is that other repos that use bazel and try to write unit tests for validatingAdmissionPolicies may encounter similar visibility issues.

@TristonianJones
Copy link
Collaborator

The parser/gen package is truly internal and we don't want anyone to depend on it accidentally. I'm not sure if there's a better package layout which would avoid the vendoring visibility issue, but we should be able to move the package pretty easily if so.

@RamLavi
Copy link
Author

RamLavi commented Jun 2, 2024

The parser/gen package is truly internal and we don't want anyone to depend on it accidentally. I'm not sure if there's a better package layout which would avoid the vendoring visibility issue, but we should be able to move the package pretty easily if so.

ACK. I will try to dig some more on bazel logs and see if there's a clue why it happens and how we can work around it. Is that OK if we keep this issue open until we have more information?
Thanks for the help!

RamLavi added a commit to RamLavi/kubevirt that referenced this issue Jun 2, 2024
currently fails with bazel visibility error, see issue
google/cel-go#947

tests need more scenarios to fit all validation rules but the gist is
done.
in order to run test with visibility check excluded:
```
hack/dockerized bazel test --test_output=errors --cache_test_results=no
--check_visibility=false //pkg/virt-operator/...
```

Signed-off-by: Ram Lavi <ralavi@redhat.com>
@TristonianJones
Copy link
Collaborator

@RamLavi totally fine to keep the issue open until we know more. My best guess is that the visibility isn't happy with being moved to a new directory. From what I understand, this can be fixed at the tooling layer with annotations in BUILD files, but it's not a very friendly user experience either way

RamLavi added a commit to RamLavi/kubevirt that referenced this issue Jun 4, 2024
currently fails with bazel visibility error, see issue
google/cel-go#947

tests need more scenarios to fit all validation rules but the gist is
done.
in order to run test with visibility check excluded:
```
hack/dockerized bazel test --test_output=errors --cache_test_results=no
--check_visibility=false //pkg/virt-operator/...
```

Signed-off-by: Ram Lavi <ralavi@redhat.com>
RamLavi added a commit to RamLavi/kubevirt that referenced this issue Jun 6, 2024
currently fails with bazel visibility error, see issue
google/cel-go#947

in order to run test with visibility check excluded:
```
hack/dockerized bazel test --test_output=errors --cache_test_results=no
--check_visibility=false //pkg/virt-operator/...
```

Signed-off-by: Ram Lavi <ralavi@redhat.com>
@TristonianJones
Copy link
Collaborator

@RamLavi any progress to report?

RamLavi added a commit to RamLavi/kubevirt that referenced this issue Jun 17, 2024
currently fails with bazel visibility error, see issue
google/cel-go#947

in order to run test with visibility check excluded:
```
hack/dockerized bazel test --test_output=errors --cache_test_results=no
--check_visibility=false //pkg/virt-operator/...
```

Signed-off-by: Ram Lavi <ralavi@redhat.com>
@RamLavi
Copy link
Author

RamLavi commented Jun 26, 2024

@RamLavi any progress to report?

BAZEL is hard, and not well documented :) I didn't manage to understand how to properly set the label so that it will ignore your library's visibility.
I'm currently waiting for support from my team, but they are not yet free to assist on this matter.

@SlayerBirden
Copy link

Hi, I wanted to just emphasise that this library is essentially broken for anyone using Bazel. This bug is not getting a lot of traction because I think the majority of users aren't using Bazel.

The first example on this page https://pkg.go.dev/github.com/google/cel-go/cel#pkg-overview is not possible since github.com/google/cel-go/cel package depends on parser: https://github.com/google/cel-go/blob/master/cel/BUILD.bazel#L41, and parser depends on gen: https://github.com/google/cel-go/blob/master/parser/BUILD.bazel#L28 which is not public.

As far as I understand maintainers don't want to make gen public? But what is the alternative? How can private package be a dependency of the public one?

@TristonianJones

@TristonianJones
Copy link
Collaborator

@SlayerBirden bazel dependency graphs aren't supposed to be all set to the same visibility in order to function properly; however, I don't think that the bazel team considered go vendoring. I will poke around to see what the options are, but often such interactions are non-trivial and poorly documented

@SlayerBirden
Copy link

@TristonianJones thanks for the update! If you have any suggestion I'd also appreciate that.

@RamLavi
Copy link
Author

RamLavi commented Oct 29, 2024

@TristonianJones thanks for looking into this! Can you share if you have any update?

@TristonianJones
Copy link
Collaborator

@RamLavi I'm hopeful the change is as simple as what's been put forward for review.

RamLavi added a commit to RamLavi/kubevirt that referenced this issue Nov 5, 2024
currently fails with bazel visibility error, see issue
google/cel-go#947

in order to run test with visibility check excluded:
```
hack/dockerized bazel test --test_output=errors --cache_test_results=no
--check_visibility=false //pkg/virt-operator/...
```

Signed-off-by: Ram Lavi <ralavi@redhat.com>
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

No branches or pull requests

3 participants