Skip to content

fix: make python_headers targets compatible with layering checks#3420

Merged
rickeylev merged 3 commits intobazel-contrib:mainfrom
keith:ks/add-hdrs-to-public_headers-target
Nov 22, 2025
Merged

fix: make python_headers targets compatible with layering checks#3420
rickeylev merged 3 commits intobazel-contrib:mainfrom
keith:ks/add-hdrs-to-public_headers-target

Conversation

@keith
Copy link
Member

@keith keith commented Nov 20, 2025

Previously the headers from this target were available because it
depends on python_headers_abi3, but that fails downstream
layering_checks since the headers weren't direct. Now it re-exports the
same headers as that underlying target to satisfy those checks.

Inspectable with:

bazel cquery --output=starlark --starlark:expr 'providers(target)["@@rules_cc+//cc/private:cc_info.bzl%CcInfo"].compilation_context.direct_public_headers' @rules_python//python/cc:current_py_cc_headers

Previously the headers from this target were available because it
dpeends on python_headers_abi3, but that fails downstream
layering_checks since the headers weren't direct. Now it re-exports the
same headers as that underlying target to satisfy those checks.

Inspectable with:

```
bazel cquery --output=starlark --starlark:expr 'providers(target)["@@rules_cc+//cc/private:cc_info.bzl%CcInfo"].compilation_context.direct_public_headers' @rules_python//python/cc:current_py_cc_headers
```
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @keith, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a build system issue where the python_headers target implicitly relied on headers from python_headers_abi3, leading to failures in layering_checks. The change explicitly adds the necessary headers to the python_headers target itself, ensuring direct availability and compliance with Bazel's build rules. This improves the robustness and correctness of the build configuration for Python C++ extensions.

Highlights

  • Build System Compliance: Explicitly added headers to the python_headers target to satisfy downstream layering_checks that were previously failing due to indirect header availability.
  • Direct Header Export: The python_headers cc_library now directly re-exports the headers it depends on, ensuring they are properly exposed to consumers.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds the hdrs attribute to the python_headers cc_library target. This makes the headers a direct part of the target's public interface, which, as you noted, is necessary to satisfy some downstream layering checks. The change is correct and addresses the issue. I've added one suggestion to also make the include paths direct for consistency, which would make the python_headers target's interface more explicit.

@rickeylev rickeylev changed the title Add hdrs to public_headers target fix: make python_headers targets compatible with layering checks Nov 22, 2025
@rickeylev rickeylev added this pull request to the merge queue Nov 22, 2025
Merged via the queue into bazel-contrib:main with commit 23e605c Nov 22, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants