Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doesn't CPU always have a value that would start with darwin? (unless you explicitly specified otherwise) as in if you passed
--macos_cpus=arm64,x86_64 --cpu=darwin_x86_64
it should build a fat binary for both archs but with this change I don't think it would?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey Keith! Good Q. Glad I get to engage with you on this.
Here's my reasoning--and I'd love it if you'd check me. Two cases:
Why? binary target does split cpu transition on e.g. --ios_multi_cpus or --macos_cpus -> triggers picking up the CPU from apple_split_cpu in the first lines of this function, _determine_single_architecture, returning early and bypassing all the if statements around this diff.
Hence no change; you still get your fat binary with architectures controlled by, e.g., --macos_cpus.
Current bazel behavior is, I believe, producing a single-arch archive (sometimes w/ the wrong architecture), rather than a fat binary. That's what I'm seeing in testing, and also what I'd expect from the existing code; it's only returning a single CPU.
(Now, like you, I'm not so sure the current behavior is ideally intuitive, but that's a different issue--and not one I'm trying to tackle with this intentionally minimal fix, doubly since incoming transitions like this are constrained to be 1:1 and Bazel's general binary-vs-library MO.)
To sum the above: I think we have have the same fat binary behavior as before.
(What this does change is, in the single, thin output case, where we hit this code and aren't honoring multiple cpus anyway, which architecture gets chosen as a fallback. The change makes bazel honor the single cpu flag, whether defaulted to the current machine, configured, or specified on the command line (unless the cpu has been set to some obviously invalid value that's not for Mac (doesn't start with darwin), at which point we go down the fallbacks as before). Goal here was minimal change that made objc_library work correctly with the core cc-ecosystem while maintaining reasonable defaults and configurability for the other common use cases.)