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

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

Open
yashdesai7 opened this issue May 18, 2022 · 18 comments
Open

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

yashdesai7 opened this issue May 18, 2022 · 18 comments
Labels
kind/support Adopter support requests.

Comments

@yashdesai7
Copy link

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 yashdesai7 added the kind/support Adopter support requests. label May 18, 2022
@yashdesai7 yashdesai7 changed the title Unable to buildgrpc-swfit with xcode proj file. Unable to build grpc-swfit with xcode proj file. May 18, 2022
@Lukasa
Copy link
Collaborator

Lukasa commented May 18, 2022

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
Copy link
Author

yashdesai7 commented May 18, 2022 via email

@Lukasa
Copy link
Collaborator

Lukasa commented May 18, 2022

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

@yashdesai7
Copy link
Author

Interesting. This dose not work for NIOSSL

@yashdesai7
Copy link
Author

@Lukasa would you be able to help here ?

@FranzBusch
Copy link
Collaborator

@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
Copy link
Author

@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
Copy link
Collaborator

FranzBusch commented May 23, 2022

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

@yashdesai7
Copy link
Author

@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

@FranzBusch
Copy link
Collaborator

@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
Copy link
Author

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

@yashdesai7
Copy link
Author

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

@FranzBusch
Copy link
Collaborator

@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
Copy link
Author

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
Copy link
Collaborator

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
Copy link
Author

yashdesai7 commented Oct 11, 2022 via email

@cassianomonteiro
Copy link

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
Copy link

Also related to the issue #1405 : the workaround script no longer works.
And the issue #1391: It's not possible to use BUILD_LIBRARY_FOR_DISTRIBUTION.
Also related to:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/support Adopter support requests.
Projects
None yet
Development

No branches or pull requests

4 participants