Hello @gn-dev,
Context: some GN `template`s will expand into **multiple** targets. For example, `rust_static_library("foo")` will expand into a `group("foo")` and a bag of interdependent other targets (e.g. `rust_library("foo_main_target")`, `foo_clippy`, `foo_cxx_generated`, etc.). It is quite common for `deps` specified for `rust_static_library("foo")` to be needed by more than 1 target - let me share 2 examples example:
- A native library (used via FFI) needs to be 1) linked as a transitive dependency of `foo_main_target` and 2) included from `.rs.h` and/or `.rs.cc` files generated by `cxx` FFI tool run underneath `foo_cxx_generated`
- A `build.rs`-generated `gen/.../auto_generated_source.rs` may need to be `include!`d from one of sources of "foo" when 1) building `foo_main_target` using `rustc`, 2) linting `foo_clippy` using `clippy-driver`, 3) generating C++ bindings in `foo_cpp_api_from_rust` target using Crubit
Problem: setting `visibility = [":foo"]` may result in a dependency being visible only to `group("foo")` and being invisible the other, internal targets that `rust_static_library("foo")` expands into.
A workaround that Chrome Rust team has been recommending is to set `visibility = [":*"]` instead of `visibility = [":foo"]`. This is a somewhat broader visibility, but the affected target's visibility still remains restricted to a given directory - using the target from another directory would require changing it's `visibility` which would presumably would require `OWNERS` approval for `BUILD.gn` changes. QUESTION: Is this a reasonable guidance?
In theory GN could:
- internally track the origin of a target - e.g. it could track that `action_foreach("foo_cxx_generated_gen")` got expanded from `rust_cxx("foo_cxx_generated")` which got expanded from `rust_target("foo")` which got expanded from `rust_static_library("foo")`.
- compare `visibility` not just to a given target name (e.g. to `":foo_cxx_generated_gen"`) but to the whole expansion set (e.g. also compare `visibility` to `":foo_cxx_generated"` and `":foo"`).
QUESTION: Does the above look like a reasonable feature request for GN? What is the best way to discuss and track this proposal? Should I open a new bug for this in
https://gn.issues.chromium.org/home?
QUESTION: Are there other potential ways forward? (e.g. additional wildcard support in `visibility` declarations/lists)
Best regards,
Lukasz