grpc / grpc-swift

The Swift language implementation of gRPC.
Apache License 2.0
2.01k stars 413 forks source link

Unable to build grpc-swfit with xcode proj file. #1408

Open yashdesai7 opened 2 years ago

yashdesai7 commented 2 years ago

What are you trying to achieve?

Trying to build the GRPC target using xcodeproj file.

What have you tried so far?

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, };

Lukasa commented 2 years ago

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?

yashdesai7 commented 2 years ago

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

Lukasa commented 2 years ago

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

yashdesai7 commented 2 years ago

Interesting. This dose not work for NIOSSL

yashdesai7 commented 2 years ago

@Lukasa would you be able to help here ?

FranzBusch commented 2 years ago

@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?

yashdesai7 commented 2 years ago

@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.

FranzBusch commented 2 years ago

@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:

yashdesai7 commented 2 years ago

@FranzBusch

❯ 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
FranzBusch commented 2 years ago

@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.

yashdesai7 commented 2 years ago

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

yashdesai7 commented 2 years ago

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

FranzBusch commented 2 years ago

@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?

yashdesai7 commented 2 years ago

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.

FranzBusch commented 2 years ago

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.

yashdesai7 commented 1 year ago

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

cassianomonteiro commented 1 year ago

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 commented 1 year ago

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: