diff --git a/.bazelignore b/.bazelignore index 09a2221b51..a6b5983f4b 100644 --- a/.bazelignore +++ b/.bazelignore @@ -5,5 +5,6 @@ src/sta/debug/ # we use abc from MODULE.bazel third-party/abc/ tmp -# standalone workspace for downstream consumer tests +# standalone workspaces for downstream consumer tests test/downstream/ +test/visibility/ diff --git a/BUILD.bazel b/BUILD.bazel index 9e6d2babbc..06c84fdf4e 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -227,7 +227,7 @@ cc_library( includes = [ "include", ], - visibility = ["//:__subpackages__"], + visibility = ["//visibility:public"], deps = [ "//src/sta:opensta_lib", "@abseil-cpp//absl/base:core_headers", @@ -251,7 +251,7 @@ cc_library( "include", "include/ord", ], - visibility = ["//:__subpackages__"], + visibility = ["//visibility:public"], deps = ["@abseil-cpp//absl/synchronization"], ) diff --git a/test/visibility/.bazelversion b/test/visibility/.bazelversion new file mode 100644 index 0000000000..acd405b1d6 --- /dev/null +++ b/test/visibility/.bazelversion @@ -0,0 +1 @@ +8.6.0 diff --git a/test/visibility/BUILD.bazel b/test/visibility/BUILD.bazel new file mode 100644 index 0000000000..0e35f4b229 --- /dev/null +++ b/test/visibility/BUILD.bazel @@ -0,0 +1,15 @@ +# Downstream visibility smoke test. +# +# Each alias references an OpenROAD target that downstream consumers +# need. If any target has visibility restricted to //:__subpackages__, +# Bazel analysis will fail with a visibility error — proving the bug. +# +# Run: bazelisk build --nobuild :all + +[alias( + name = t, + actual = "@openroad//:" + t, +) for t in [ + "openroad_lib", + "ord", +]] diff --git a/test/visibility/MODULE.bazel b/test/visibility/MODULE.bazel new file mode 100644 index 0000000000..a803ecd9df --- /dev/null +++ b/test/visibility/MODULE.bazel @@ -0,0 +1,12 @@ +"""Minimal downstream consumer that tests Bazel visibility of OpenROAD targets.""" + +module( + name = "visibility-test", + version = "0.0.0", +) + +bazel_dep(name = "openroad") +local_path_override( + module_name = "openroad", + path = "../..", +) diff --git a/test/visibility/README.md b/test/visibility/README.md new file mode 100644 index 0000000000..5a9126c5db --- /dev/null +++ b/test/visibility/README.md @@ -0,0 +1,34 @@ +# Bazel visibility test for downstream consumers + +## Why each target is public + +### `openroad_lib` (cc_library) and `ord` (cc_library — headers) + +These are the core C++ library and public headers. A downstream +Bazel consumer that wants to build a custom binary linking against +the OpenROAD library (rather than just running the prebuilt +`openroad` binary) must be able to depend on these targets. + +### Why NOT the SWIG filegroups + +`error_swig`, `error_swig-py`, and `options_swig` stay at +`//:__subpackages__`. They are referenced by internal subpackages +(e.g. `//src/gpl:swig` depends on `//:error_swig`), which already +satisfies the `__subpackages__` visibility check. No downstream +consumer references them directly. + +## How to test + +```bash +cd test/visibility +bazelisk build --nobuild :all +``` + +If any target is not publicly visible, Bazel fails at analysis time: + +``` +ERROR: target '@openroad//:openroad_lib' is not visible from +target '@@visibility-test//:openroad_lib'. +``` + +After the fix, the command succeeds (exit 0).