Skip to content

Conversation

@meteorcloudy
Copy link
Member

@meteorcloudy meteorcloudy commented Jul 11, 2025

Fixes #18683

Related: protocolbuffers/protobuf#20085

This change is a rework of #26005 to enable short virtual includes based on a cc feature, therefore we can limit the change to only MSVC compiler on Windows.

RELNOTES: If a cc toolchain feature named shorten_virtual_includes is enabled, virtual include header files are linked under bin/_virtual_includes/<hash of target path> instead of bin/<target package path>/_virtual_includes/<target name>. This shortens the virtual include paths which is critical for mitigating long path issue with MSVC on Windows.

@meteorcloudy meteorcloudy requested review from a team, comius, lberki, pzembrod and trybka as code owners July 11, 2025 13:03
@meteorcloudy meteorcloudy requested review from aranguyen and removed request for a team July 11, 2025 13:03
@github-actions github-actions bot added team-Configurability platforms, toolchains, cquery, select(), config transitions team-Rules-CPP Issues for C++ rules awaiting-review PR is awaiting review from an assigned reviewer labels Jul 11, 2025
@meteorcloudy meteorcloudy changed the title Introduce shorten_include_paths cc toolchain feature Introduce shorten_virtual_includes cc toolchain feature Jul 11, 2025
@meteorcloudy
Copy link
Member Author

meteorcloudy commented Jul 11, 2025

I can confirm with Bazel built at this change and bazelbuild/rules_cc#438, I can build protobuf 31.1 with

startup --output_user_root=C:/a_very_very_very_very_very_looooooooooooong_path
common --cxxopt=/std:c++17 --host_cxxopt=/std:c++17
common --define=protobuf_allow_msvc=true

@mkruskal-google

virtual_include_dir = paths.join(paths.join(package_source_root(label.workspace_name, label.package, is_sibling_repository_layout), _VIRTUAL_INCLUDES_DIR), label.name)
source_package_path = package_source_root(label.workspace_name, label.package, is_sibling_repository_layout)
if shorten_virtual_includes:
virtual_include_dir = paths.join(_VIRTUAL_INCLUDES_DIR, "%x" % hash(paths.join(source_package_path, label.name)))
Copy link
Collaborator

@fmeum fmeum Jul 11, 2025

Choose a reason for hiding this comment

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

The Starlark hash is not particularly collision resistant, even on non-adversarial inputs. What would happen if this collides?

This could be an argument for introducing a better hash function to Starkark.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, we had the same discussion when reviewing the previous PR internally. We should probably upgrade it, but in another change.

Copy link
Member Author

Choose a reason for hiding this comment

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

Filed #26529 to track it

@github-actions github-actions bot removed the awaiting-review PR is awaiting review from an assigned reviewer label Jul 11, 2025
copybara-service bot pushed a commit to bazelbuild/rules_cc that referenced this pull request Jul 11, 2025
Copybara Import from #438

BEGIN_PUBLIC
Support shorten_virtual_includes (#438)

Context: bazelbuild/bazel#26528, protocolbuffers/protobuf#20085

Enable `shorten_virtual_includes` for MSVC toolchains to shorten virtual include paths to mitigate long path issue on windows.

Closes #438
END_PUBLIC

COPYBARA_INTEGRATE_REVIEW=#438 from meteorcloudy:shorten_virtual_includes 5ab4b94
PiperOrigin-RevId: 781977791
Change-Id: Ia683103cb9da2eed8cca165ccf1243f3ee1357da
meteorcloudy added a commit to meteorcloudy/bazel that referenced this pull request Jul 11, 2025
Fixes bazelbuild#18683

Related: protocolbuffers/protobuf#20085

This change is a rework of bazelbuild#26005 to enable short virtual includes based on a cc feature, therefore we can limit the change to only MSVC compiler on Windows.

RELNOTES: If a cc toolchain feature named `shorten_virtual_includes` is enabled, virtual include header files are linked under `bin/_virtual_includes/<hash of target path>` instead of `bin/<target package path>/_virtual_includes/<target name>`. This shortens the virtual include paths which is critical for mitigating long path issue with MSVC on Windows.

Closes bazelbuild#26528.

PiperOrigin-RevId: 781975309
Change-Id: Ia573a5f25707ad2462aa3a4459fc66db1779df36
@armandomontanez
Copy link

In the future, please consider documenting features like this here.

@meteorcloudy
Copy link
Member Author

Ah, thanks for catching this, will fix it now!

@meteorcloudy
Copy link
Member Author

@armandomontanez Doc added at 6ce0384

github-merge-queue bot pushed a commit that referenced this pull request Jul 11, 2025
Fixes #18683

Related: protocolbuffers/protobuf#20085

This change is a rework of
#26005 to enable short virtual
includes based on a cc feature, therefore we can limit the change to
only MSVC compiler on Windows.

RELNOTES: If a cc toolchain feature named `shorten_virtual_includes` is
enabled, virtual include header files are linked under
`bin/_virtual_includes/<hash of target path>` instead of `bin/<target
package path>/_virtual_includes/<target name>`. This shortens the
virtual include paths which is critical for mitigating long path issue
with MSVC on Windows.

Closes #26528.

PiperOrigin-RevId: 781975309
Change-Id: Ia573a5f25707ad2462aa3a4459fc66db1779df36

---------

Co-authored-by: Googler <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

team-Configurability platforms, toolchains, cquery, select(), config transitions team-Rules-CPP Issues for C++ rules

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Alternative _virtual_includes organization to solve MSVC issues

3 participants