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

iOS bitcode compilation error (via Carthage) #377

Closed
3 tasks done
dekpient opened this issue Feb 24, 2019 · 11 comments
Closed
3 tasks done

iOS bitcode compilation error (via Carthage) #377

dekpient opened this issue Feb 24, 2019 · 11 comments
Labels
version/cgrpc Relates to the CgRPC based version of gRPC Swift

Comments

@dekpient
Copy link

New Issue Checklist

Issue Description

Bitcode compilation error when exporting an iOS app that depends on Swift gPRC via Carthage (with default build config).

The issue seems to be around LD_RUNPATH_SEARCH_PATHS = "$(inherited) $(TOOLCHAIN_DIR)/usr/lib/swift/macosx"; for SwiftProtobuf. Overriding the build config when running Carthage with LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks" works around this issue, but it still sounds like bug to me – unless overriding build config is expected? Is there any documentation around this?

2019-02-23 11:28:02 +0000  /Applications/Xcode.app/Contents/Developer/usr/bin/bitcode-build-tool -v -t /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin --sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.1.sdk -o /var/folders/_0/d90qm2td1y93yvsvzfsb09hm0000gn/T/ipatool20190224-28707-142wm8i/thinned-out/armv7/Payload/mobile.app/Frameworks/SwiftProtobuf.framework/SwiftProtobuf --generate-dsym /var/folders/_0/d90qm2td1y93yvsvzfsb09hm0000gn/T/ipatool20190224-28707-142wm8i/thinned-out/armv7/Payload/mobile.app/Frameworks/SwiftProtobuf.framework/SwiftProtobuf.dSYM --strip-swift-symbols /var/folders/_0/d90qm2td1y93yvsvzfsb09hm0000gn/T/ipatool20190224-28707-142wm8i/thinned-in/armv7/Payload/mobile.app/Frameworks/SwiftProtobuf.framework/SwiftProtobuf
2019-02-23 11:28:02 +0000      Compiling armv7 bitcode in 'SwiftProtobuf'
2019-02-23 11:28:12 +0000      Command exited with pid 33420 exit 1:
    /Applications/Xcode.app/Contents/Developer/usr/bin/bitcode-build-tool -v -t /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin --sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.1.sdk -o /var/folders/_0/d90qm2td1y93yvsvzfsb09hm0000gn/T/ipatool20190224-28707-142wm8i/thinned-out/armv7/Payload/mobile.app/Frameworks/SwiftProtobuf.framework/SwiftProtobuf --generate-dsym /var/folders/_0/d90qm2td1y93yvsvzfsb09hm0000gn/T/ipatool20190224-28707-142wm8i/thinned-out/armv7/Payload/mobile.app/Frameworks/SwiftProtobuf.framework/SwiftProtobuf.dSYM --strip-swift-symbols /var/folders/_0/d90qm2td1y93yvsvzfsb09hm0000gn/T/ipatool20190224-28707-142wm8i/thinned-in/armv7/Payload/mobile.app/Frameworks/SwiftProtobuf.framework/SwiftProtobuf
    Stdout:
        Debug: SDK path: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.1.sdk
        Debug: PATH: ['/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin', '/Applications/Xcode.app/Contents/Developer/usr/bin']
        Debug: Using: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo
        MachoInfo: cd /
        "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo" "-info" "/var/folders/_0/d90qm2td1y93yvsvzfsb09hm0000gn/T/ipatool20190224-28707-142wm8i/thinned-in/armv7/Payload/mobile.app/Frameworks/SwiftProtobuf.framework/SwiftProtobuf"
        -= Output =-
        Non-fat file: /var/folders/_0/d90qm2td1y93yvsvzfsb09hm0000gn/T/ipatool20190224-28707-142wm8i/thinned-in/armv7/Payload/mobile.app/Frameworks/SwiftProtobuf.framework/SwiftProtobuf is architecture: armv7
        Exited with 0
        
        Debug: Command took 0 seconds
        Debug: Using: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/dwarfdump
        GetUUID: cd /
        "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/dwarfdump" "-u" "/var/folders/_0/d90qm2td1y93yvsvzfsb09hm0000gn/T/ipatool20190224-28707-142wm8i/thinned-in/armv7/Payload/mobile.app/Frameworks/SwiftProtobuf.framework/SwiftProtobuf"
        -= Output =-
        UUID: 82F159BC-DCFD-3C35-9003-6B919CE4D577 (armv7) /var/folders/_0/d90qm2td1y93yvsvzfsb09hm0000gn/T/ipatool20190224-28707-142wm8i/thinned-in/armv7/Payload/mobile.app/Frameworks/SwiftProtobuf.framework/SwiftProtobuf
        Exited with 0

