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

Unable to build grpc-swfit with xcode proj file.

Open yashdesai7 opened this issue 3 years ago • 18 comments

What are you trying to achieve?

Trying to build the GRPC target using xcodeproj file.

What have you tried so far?

  • Checked out repo
  • Generated xcode proj using the swift package generate-xcodeproj
    • first build failed with build failure ofCNIOBoringSSLShims with error Include of non-modular header inside framework module 'CNIOBoringSSL.CNIOBoringSSL_bn': '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/clang/include/inttypes.h'
    • which was fixed by changing build setting Allow non modular includes in Framework modules to YES
  • Build kept failing due to failure in building NIO dependency NIOSSL with error
/Users/yash/Library/Developer/Xcode/DerivedData/grpc-swift-cxhdtopxuzlraycvqlcyfuxicxux/Build/Products/Debug-iphonesimulator/CNIOBoringSSL.framework/Headers/CNIOBoringSSL_bn.h:129:10: error: include of non-modular header inside framework module 'CNIOBoringSSL.CNIOBoringSSL_bn': '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/clang/include/inttypes.h'
#include <inttypes.h>  // for PRIu64 and friends
  • Updating build setting Allow non modular includes in Framework modules to YES does not help here.
  • I am also seeing could not build Objective-C module 'CNIOBoringSSL'
    • I realized we dont have module.modulemap file for CNIOBoringSSL and NIOSSL already has Other Swift Flags build setting with -fmodule-map-file=$(SRCROOT)/.build/checkouts/swift-nio/Sources/CNIOWindows/include/module.modulemap so I updated this module map with custom path for 'CNIOBoringSSL' that helped fixing the could not build Objective-C module but I started getting symbol not found in the scope for below enum although CNIOBoringSSL_ssl.h is part of CNIOBoringSSL.h which is part of my custom module map which looks like
module CNIOWindows {
  header "CNIOWindows.h"
  export *
}

module CNIOBoringSSL {
    header "/Users/yash/Downloads/grpc-swift-main/.build/checkouts/swift-nio-ssl/Sources/CNIOBoringSSL/include/CNIOBoringSSL.h"
    export *
}

module CNIOBoringSSLShims {
    header "/Users/yash/Downloads/grpc-swift-main/.build/checkouts/swift-nio-ssl/Sources/CNIOBoringSSLShims/include/CNIOBoringSSLShims.h"
    export *
}

enum ssl_private_key_result_t BORINGSSL_ENUM_INT {
  ssl_private_key_success,
  ssl_private_key_retry,
  ssl_private_key_failure,
};

yashdesai7 avatar May 18 '22 01:05 yashdesai7

swift package generate-xcodeproj is no longer supported by Swift, so it's highly likely that build failures occur when you do this. Is there any reason you can't simply depend on the Swift package directly?

Lukasa avatar May 18 '22 06:05 Lukasa

Yes. I can not move to SPM yet.

On Tue, May 17, 2022 at 11:40 PM Cory Benfield @.***> wrote:

swift package generate-xcodeproj is no longer supported by Swift, so it's highly likely that build failures occur when you do this. Is there any reason you can't simply depend on the Swift package directly?

— Reply to this email directly, view it on GitHub https://github.com/grpc/grpc-swift/issues/1408#issuecomment-1129629834, or unsubscribe https://github.com/notifications/unsubscribe-auth/AALEVB6P3BHEC2MICYVY7OLVKSGHNANCNFSM5WGWZG4Q . You are receiving this because you authored the thread.Message ID: @.***>

--

Thanks, Yash Desai

yashdesai7 avatar May 18 '22 06:05 yashdesai7

I think the "allow non-modular includes" setting should work so long as you apply it to all targets.

Lukasa avatar May 18 '22 06:05 Lukasa

Interesting. This dose not work for NIOSSL

yashdesai7 avatar May 18 '22 16:05 yashdesai7

@Lukasa would you be able to help here ?

yashdesai7 avatar May 22 '22 22:05 yashdesai7

@yashdesai7 Like @Lukasa said sadly the swift package generate-xcodeproj is no longer officially supported. However, I just tried to reproduce your issue. I checked out the latest commit on main, generated the project and clean build swift-rio-Package and a couple of the executable targets.

For me all of the clean build succeeded on both MacOS and iOS. Do you have a more complex setup by any chance?

FranzBusch avatar May 23 '22 08:05 FranzBusch

@FranzBusch

did you build the grpc-swift-Package or GRPC target from this repo?

