bazelbuild / bazelbuild/bazel

Visibility checks use the location of the symbolic macro's definition

Open
#27,092 7 comments 2 reactions 0 assignees View on GitHub
P3 team-Loading-API type: bug
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 20h
Merged PRs (30d)
72

Description

### Description of the bug:

When a symbolic macro uses a label (string) defined in its implementation (e.g., hard-coded or generated from attributes), the visibility checks for use of that label are based on the location of the symbolic macro's definition rather than the package using the macro to define a target. This applies to both target and file visibility.

As a result:
* Such dependencies and files must be visible to the package containing the symbolic macro definition.
* Any target defined using the symbolic macro can access those files via the macro because the actual package of the target is not checked.

### Which category does this issue belong to?

Core

### What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

https://fxrev.dev/1377945 provides targets and instructions to reproduce this. It is in a Fuchsia workspace, but it should be easy to adapt to a simpler workspace.

In that CL, the legacy macro works fine, but the target using the symbolic macro fails to build with two visibility errors. If two additional lines - an additional visibility entry and a `exports_files()` statement - are uncommented, the symbolic macro builds successfully.

### Which operating system are you running Bazel on?

Linux

### What is the output of `bazel info release`?

release 8.2.1

### If `bazel info release` returns `development version` or `(@non-git)`, tell us how you built Bazel.

_No response_

### What's the output of `git remote get-url origin; git rev-parse HEAD` ?

```text

```

### If this is a regression, please try to identify the Bazel commit where the bug was introduced with bazelisk --bisect.

_No response_

### Have you found anything relevant by searching the web?

Issue #25940 may be related and provide context for why this is happening.

### Any other information, logs, or outputs that you want to share?

The errors when building the symbolic macro target from https://fxrev.dev/1377945:

```
$ fx bazel build //build/bazel/examples/hello_host:my_symbolic_test
ERROR: out/default/gen/build/bazel/workspace/build/bazel/examples/hello_host/BUILD.bazel:22:20: in filegroup rule //build/bazel/examples/hello_host:my_symbolic_test: Visibility error:
target '//build/bazel/examples/hello_host:main.cc' is not visible from
target '//build/bazel/examples/hello_host:my_symbolic_test'
Recommendation: modify the visibility declaration if you think the dependency is legitimate. For more info see https://bazel.build/concepts/visibility. To set the visibility of that source file target, use the exports_files() function
ERROR: out/default/gen/build/bazel/workspace/build/bazel/examples/hello_host/BUILD.bazel:22:20: in filegroup rule //build/bazel/examples/hello_host:my_symbolic_test: Visibility error:
target '//build/bazel/examples/hello_world:hello_world' is not visible from
target '//build/bazel/examples/hello_host:my_symbolic_test'
Recommendation: modify the visibility declaration if you think the dependency is legitimate. For more info see https://bazel.build/concepts/visibility
ERROR: out/default/gen/build/bazel/workspace/build/bazel/examples/hello_host/BUILD.bazel:22:20: Analysis of target '//build/bazel/examples/hello_host:my_symbolic_test' failed
ERROR: Analysis of target '//build/bazel/examples/hello_host:my_symbolic_test' failed; build aborted
```

Contributor guide

Open the contributing guide

Research direction

Start with the minimal reproduction and instructions in https://fxrev.dev/1377945, then read issue #25940 for related context. Build the symbolic macro target and compare its visibility checks with the legacy macro; the work is done when the target and file dependencies resolve from the package using the macro without extra visibility declarations.

Written by the indexing model from the issue text.

Assessment

Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.