//--- omitted similar logs

        Debug: Command took 0 seconds
        Swift: cd /var/folders/_0/d90qm2td1y93yvsvzfsb09hm0000gn/T/tempjDnbvh
        "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc" "-frontend" "-emit-object" "-target" "armv7-apple-ios9.0" "-O" "-
2019-02-23 11:28:12 +0000  disable-llvm-optzns" "-module-name" "SwiftProtobuf" "77.bc" "-o" "77.o"
        -= Output =-
        <unknown>:0: warning: using sysroot for 'MacOSX' but targeting 'iPhone'
        Exited with 0
        
        Debug: Command took 0 seconds
        Debug: Found framework/dylib: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.1.sdk/System/Library/Frameworks/Foundation.framework/Foundation.tbd
        Debug: Found framework/dylib: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.1.sdk/usr/lib/libobjc.A.tbd
        Debug: Found framework/dylib: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.1.sdk/usr/lib/libSystem.B.tbd
        Debug: Found framework/dylib: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.1.sdk/usr/lib/libobjc.A.tbd
        Debug: Using: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
        Debug: Search Path: "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/10.0.0/lib/darwin", "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.1.sdk/usr/lib", "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.1.sdk/System/Library/Frameworks"
        error: libswiftCore.dylib not found in dylib search path
        
    
    Stderr:
    