I don’t have a complex setup. I just checked out the repo and tried to build but I was building a GRPC target as I will need a GRPC framework. I also tried building grpc-swift-Package, GRPC, with xcodeproj and seeing the same error.

I suspect you build the swift-nio-Package and I believe NIO target builds that with xcodeproj. I tried that and it built fine for me as well.

yashdesai7 avatar May 23 '22 14:05 yashdesai7

@yashdesai7 Sorry I misspoke earlier. I build the GRPC target for both MacOS and iOS successfully. I was also able to build the grpc-swift-Package target for MacOS (This one failed for iOS, but that is intended I think)

So I can sadly not reproduce the build error you are seeing.

Could you provide some more infos:

  • Which commit of gRPC are you trying to build?
  • Which Xcode are you using?
  • Are you doing any changes to the generated Xcode project or have it include in some workspace?

FranzBusch avatar May 23 '22 14:05 FranzBusch

@FranzBusch

  • I am using Version 13.4 (13F17a)
  • I downloaded the zip from https://github.com/grpc/grpc-swift/archive/refs/heads/main.zip
  • Extracted the zip
  • ran swift package generate-xcodeproj
  • I am not making any changes to xcode project
  • I have .xcodeproj in the same directory as rest of the source see tree below within my extracted directory.
❯ tree -d
.
├── Examples
│   ├── EchoWeb
│   │   └── Generated
│   └── Google
│       ├── NaturalLanguage
│       │   └── Sources
│       ├── SpeechToText
│       │   ├── Images
│       │   ├── Sources
│       │   │   ├── Configuration
│       │   │   │   └── Assets.xcassets
│       │   │   │       └── AppIcon.appiconset
│       │   │   └── Launch
│       │   │       └── Base.lproj
│       │   └── SpeechToText-gRPC-iOS.xcodeproj
│       │       └── xcshareddata
│       │           └── xcschemes
│       └── common
│           └── include
│               └── google
│                   └── protobuf
│                       └── compiler
├── FuzzTesting
│   ├── FailCases
│   └── Sources
│       ├── EchoImplementation -> ../../Sources/Examples/Echo/Implementation
│       ├── EchoModel -> ../../Sources/Examples/Echo/Model
│       └── ServerFuzzer
├── Performance
│   ├── QPSBenchmark
│   │   ├── Sources
│   │   │   ├── BenchmarkUtils
│   │   │   └── QPSBenchmark
│   │   │       ├── Model
│   │   │       └── Runtime
│   │   ├── Tests
│   │   │   └── BenchmarkUtilsTests
│   │   └── scenarios
│   └── allocations
│       └── tests
│           └── shared
├── Sources
│   ├── CGRPCZlib
│   │   └── include
│   ├── Examples
│   │   ├── Echo
│   │   │   ├── Implementation
│   │   │   ├── Model
│   │   │   └── Runtime
│   │   ├── HelloWorld
│   │   │   ├── Client
│   │   │   ├── Model
│   │   │   └── Server
│   │   ├── PacketCapture
│   │   └── RouteGuide
│   │       ├── Client
│   │       ├── Model
│   │       └── Server
│   ├── GRPC
│   │   ├── CallHandlers
│   │   ├── ClientCalls
│   │   ├── Compression
│   │   ├── ConnectionPool
│   │   ├── GRPCChannel
│   │   ├── Interceptor
│   │   └── ServerCallContexts
│   ├── GRPCConnectionBackoffInteropTest
│   ├── GRPCInteroperabilityTestModels
│   │   ├── Generated
│   │   └── src
│   │       └── proto
│   │           └── grpc
│   │               └── testing
│   ├── GRPCInteroperabilityTests
│   ├── GRPCInteroperabilityTestsImplementation
│   ├── GRPCPerformanceTests
│   │   └── Benchmarks
│   ├── GRPCSampleData
│   └── protoc-gen-grpc-swift
├── Tests
│   └── GRPCTests
│       ├── Codegen
│       │   └── Normalization
│       ├── ConnectionPool
│       └── EchoHelpers
│           ├── Interceptors
│           └── Providers
├── dev
│   └── codegen-tests
│       ├── 01-echo
│       │   ├── golden
│       │   └── proto
│       ├── 02-multifile
│       │   ├── golden
│       │   └── proto
│       ├── 03-multifile-with-module-map
│       │   ├── golden
│       │   └── proto
│       ├── 04-service-with-message-import
│       │   ├── golden
│       │   └── proto
│       ├── 05-service-only
│       │   ├── golden
│       │   └── proto
│       └── 06-test-client-only
│           ├── golden
│           └── proto
├── docs
├── grpc-swift.xcodeproj
│   ├── project.xcworkspace
│   │   ├── xcshareddata
│   │   │   └── swiftpm
│   │   └── xcuserdata
│   │       └── yashdesa.xcuserdatad
│   ├── xcshareddata
│   │   └── xcschemes
│   └── xcuserdata
│       └── yashdesa.xcuserdatad
│           └── xcschemes
└── scripts

