Skip to content

tests: make some analysis tests work for when test's exec platform is required #2869

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

fmeum
Copy link
Member

@fmeum fmeum commented May 9, 2025

An upcoming change in Bazel makes the test toolchain required, which means a compatible
exec platform amongst toolchains must be found (bazelbuild/bazel@2780393).

Some analysis tests force the target platform to a specific platform, but the exec platform
was left alone. The combination of toolchains, target platform, and exec platform then
prevented a toolchain resolution from succeeding (the py rules depend on some cc targets,
which need the cc toolchain, which needs an exec platform).

To fix: Also explicitly set the exec platform and use a fake cc toolchain. This ensures a valid combination is used.

Work towards #2850

@fmeum
Copy link
Member Author

fmeum commented May 9, 2025

@rickeylev @aignas I need help here. I am registering the test target platform as an execution platform to ensure compatibility with the new test toolchain, but that runs into an issue I'm planning to resolve in the future by bazelbuild/bazel#26019: every py_executable has an exec dependency on a C++ toolchain through launcher_maker.

In this particular case, I could work around this by transitioning to the host platform rather than the fixed platform LINUX_X86_64. Would that be acceptable?

@rickeylev
Copy link
Collaborator

The launcher_maker is only needed for windows, so that dependency shouldn't be occurring for linux et al. I see it's refering to @bazel_tools//tools/launcher:launcher_maker directly, though. IIRC, bazel_tools has a select() to point that to something no-op. So it shouldn't still be requiring a C++ toolchain?

Would it help if we changed py_executable to point to an alias with select()?

alias(
    name = "launcher_maker",
    actual = select({
        "@platforms//os:windows": "@bazel_tools/tools/launcher:launcher_maker",
        "//conditions:default": "//python:none",
    })

py_executable has an optional dependency on the cc toolchain regardless, but I'm assuming that's OK.

@fmeum
Copy link
Member Author

fmeum commented May 9, 2025

Yes, it's only needed for Windows, but with the current setup within Bazel, every OS pays the price (the exec dep on a C++ toolchain).

The selects (both the one that exists in Bazel and the one you suggest) apply after the exec transition and thus can't distinguish between a build that targets Windows and a build that doesn't. That's why I'm planning to introduce a toolchain for the launcher maker, which can match on both exec and target platform simultaneously.

However, this will require Bazel feature detection or a new BCR module for the launcher maker, so it won't help here (at least not soon).

@rickeylev
Copy link
Collaborator

I think I follow, I think 🙃

Transitioning to the host platform is probably ok.

@fmeum
Copy link
Member Author

fmeum commented May 11, 2025

I now realized that this wouldn't work on Windows hosts. What do you think of registering a fake C++ toolchain? I've done that on other analysis tests and it did work there.

@rickeylev
Copy link
Collaborator

Sgtm. There are a couple fake cc tool chains in tests/support/cc_toolchain that might just work already

@rickeylev rickeylev changed the title fix: add execution platforms to more analysis tests tests: make some analysis tests work for when test's exec platform is required May 12, 2025
@rickeylev
Copy link
Collaborator

I updated the title and description to better reflect the what/why -- can you please confirm/correct?

CI is passing after your recent change, so I think this is otherwise ready?

After the title/description is confirmed, we can queue to merge.

@aignas
Copy link
Collaborator

aignas commented May 12, 2025

Does this PR mean that users using rules_python will have to depend on a C++ toolchain eventually? Or will this limitation be fixed in the future (bazelbuild/bazel#26019)?

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.

3 participants