Skip to content

Fix exec transition handling in cc tool_map for multiplatform builds#548

Closed
dzbarsky wants to merge 1 commit into
bazelbuild:mainfrom
dzbarsky:zbarsky/exec
Closed

Fix exec transition handling in cc tool_map for multiplatform builds#548
dzbarsky wants to merge 1 commit into
bazelbuild:mainfrom
dzbarsky:zbarsky/exec

Conversation

@dzbarsky

Copy link
Copy Markdown
Contributor

These extra exec transitions are harmful because they allow Bazel to select a different exec platform than the one the toolchain is being used on. This means when host != exec (say Windows host, Linux remote), the wrong compiler can be picked and the build fails.

Without this patch, users who want to support multiplatform builds need to hack it by forcing the tools to transition to the correct exec platform, since the toolchain "forgets". See example workaround being reverted and CI works when patch is applied

While I was here I cleaned up the example a bit to be more like the canonical usage of cc_tool.

@fmeum

fmeum commented Dec 15, 2025

Copy link
Copy Markdown
Collaborator

@armandomontanez @pzembrod A full fix for the toolchain resolution behavior would require moving the tool_map attribute up to the cc_toolchain rule. If you are okay with this, I can work on a follow-up PR that turns the rule-based cc_toolchain macro into a proper rule with this property.

@armandomontanez

Copy link
Copy Markdown
Collaborator

I'm on board. For now, I'm going to manually import this change and patch in a docs update that reflects the behavioral change. This was the near-term direction we decided on for #299, and as @fmeum has mentioned now that most of the rules_cc implementation has been moved into this repo, we can pursue the better solution of doing an exec transition from the top.

We talked about potentially doing this quite a while back, but I'd like to double check with @pzembrod to make sure we have a green light to pursue that right now.

@dzbarsky

Copy link
Copy Markdown
Contributor Author

I'd prefer we do the real fix Fabian mentions instead of trying to land this first. I think if we land this as-is it will break using 'select' on the platform. This stuff is pretty subtle and we should be careful and do a holistic fix IMO

@dzbarsky

Copy link
Copy Markdown
Contributor Author

OK I updated the PR to keep the exec transition on the tools attribute in tool_map for now, so it's not breaking. It's safe to remve the transition on cc_tool, that one is not needed. So we should be able to land this PR whenever we want, but it's not sufficient to fix the entire problem :)

@armandomontanez armandomontanez left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks, will merge after I get a 2nd approval internally.

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