yashdesai7 avatar May 23 '22 14:05 yashdesai7

@yashdesai7 I was finally able to reproduce the build errors.

I dug a bit into the errors and what Xcode is doing here. Sadly, how swift package generate-xcodeproj is generating a project is not compatible any more with what SPM is doing.

Furthermore, it doesn't look like we can easily fix this from the NIO/gRPC side.

Maybe you can explain your restriction around why you can't use SPM right now and how/where you want to integrate gRPC a bit and I might be able to suggest alternative solutions.

FranzBusch avatar May 24 '22 08:05 FranzBusch

Moving to SPM requires larger efforts across teams and I dont think it's going to happen anytime soon.

yashdesai7 avatar May 25 '22 23:05 yashdesai7

@FranzBusch you also mentioned grpc-Lite-swift-Package , I dont see that target. is there a lite version of gRPC swift implementation ?

yashdesai7 avatar May 26 '22 07:05 yashdesai7

@yashdesai7 that was just my brain getting things mixed up. There are some variations of grpc-Lite floating around but nothing in Swift.

I am currently trying to think of different solutions how you could still integrate grpc-swift without relying on the generated project.

How are you using/planning to use the xcproj? Are you just building a framework and then integrate it manually or is the project part of an xcworkspace in the end?

FranzBusch avatar May 26 '22 08:05 FranzBusch

Are you just building a framework and then integrate it manually ?

Yes

is the project part of an xcworkspace in the end?

I explored a cocoapod option as well but , grpc-swift also brings in SwiftProtobuf.framework that's causing build issues as we already integrated SwiftProtobuf.framework directly. But I am open to this as well. If I can work around SwiftProtobuf as well.

yashdesai7 avatar May 26 '22 16:05 yashdesai7

Sadly, I don't think there is much we can do for you here. SPM is the official integration method and using the generated xcproj is deprecated.

The only thing that I would try is to build an xcframework from swift-grpc. This is another unsupported workflow but I have seen people make it work with other packages (Though I am not sure if this is just going to end up in the same errors). However, one important note on the integration of packages as frameworks in general. It is super easy to get duplicated symbols or versions clashes this way.

In the end, I can only recommend you to push the migration to SPM since the ecosystem is moving more and more into that direction.

FranzBusch avatar May 27 '22 10:05 FranzBusch

Interesting, It is not working for NIOSSL

On Tue, May 17, 2022 at 11:49 PM Cory Benfield @.***> wrote:

I think the "allow non-modular includes" setting should work so long as you apply it to all targets.

— Reply to this email directly, view it on GitHub https://github.com/grpc/grpc-swift/issues/1408#issuecomment-1129636031, or unsubscribe https://github.com/notifications/unsubscribe-auth/AALEVB3YP7NEJW3NQO6GAULVKSHIVANCNFSM5WGWZG4Q . You are receiving this because you authored the thread.Message ID: @.***>

--

Thanks, Yash Desai Contact: +1 607 644 5866

yashdesai7 avatar Oct 11 '22 07:10 yashdesai7

Following up on this, it still doesn't work now that Xcode supports building frameworks from packages. Reference here.

I'm trying this: xcodebuild archive -scheme GRPC -destination "generic/platform=iOS" -archivePath "archives/GRPC-iOS" xcodebuild archive -scheme GRPC -destination "generic/platform=iOS Simulator" -archivePath "archives/GRPC-iOS_Simulator"

xcodebuild -create-xcframework -archive archives/GRPC-iOS.xcarchive -framework GRPC.framework -archive archives/GRPC-iOS_Simulator.xcarchive -framework GRPC.framework -output xcframeworks/GRPC.xcframework

cassianomonteiro avatar Apr 17 '23 14:04 cassianomonteiro

Also related to the issue https://github.com/grpc/grpc-swift/issues/1405 : the workaround script no longer works. And the issue https://github.com/grpc/grpc-swift/issues/1391: It's not possible to use BUILD_LIBRARY_FOR_DISTRIBUTION. Also related to:

  • https://github.com/apple/swift-protobuf/issues/1101
  • https://github.com/apple/swift-protobuf/issues/1157

cassianomonteiro avatar Apr 17 '23 15:04 cassianomonteiro