2019-02-23 11:28:12 +0000  /Applications/Xcode.app/Contents/Developer/usr/bin/ipatool:248:in `run'
2019-02-23 11:28:12 +0000  : Command exited with pid 33420 exit 1: (CmdSpec::NonZeroExcitException)
/Applications/Xcode.app/Contents/Developer/usr/bin/bitcode-build-tool -v -t /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin --sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.1.sdk -o /var/folders/_0/d90qm2td1y93yvsvzfsb09hm0000gn/T/ipatool20190224-28707-142wm8i/thinned-out/armv7/Payload/mobile.app/Frameworks/SwiftProtobuf.framework/SwiftProtobuf --generate-dsym /var/folders/_0/d90qm2td1y93yvsvzfsb09hm0000gn/T/ipatool20190224-28707-142wm8i/thinned-out/armv7/Payload/mobile.app/Frameworks/SwiftProtobuf.framework/SwiftProtobuf.dSYM --strip-swift-symbols /var/folders/_0/d90qm2td1y93yvsvzfsb09hm0000gn/T/ipatool20190224-28707-142wm8i/thinned-in/armv7/Payload/mobile.app/Frameworks/SwiftProtobuf.framework/SwiftProtobuf
Complete output when running grpc-swift, including the stack trace and command used

N/A

Environment

Key Value
OS Version 10.14.3
Swift Version 4.2.1
Xcode Version 10.1
gRPC-Swift Version master (ac1939e)
gRPC-Swift Version x.x.x
protoc Version x.x.x
protoc-gen-swift Version x.x.x
protoc-gen-swiftgrpc Version x.x.x
@MrMage
Copy link
Collaborator

MrMage commented Feb 25, 2019

@JonasVautherin @byuarus have you guys seen this before?

@JonasVautherin
Copy link
Contributor

Haven't, but I disable bitcode on my end.

@dekpient: does it only happen with Carthage?
@MrMage: do you compile with bitcode enabled on your side (using SwiftPM or CocoaPods)?

@MrMage
Copy link
Collaborator

MrMage commented Feb 25, 2019

@JonasVautherin I'm using CocoaPods, and I'm only compiling for macOS (i.e. without Bitcode).

@dekpient
Copy link
Author

dekpient commented Feb 25, 2019 via email

@JonasVautherin
Copy link
Contributor

@JonasVautherin I'm using CocoaPods, and I'm only compiling for macOS (i.e. without Bitcode).

Oh right, that probably means that SwiftPM doesn't enable bitcode when generating the xcodeproj, since SwiftPM doesn't know about iOS 😅.

Should we add that in one of the patch scripts, e.g. fix-project-settings, because it already sets the iPhoneOS target?

@dekpient: would enabling bitcode fix your LD_RUNPATH_SEARCH_PATHS issue, in your opinion?

@dekpient
Copy link
Author

dekpient commented Feb 26, 2019

@JonasVautherin I believe bitcode is already enabled by default. I could see -fembed-bitcode (clang) and -embed-bitcode (swift) in my Carthage build log. I think the reason that it fails on an archived iOS app is because all the Swift standard libraries are copied to <where_app_executable_is>/Frameworks and the bitcode recompilation needs to link against those copied libraries.

Still, setting LD_RUNPATH_SEARCH_PATHS = "$(inherited) $(TOOLCHAIN_DIR)/usr/lib/swift/macosx"; for every target platform is kinda weird. Would something like this make more sense? https://github.com/mrackwitz/xcconfigs/blob/master/UniversalFramework_Base.xcconfig#L18-L25. I don't much about how SwiftPM generates the project though.

By the way, master is failing for Carthage since this commit. Could you guys run project-carthage again please? So it knows about ChannelConnectivityState.swift.

@JonasVautherin
Copy link
Contributor

By the way, master is failing for Carthage since this commit. Could you guys run project-carthage again please? So it knows about ChannelConnectivityState.swift.

Yes that's an issue coming from the fact that the xcodeproj needs to be versioned. We don't want to update the xcodeproj for each commit, so the tradeoff is to generate it for each release. Meaning that Carthage only works with release tags (the rest is "undefined behavior").

Still, setting LD_RUNPATH_SEARCH_PATHS = "$(inherited) $(TOOLCHAIN_DIR)/usr/lib/swift/macosx"; for every target platform is kinda weird.

I'd like to understand the root cause of this problem. Does SwiftPM set LD_RUNPATH_SEARCH_PATHS in a different way than Carthage, or are we missing something different in the xcodeproj?

@rebello95
Copy link
Collaborator

Yes that's an issue coming from the fact that the xcodeproj needs to be versioned. We don't want to update the xcodeproj for each commit, so the tradeoff is to generate it for each release. Meaning that Carthage only works with release tags (the rest is "undefined behavior").

FYI, I'm updating the README to include instructions on updating the Carthage project with each release: #383

@dekpient
Copy link
Author

dekpient commented Mar 1, 2019

Ahh, so SwiftPM only supports macOS at the moment.

I came across this Overture issue while researching this problem. Looks like they have switched to XcodeGen to generate their project – see PR#32. Their project.yml looks simple enough. It might worth a try.

@JonasVautherin
Copy link
Contributor

I started trying that here, but without success. I had issues with CgRPC. But I am using XcodeGen in my project and that's working fine! @dekpient: feel free to give it a try!

@glbrntt glbrntt added the version/cgrpc Relates to the CgRPC based version of gRPC Swift label Feb 7, 2020
@MrMage
Copy link
Collaborator

MrMage commented Mar 19, 2020

The CgRPC implementation is now officially deprecated; closing this for now.

@MrMage MrMage closed this as completed Mar 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
version/cgrpc Relates to the CgRPC based version of gRPC Swift
Projects
None yet
Development

No branches or pull requests

5 participants