Add crate_package_default_visibility to render_config#4003
Open
tamasvajk wants to merge 2 commits intobazelbuild:mainfrom
Open
Add crate_package_default_visibility to render_config#4003tamasvajk wants to merge 2 commits intobazelbuild:mainfrom
crate_package_default_visibility to render_config#4003tamasvajk wants to merge 2 commits intobazelbuild:mainfrom
Conversation
Allow configuring the default_visibility of individual crate BUILD
packages generated by crate_universe. By default, crate packages use
//visibility:public. Setting crate_package_default_visibility restricts
direct references to crate targets, encouraging consumers to go through
top-level aliases instead.
This is useful in monorepos where visibility control helps enforce
dependency hygiene.
Example usage in render_config():
render_config(
crate_package_default_visibility = ["//third_party/rust:__subpackages__"],
)
8161340 to
8f02225
Compare
Two tests in rendering.rs: - render_crate_package_default_visibility: verifies custom visibility appears in the generated BUILD file instead of //visibility:public - render_default_visibility_when_not_configured: verifies the default behavior (//visibility:public) when the option is not set Use skip_serializing_if on the new field to preserve lockfile digest compatibility when the option is not set (None).
8f02225 to
ab9eb40
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add
crate_package_default_visibilityoption torender_configfor controlling the visibility of individual crate BUILD packages generated bycrate_universe.Problem
All generated crate BUILD packages use
//visibility:publicunconditionally. In monorepos, this allows any target to directly depend on versioned crate targets (e.g.@crates__tokio-1.2.3//:tokio) instead of going through the top-level aliases (e.g.@crates//:tokio). Direct references to versioned targets are fragile and bypass any dependency governance the aliases provide.Fix
Add an optional
crate_package_default_visibilityparameter torender_config(). When set, generated crate BUILD packages use the specified visibility instead of//visibility:public. The top-level aliases BUILD is unaffected and remains public.Example usage:
Changes:
crate_universe/private/generate_utils.bzl: add parameter and pass through to JSON configcrate_universe/src/config.rs: addcrate_package_default_visibilityfield toRenderConfigcrate_universe/src/rendering.rs: usecrate_packagehelper method that respects the config