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

Support aspect_hints for improved Swift interop compatibility #1191

Commits on Apr 5, 2024

  1. Add the swift_interop_hint rule to be used with aspect_hints.

    The new `aspect_hints` attribute in Bazel, available on all rules, lets us attach arbitrary providers to targets that `swift_clang_module_aspect` can read. The `swift_interop_hint` rule uses this to provide the module name for whichever target references it in its `aspect_hints`.
    
    A canonical auto-deriving hint is also provided as part of the Swift build rules (in `.../swift:auto_module`), so that the default/recommended behavior of deriving a module name from the target label can be easily obtained without having to declare one's own `swift_module_hint` targets.
    
    This is a more principled approach to handling Swift interop than the current `tags` implementation (which will be removed in a future change), and lets us associate additional metadata easily in the future, including files (for example, custom module maps or APINotes).
    
    PiperOrigin-RevId: 387147846
    (cherry picked from commit c42a37a)
    allevato authored and brentleyjones committed Apr 5, 2024
    Configuration menu
    Copy the full SHA
    eb5f6e5 View commit details
    Browse the repository at this point in the history
  2. Add support for custom module_maps in swift_interop_hint.

    This allows rules like `cc_library` to associate a custom module map if needed (however, this should be rare and used sparingly). It also eliminates the need for the `swift_c_module`, which will be removed.
    
    Added analysis tests around the propagation of the module map artifacts.
    
    PiperOrigin-RevId: 387195026
    (cherry picked from commit 1356365)
    allevato authored and brentleyjones committed Apr 5, 2024
    Configuration menu
    Copy the full SHA
    708c6cd View commit details
    Browse the repository at this point in the history
  3. Don't drop SwiftInfo providers from the target's dependencies when …

    …using `swift_interop_hint`.
    
    PiperOrigin-RevId: 387355219
    (cherry picked from commit 81c3074)
    allevato authored and brentleyjones committed Apr 5, 2024
    Configuration menu
    Copy the full SHA
    a1ae533 View commit details
    Browse the repository at this point in the history
  4. Delete the swift_c_module rule.

    Its functionality has been replaced by `swift_import_hint` and `aspect_hints`.
    
    PiperOrigin-RevId: 387358449
    (cherry picked from commit 553f697)
    allevato authored and brentleyjones committed Apr 5, 2024
    Configuration menu
    Copy the full SHA
    e480aca View commit details
    Browse the repository at this point in the history
  5. Replace the swift_module tag in the gRPC BUILD overlay with a `swif…

    …t_interop_hint`.
    
    PiperOrigin-RevId: 388242317
    (cherry picked from commit 6ded44e)
    allevato authored and brentleyjones committed Apr 5, 2024
    Configuration menu
    Copy the full SHA
    5856821 View commit details
    Browse the repository at this point in the history
  6. Revert "Generate module maps for cc_library deps"

    This reverts commit 15e8c3d.
    keith authored and brentleyjones committed Apr 5, 2024
    Configuration menu
    Copy the full SHA
    15013e8 View commit details
    Browse the repository at this point in the history
  7. Remove support for interop using the swift_module tag.

    Interop for non-Obj-C rules should now exclusively use `aspect_hints` (see the documentation for `swift_interop_hint`).
    
    PiperOrigin-RevId: 388940287
    (cherry picked from commit a67043f)
    allevato authored and brentleyjones committed Apr 5, 2024
    Configuration menu
    Copy the full SHA
    69fa0f0 View commit details
    Browse the repository at this point in the history
  8. Add a way for swift_interop_hint to suppress the module for targets…

    … that generate them by default, like `objc_library`.
    
    PiperOrigin-RevId: 391087374
    (cherry picked from commit de0f604)
    allevato authored and brentleyjones committed Apr 5, 2024
    Configuration menu
    Copy the full SHA
    4cf19d2 View commit details
    Browse the repository at this point in the history
  9. Add exclude_hdrs to swift_interop_hint.

    This attribute can be used to exclude a list of headers from the Swift-generated module map (via `exclude header` declarations) without removing them from the hinted target completely. This is often helpful in cases where some subset of headers are not Swift-compatible but still needed as part of the library for other reasons (e.g., they are private headers used by implementation source files, or still used by other non-Swift dependents).
    
    PiperOrigin-RevId: 398076709
    (cherry picked from commit ef6662c)
    allevato authored and brentleyjones committed Apr 5, 2024
    Configuration menu
    Copy the full SHA
    ea19476 View commit details
    Browse the repository at this point in the history
  10. Correctly exclude both the actual and virtual header when using `swif…

    …t_interop_hint.exclude_hdrs` on a `cc_library` that has `include_prefix` and/or `strip_include_prefix` set.
    
    PiperOrigin-RevId: 412917671
    (cherry picked from commit 6b13232)
    allevato authored and brentleyjones committed Apr 5, 2024
    Configuration menu
    Copy the full SHA
    495edff View commit details
    Browse the repository at this point in the history
  11. Update Swift build rules to support, and enable, explicit modules for…

    … J2ObjC
    
    Targets processed by J2ObjC's aspects have a new compilation context created that treats the generated J2ObjC headers as textual headers, and the "umbrella" header as a regular header. The root path of the generated headers is added to the compilation context as an include path so the headers can be found by dependents.
    
    To handle `java_libary`'s `exports` attribute (this lists targets that should be treated as a direct dependency when depending on the `java_libary` in question), the `SwiftInfos` from dependencies are split into direct and indirect. These are then propagated as `direct_swift_infos` vs `swift_infos` respectively to provide the semantics of `exports`.
    
    The modular import header rewriter was updated to accommodate the fact that the J2ObjC "umbrella" header is no longer marked as being an umbrella header in the module map. It still needs to be rewritten for the same reason as before, but must now be detected by a portion of the file path (🤮).
    
    PiperOrigin-RevId: 416355827
    (cherry picked from commit dd22a51)
    Googler authored and brentleyjones committed Apr 5, 2024
    Configuration menu
    Copy the full SHA
    3ee3129 View commit details
    Browse the repository at this point in the history
  12. Represent symlinks from cc_inc_library targets as textual headers s…

    …o that
    
    layering checks are still satisfied correctly.
    
    PiperOrigin-RevId: 416824355
    (cherry picked from commit 7c7ee72)
    allevato authored and brentleyjones committed Apr 5, 2024
    Configuration menu
    Copy the full SHA
    8095662 View commit details
    Browse the repository at this point in the history
  13. Migrate ObjcProvider's direct headers usage to CcInfo

    The direct_headers field in ObjcProvider is being deprecated and will
    be removed.  The same information can be found in CcInfo.
    J2ObjcAspect has been modified so that the CcInfo is accessible via
    Starlark.
    
    PiperOrigin-RevId: 417648590
    (cherry picked from commit 612725e)
    googlewalt authored and brentleyjones committed Apr 5, 2024
    Configuration menu
    Copy the full SHA
    6920972 View commit details
    Browse the repository at this point in the history
  14. Copy strict_includes into SwiftInfo provider's Clang module descr…

    …iptor in `swift_clang_module_aspect`.
    
    This makes it so that the `apple_common.Objc` provider no longer needs to be handled separately for compilation by Swift build APIs. (It is still used for linking until that is migrated entirely onto `CcInfo`.)
    
    PiperOrigin-RevId: 423822059
    (cherry picked from commit 8ce9595)
    allevato authored and brentleyjones committed Apr 5, 2024
    Configuration menu
    Copy the full SHA
    0eadb3d View commit details
    Browse the repository at this point in the history
  15. Remove unused variable & function.

    RELNOTES: None
    PiperOrigin-RevId: 430276243
    (cherry picked from commit 01b9d32)
    thomasvl authored and brentleyjones committed Apr 5, 2024
    Configuration menu
    Copy the full SHA
    af1f5c6 View commit details
    Browse the repository at this point in the history
  16. Configuration menu
    Copy the full SHA
    318172f View commit details
    Browse the repository at this point in the history