grpc-swift icon indicating copy to clipboard operation
grpc-swift copied to clipboard

Rebuild from Bitcode fails on watchOS

Open daltonclaybrook opened this issue 5 years ago • 11 comments

Describe the bug

Xcode version: 12.0.1 (12A7300) grpc-swift version: 1.0.0-alpha.20

When linking a watchOS app with grpc-swift, the app compiles and runs successfully. But attempting to distribute the app and rebuild from Bitcode (required for App Store release) results in a failure:

ipatool failed with an exception: #<CmdSpec::NonZeroExitException

(more output in attached log below)

To reproduce

  1. Create a new watchOS project in Xcode. This can be a standalone Watch app or iOS companion. It doesn't matter.
  2. Add grpc-swift as a dependency of the Watch extension with File -> Swift Packages -> Add Package Dependency... Important: When selecting the "GRPC" library, you will need to change the target on the righthand side from the iOS app to the WatchKit extension. The Watch extension is not selected by default.
  3. Archive the app with Product -> Archive
  4. After the archive is finished, the Xcode Organizer window will appear. Select "Distribute App"
  5. Select "Ad Hoc" as the method of distribution
  6. Important: On the next screen, make sure "Rebuild from Bitcode" is checked. The other fields don't matter. Select "Next"
  7. Proceed through the next screen until the app starts rebuilding from Bitcode.
  8. Observe the error

Expected behavior

Xcode should be able to rebuild the app successfully from Bitcode, and you should be able to export the Ad Hoc IPA file afterward.

Actional behavior

The Rebuild from Xcode step fails and the IPA file cannot be exported. I've attached the build log file that contains additional output from the build tool.

bitcode.log

daltonclaybrook avatar Oct 16 '20 00:10 daltonclaybrook

As a test, I excluded the armv7k architecture from the build and am still seeing the same error, but now referencing the arm64_32 slice.

daltonclaybrook avatar Oct 16 '20 01:10 daltonclaybrook

I cannot reproduce this locally: I am able to package grpc-swift for watchOS with "Rebuild from bitcode" enabled. I recommend filing a feedback request with Apple using feedbackassistant.apple.com, as this sounds like it may be an Xcode issue. Please leave the feedback number here if you do so.

Lukasa avatar Oct 16 '20 09:10 Lukasa

Do you mind sharing what version of Xcode you used for your test? I have tried on Xcode 11.6, 12.0.1, and 12.1 GM, and each one fails. Here is my test project where the failure occurs. Would you be willing to try again with this project? Thank you for your patience with this. BitcodeTest.zip

FYI, I updated the report above to include additional details in step 2 that are easy to miss, namely:

When selecting the "GRPC" library, you will need to change the target on the righthand side from the iOS app to the WatchKit extension. The Watch extension is not selected by default.

daltonclaybrook avatar Oct 16 '20 13:10 daltonclaybrook

I have created a new project following the steps above, but linking a different Swift package (Alamofire), and this issue does not occur on the new project. Here it is in case you are interested: AlamofireBitcode.zip

daltonclaybrook avatar Oct 16 '20 13:10 daltonclaybrook

I was using 12.1 GM.

Can you provide full details of your configuration? macOS version (including build number) and Xcode version (including build number)? I'll try to put together that environment and see if I can reproduce it. I recommend filing an issue with Feedback Assistant anyway, as my success indicates that the issue isn't with Xcode per se.

Lukasa avatar Oct 16 '20 14:10 Lukasa

macOS 10.15.7 (19H2) Xcode 12.1 GM (12A7403) (or Xcode 12.0.1 (12A7300))

I'm happy to provide any other details you need. I will also file the feedback report very soon and reply with the issue number. One other important detail I can share: I started to discover this issue when I uploaded a build to App Store Connect. The upload succeeded, but a few minutes later, I received an email from Apple with this message:

ITMS-90562: Invalid Bundle - Bitcode failed to compile for your watchOS binary because it includes assembly source code or inline assembly. To resolve this issue, rewrite the corresponding code in a higher-level language such as Objective-C or Swift and redeliver your app.

daltonclaybrook avatar Oct 16 '20 15:10 daltonclaybrook

I have created the feedback report with Apple and the number is FB8806154. As a test, I followed these repro steps again, but this time using just the Swift NIO package instead of grpc-swift, and the app was able to rebuild from Bitcode without error. This strengthens my suspicion that this is an issue with grpc-swift and not with Xcode. I will attempt to reproduce this on another computer today, and I've asked a few colleagues to try to reproduce as well. I will comment again when I have more information. As you might have inferred, this issue is hugely important for myself and my organization as we are not able to distribute through the App Store without a fix.

daltonclaybrook avatar Oct 16 '20 18:10 daltonclaybrook

It may be worth trying with swift-nio-ssl. This is an unusual project in that it contains assembly files, which may be relevant.

Lukasa avatar Oct 16 '20 18:10 Lukasa

@Lukasa Just tried and swift-nio-ssl fails in the same way! Thanks for the great tip! I will try each of the other dependencies of grpc-swift and create issues on relevant repos. Thanks!

daltonclaybrook avatar Oct 16 '20 18:10 daltonclaybrook

This will likely be just a watchOS problem. It seems that watchOS won’t allow submitting direct assembly code, so we probably just need to update that repo to remove the assembly on watchOS.

Lukasa avatar Oct 16 '20 18:10 Lukasa

Note that the Swift-NIO-SSL issue itself depends on a Swift issue: https://bugs.swift.org/browse/SR-14109

If this is impacting you, you may want to consider voting for the bug on the Swift board.

dweekly avatar Nov 19 '21 19:11 dweekly