Skip to content

Commit

Permalink
[apple] fix issues compiling C in objc_library for watchos/armv7k
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dflems authored and Wyverald committed Dec 7, 2021
1 parent b46de75 commit 24a340a
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ public static CcToolchainConfig.Builder watchos_armv7k() {
.withCompiler("compiler")
.withToolchainIdentifier("watchos_armv7k")
.withHostSystemName("x86_64-apple-ios")
.withTargetSystemName("armv7-apple-watchos")
.withTargetSystemName("armv7k-apple-watchos")
.withTargetLibc("watchos")
.withAbiVersion("local")
.withAbiLibcVersion("local")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6991,7 +6991,7 @@ def _impl(ctx):
actions = _ALL_LINK_ACTIONS,
flag_groups = [
flag_group(
flags = ["-lc++", "-target", "armv7-apple-watchos"],
flags = ["-lc++", "-target", "armv7k-apple-watchos"],
),
],
),
Expand Down
2 changes: 1 addition & 1 deletion tools/osx/crosstool/cc_toolchain_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def _impl(ctx):
elif (ctx.attr.cpu == "ios_armv7"):
target_system_name = "armv7-apple-ios"
elif (ctx.attr.cpu == "watchos_armv7k"):
target_system_name = "armv7-apple-watchos"
target_system_name = "armv7k-apple-watchos"
elif (ctx.attr.cpu == "ios_i386"):
target_system_name = "i386-apple-ios"
elif (ctx.attr.cpu == "watchos_i386"):
Expand Down

0 comments on commit 24a340a

Please sign in to comment.