Skip to content
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

[apple] fix issues compiling C in objc_library for watchos/armv7k #14367

Closed
wants to merge 1 commit into from

Conversation

dflems
Copy link
Contributor

@dflems dflems commented Dec 2, 2021

Reproducible example here: https://github.com/dflems/bazel-repro/tree/master/watch-armv7k. This was tested against 5.0.0 rc2 and latest master and fails on both. The build succeeds after this fix is applied.

Basically, if you have any non-objc files (like C sources) in objc_library rules, they'll get compiled for the wrong architecture when targeting watchOS/armv7k.

The target triplet for the watchos_armv7k CPU was set to armv7-apple-watchos instead of armv7k-apple-watchos (which is what Xcode sets when compiling/linking for this architecture). It's been like this for a few years, but I think this has always been wrong.

Before the recent starlark rewrite of the objc rules, it appears that all of the sources (objc or not) were compiled with the -arch armv7k arguments applied. After the rewrite, objc still gets compiled this way but C files in the same library get the target triplet from the crosstool, which is incorrect. Then when libtool creates the archive, the object files are filtered out because they don't match -arch_only armv7k.

If approved, I think this should be cherry-picked into the 5.0 release.

@google-cla google-cla bot added the cla: yes label Dec 2, 2021
@keith
Copy link
Member

keith commented Dec 2, 2021

@oquenchil can you review

@BalestraPatrick BalestraPatrick mentioned this pull request Dec 3, 2021
9 tasks
@Wyverald
Copy link
Member

Wyverald commented Dec 7, 2021

Thanks for the fix! I'll import and cherrypick this shortly.

@bazel-io bazel-io closed this in dce2435 Dec 7, 2021
Wyverald pushed a commit that referenced this pull request Dec 7, 2021
Reproducible example here: https://github.com/dflems/bazel-repro-armv7k. This was tested against 5.0.0 rc2 and latest master and fails on both. The build succeeds after this fix is applied.

Basically, if you have any non-objc files (like C sources) in `objc_library` rules, they'll get compiled for the wrong architecture when targeting watchOS/armv7k.

The target triplet for the `watchos_armv7k` CPU was set to `armv7-apple-watchos` instead of `armv7k-apple-watchos` (which is what Xcode sets when compiling/linking for this architecture). It's been like this for a few years, but I think this has always been wrong.

Before the recent starlark rewrite of the objc rules, it appears that all of the sources (objc or not) were compiled with the `-arch armv7k` arguments applied. After the rewrite, objc still gets compiled this way but C files in the same library get the target triplet from the crosstool, which is incorrect. Then when `libtool` creates the archive, the object files are filtered out because they don't match `-arch_only armv7k`.

If approved, I think this should be cherry-picked into the 5.0 release.

Closes #14367.

PiperOrigin-RevId: 414693641
@dflems dflems deleted the armv7k branch December 8, 2021 12:43
Bencodes pushed a commit to Bencodes/bazel that referenced this pull request Jan 10, 2022
Reproducible example here: https://github.com/dflems/bazel-repro-armv7k. This was tested against 5.0.0 rc2 and latest master and fails on both. The build succeeds after this fix is applied.

Basically, if you have any non-objc files (like C sources) in `objc_library` rules, they'll get compiled for the wrong architecture when targeting watchOS/armv7k.

The target triplet for the `watchos_armv7k` CPU was set to `armv7-apple-watchos` instead of `armv7k-apple-watchos` (which is what Xcode sets when compiling/linking for this architecture). It's been like this for a few years, but I think this has always been wrong.

Before the recent starlark rewrite of the objc rules, it appears that all of the sources (objc or not) were compiled with the `-arch armv7k` arguments applied. After the rewrite, objc still gets compiled this way but C files in the same library get the target triplet from the crosstool, which is incorrect. Then when `libtool` creates the archive, the object files are filtered out because they don't match `-arch_only armv7k`.

If approved, I think this should be cherry-picked into the 5.0 release.

Closes bazelbuild#14367.

PiperOrigin-RevId: 414693641
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants