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

Generate framework with grpc-swift fails #1391

Closed
daniellfalcao opened this issue Apr 21, 2022 · 8 comments
Closed

Generate framework with grpc-swift fails #1391

daniellfalcao opened this issue Apr 21, 2022 · 8 comments
Labels

Comments

@daniellfalcao
Copy link

What are you trying to achieve?

I'm trying to create a lib to make some GRPC calls and distribute the implementation creating a XCFramework (I really need a XCFramework, pod or spm will not work for my case) but xcodebuild archive fails every time when I try to create the framework.

OBS:My project it's a pod library that I want to create a XCFramework from it.

What have you tried so far?

I already have tried to create a pod and spm project and use the lib in an iOS POC project and works, but as I said early I need to consume the lib using a framework, but when a tried to create the framework running this script:

#!/bin/bash

CURRENT_PATH="$(pwd)"
SCHEME=GRPCInteractor
ARCHIVE_PATH_IOS="${CURRENT_PATH}/archives/${SCHEME}-iOS"
ARCHIVE_PATH_IOS_SIMULATOR="${CURRENT_PATH}/archives/${SCHEME}-iOS-simulator"
FINAL_NAME=GRPCInteractor

rm -rf ${CURRENT_PATH}/archives

# iOS devices
xcodebuild archive \
    -scheme ${SCHEME} \
    -archivePath "${ARCHIVE_PATH_IOS}.xcarchive" \
    -destination "generic/platform=iOS" \
    -sdk iphoneos \
    SKIP_INSTALL=NO \
    BUILD_LIBRARY_FOR_DISTRIBUTION=YES

# iOS simulators
xcodebuild archive \
    -scheme ${SCHEME} \
    -archivePath "${ARCHIVE_PATH_IOS_SIMULATOR}.xcarchive" \
    -destination "generic/platform=iOS Simulator" \
    -sdk iphonesimulator \
    SKIP_INSTALL=NO \
    BUILD_LIBRARY_FOR_DISTRIBUTION=YES

xcodebuild -create-xcframework \
    -framework "${ARCHIVE_PATH_IOS}.xcarchive/Products/Library/Frameworks/${FINAL_NAME}.framework" \
    -framework "${ARCHIVE_PATH_IOS_SIMULATOR}.xcarchive/Products/Library/Frameworks/${FINAL_NAME}.framework" \
    -output "${FINAL_NAME}.xcframework"

archive fails with the message:

...
/Users/danielfalcao/Desktop/GRPCInteractor-pod/GRPCInteractor/test.pb.swift:11:8: error: no such module 'SwiftProtobuf'
import SwiftProtobuf
       ^
...       

The following build commands failed:
        CompileSwift normal x86_64 /Users/danielfalcao/Desktop/GRPCInteractor-pod/GRPCInteractor/test.pb.swift (in target 'GRPCInteractor' from project 'GRPCInteractor')
        CompileSwift normal x86_64 /Users/danielfalcao/Desktop/GRPCInteractor-pod/GRPCInteractor/test.grpc.swift (in target 'GRPCInteractor' from project 'GRPCInteractor')
        EmitSwiftModule normal x86_64 (in target 'GRPCInteractor' from project 'GRPCInteractor')
        CompileSwiftSources normal x86_64 com.apple.xcode.tools.swift.compiler (in target 'GRPCInteractor' from project 'GRPCInteractor')
        CompileSwiftSources normal arm64 com.apple.xcode.tools.swift.compiler (in target 'GRPCInteractor' from project 'GRPCInteractor')
        EmitSwiftModule normal arm64 (in target 'GRPCInteractor' from project 'GRPCInteractor')
        CompileSwift normal arm64 /Users/danielfalcao/Desktop/GRPCInteractor-pod/GRPCInteractor/test.grpc.swift (in target 'GRPCInteractor' from project 'GRPCInteractor')
        CompileSwift normal arm64 /Users/danielfalcao/Desktop/GRPCInteractor-pod/GRPCInteractor/test.pb.swift (in target 'GRPCInteractor' from project 'GRPCInteractor')
        CompileSwift normal arm64 /Users/danielfalcao/Desktop/GRPCInteractor-pod/GRPCInteractor/GRPCinteractor.swift (in target 'GRPCInteractor' from project 'GRPCInteractor')
(9 failures)

I have this project in my public GitHub link, to configure the project just clone and run pod install and run the script build_framework.sh.

I don't know what else I need to do to create the framework 😩, I'm using gRPC-swift 1.7.3.

@glbrntt
Copy link
Collaborator

glbrntt commented Apr 21, 2022

/Users/danielfalcao/Desktop/GRPCInteractor-pod/GRPCInteractor/test.pb.swift:11:8: error: no such module 'SwiftProtobuf'
import SwiftProtobuf

It looks like you're missing a dependency on SwiftProtobuf in your Podfile, can you try adding it?

@daniellfalcao
Copy link
Author

@glbrntt hello, this is my pod file:

# Uncomment the next line to define a global platform for your project
platform :ios, '15.0'

target 'GRPCInteractor' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!

  # Pods for GRPCInteractor
  pod 'gRPC-Swift', '~> 1.7.3'

end

gRPC-Swift already have a dependency to SwiftProtobuf, do I need add this dependency to my podfile too?

@glbrntt
Copy link
Collaborator

glbrntt commented Apr 22, 2022

I'm surprised it isn't pulled in as a transitive dependency so I think it's worth adding it to your podfile to try.

@daniellfalcao
Copy link
Author

I got the same error 😥

@glbrntt
Copy link
Collaborator

glbrntt commented Apr 27, 2022

I had a quick look at this, you need to specify -workspace GRPCInteractor.xcworkspace when invoking xcodebuild in your build_xcframework.sh script.

This gets us past the error: no such module 'SwiftProtobuf' error but leads to a bunch of different errors.

The first we see are:

/Users/georgebarnett/workspace/tmp/grpc-interactor-pod/Pods/_NIODataStructures/Sources/_NIODataStructures/Heap.swift:27:22: error: 'self' used before 'self.init' call or assignment to 'self'
        self.storage = []
                     ^
/Users/georgebarnett/workspace/tmp/grpc-interactor-pod/Pods/_NIODataStructures/Sources/_NIODataStructures/Heap.swift:28:5: error: 'self.init' isn't called on all paths before returning from initializer
    }
    ^
/Users/georgebarnett/workspace/tmp/grpc-interactor-pod/Pods/_NIODataStructures/Sources/_NIODataStructures/Heap.swift:219:20: error: 'self' used before 'self.init' call or assignment to 'self'
        self._heap = heap
                   ^
/Users/georgebarnett/workspace/tmp/grpc-interactor-pod/Pods/_NIODataStructures/Sources/_NIODataStructures/Heap.swift:220:5: error: 'self.init' isn't called on all paths before returning from initializer
    }
    ^

These errors don't seem at all right to me: the code in question here and here is totally valid.

I would hazard a guess that @inlinable is causing problems here (it shouldn't though) but this will require more investigation.

@Lukasa
Copy link
Collaborator

Lukasa commented Apr 27, 2022

Yes I think this is about the fact that BUILD_LIBRARY_FOR_DISTRIBUTION is not supported by these projects.

@daniellfalcao
Copy link
Author

daniellfalcao commented Apr 30, 2022

Could be something related to issue or issue?

@glbrntt
Copy link
Collaborator

glbrntt commented May 3, 2022

Could be something related to issue or issue?

Yes, but there are multiple dependencies here which do not support BUILD_LIBRARY_FOR_DISTRIBUTION. SwiftProtobuf is only one of them and they must all support BUILD_LIBRARY_FOR_DISTRIBUTION for this issue to be resolved.

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

No branches or pull requests

3 participants