Skip to content

Set direct/transitive module sets for CppCompileAction without include scanning - #30396

Open
fmeum wants to merge 1 commit into
bazelbuild:masterfrom
fmeum:claude/bazel-cpp-compile-modules-4spvby
Open

Set direct/transitive module sets for CppCompileAction without include scanning#30396
fmeum wants to merge 1 commit into
bazelbuild:masterfrom
fmeum:claude/bazel-cpp-compile-modules-4spvby

Conversation

@fmeum

@fmeum fmeum commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

Description

When include scanning is disabled, CppCompileAction never populated its top-level modules nor its discovered (transitive) modules: the former caused getOverwrittenVariables() to fall back to putting every transitive .pcm on the command line, and the latter left ActionExecutionValue without discovered modules for module-producing compiles.

Fix this by computing a suitable upper bound at action construction time when header modules are used without include scanning:

  • Top-level modules: the modules of direct dependencies plus the separate module of the current context (except for its own compile), mirroring the exclusions of CcCompilationContext#computeUsedModules. Modules that are only used transitively are found by the compiler through the paths embedded in the direct .pcm files, just as in the include scanning case.
  • Discovered (transitive) modules: all transitive modules plus the top-level bound, which are all provided as inputs.

Since the separate module of the current context is not part of the transitive modules, CppCompileActionBuilder now also adds it as an input to all compiles of the context other than its own compile, matching the existing allowedDerivedInputs special case.

Motivation

Fixing header module compilation in Bazel with default settings, i.e., without include scanning.

Build API Changes

No

Checklist

  • I have added tests for the new use cases (if any).
  • I have updated the documentation (if applicable).

Release Notes

RELNOTES: None

@google-cla

google-cla Bot commented Jul 21, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@fmeum fmeum changed the title Set module upper bounds for CppCompileAction without include scanning Set direct/transitive module sets for CppCompileAction without include scanning Jul 21, 2026
@fmeum
fmeum force-pushed the claude/bazel-cpp-compile-modules-4spvby branch from 5bb1cb4 to cc82226 Compare July 21, 2026 16:09
When include scanning is disabled, CppCompileAction never populated its
top-level modules nor its discovered (transitive) modules: the former
caused getOverwrittenVariables() to fall back to flattening all inputs,
putting every transitive .pcm on the command line, and the latter left
ActionExecutionValue without discovered modules for module-producing
compiles.

Fix this by computing a suitable upper bound at action construction time
when header modules are used without include scanning:

* Top-level modules: the modules of direct dependencies plus the separate
  module of the current context (except for its own compile), mirroring
  the exclusions of CcCompilationContext#computeUsedModules. Modules that
  are only used transitively are found by the compiler through the paths
  embedded in the direct .pcm files, just as in the include scanning case.
* Discovered (transitive) modules: all transitive modules plus the
  top-level bound, which are all provided as inputs.

Since the separate module of the current context is not part of the
transitive modules, CppCompileActionBuilder now also adds it as an input
to all compiles of the context other than its own compile, matching the
existing allowedDerivedInputs special case.
@fmeum
fmeum force-pushed the claude/bazel-cpp-compile-modules-4spvby branch from cc82226 to 7737d92 Compare July 21, 2026 17:14
@fmeum
fmeum marked this pull request as ready for review July 21, 2026 21:18
@fmeum
fmeum requested review from lberki, pzembrod and trybka as code owners July 21, 2026 21:18
@fmeum
fmeum removed request for lberki and pzembrod July 21, 2026 21:18
@github-actions github-actions Bot added team-Rules-CPP Issues for C++ rules awaiting-review PR is awaiting review from an assigned reviewer labels Jul 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-review PR is awaiting review from an assigned reviewer team-Rules-CPP Issues for C++ rules

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant