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

Manual integration - does not work for iOS #218

Closed
JCzz opened this issue Apr 23, 2018 · 16 comments
Closed

Manual integration - does not work for iOS #218

JCzz opened this issue Apr 23, 2018 · 16 comments

Comments

@JCzz
Copy link

JCzz commented Apr 23, 2018

Hi

I have tried for some days to get this working on iOS - but maybe is is not surpose to work for iOS for now and only for MacOs?

Is that correct?

Note: I have followed the Manual integration hoping it would work for iOS.

Thanks in advance

@MrMage
Copy link
Collaborator

MrMage commented Apr 24, 2018

I haven’t tested this myself on iOS, but I think it should work. What problems are you encountering?

@JCzz
Copy link
Author

JCzz commented Apr 24, 2018

Hi @MrMage

My Setup is:

MacOs 10.13.4
Xcode 9.3

Getting error: No such module 'ProtocolBuffers'
The specific steps I have done:
Install swift-protobuf

  1. brew install swift-protobuf

Building grpc-swift

  1. git clone https://github.com/grpc/grpc-swift.git
  2. cd grpc-swift
  3. make
  4. cd third_party
    5 sh RUNME.sh
  5. cd ../..
    I had an issue with SwiftGRPC.xcodeproj not showing up in grpc-swift - make did not create the project. Then I did manually:
  6. swift package generate-xcodeproj

protoc-gen-swift & protoc-gen-swiftgrpc
Plugins need to be in the path.
pwd is root of grpc-swift
8. export PATH=$PATH:$(pwd)

Generate Swift files from .proto
Form this: https://github.com/grpc/grpc/blob/master/examples/protos/helloworld.proto
1.protoc helloworld.proto --swift_out=. --swiftgrpc_out=.

Create a new Swift App in Xcode

  1. Create Swift iOS app
    After building your project, add the generated SwiftGRPC.xcodeproj to your project, and add build dependencies on BoringSSL, CgRPC, and SwiftGRPC.
  2. I added to my target in my project: Build Phases / Target Dependencies
  • BoringSSL
  • CgRPC
  • SwiftGRPC
  1. Please also note that your project will need to include the SwiftProtobuf.xcodeproj from Swift Protobuf and the source files that you generate with protoc/plugins.

This gives me the following error in the genereted proto.swift file:
No such module 'ProtocolBuffers'

I tried to add Build Phases / Target Dependencies to SwiftProtobuf_iOS still the same error.

@MrMage
Copy link
Collaborator

MrMage commented Apr 24, 2018

Weird, I can't find any reference to the string ProtocolBuffers in my project. Could you try searching for it and see where exactly it is used?

@JCzz
Copy link
Author

JCzz commented Apr 24, 2018

It is the:
protoc --swiftgrpc_out=. --swift_out=. helloworld.proto
that generates the import ProtocolBuffers and it is in the .proto.swiftfile.

I include the two generated file into my project.

@MrMage
Copy link
Collaborator

MrMage commented Apr 24, 2018

Is it possible that the version of the swift protobuf compiler plugin installed via brew is completely outdated?

@JCzz
Copy link
Author

JCzz commented Apr 24, 2018

Good suggestion - I will try to uninstall and use only the one from the grpc-swift project third_party

@MrMage I just did:

  1. brew uninstall swift-protobuf
  2. Started a new terminal.
  3. cd into: grpc-swift
  4. protoc --swiftgrpc_out=. --swift_out=. helloworld.proto
  5. copied the two file into my project

Same error

I dont think it is the protoc generating the files that is the problem. It looks more like including the SwiftProtobuf.xcodeproj issue.

@MrMage
Copy link
Collaborator

MrMage commented Apr 24, 2018 via email

@JCzz
Copy link
Author

JCzz commented Apr 24, 2018

@MrMage Do you know anyone how have this running on iOS?

Thanks for trying

@basalphenaar
Copy link

I've been able to get it running successfully in my iOS project using these instructions: https://github.com/KyoheiG3/gRPCExample

It's cumbersome, and it requires you to do this every time when a new Swift gRPC update is out, but it works. I'm keeping my fingers crossed for Carthage support in the future to make the update process easier.

@JCzz
Copy link
Author

JCzz commented Apr 30, 2018

Hi @basalphenaar

That is cool, thanks for sharing!

@timburks
Copy link
Member

timburks commented May 1, 2018

@JCzz I don't know if using Cocoapods is an option for you, but if it is, I just merged a very simple iOS sample that uses Cocoapods and calls a Google Cloud API.

@MrMage MrMage mentioned this issue May 2, 2018
36 tasks
@DroidFxGit
Copy link

DroidFxGit commented May 9, 2018

Hi @basalphenaar I checked your iOS example was very helpful and it runs well, but I haven't found a way to run the command to translate .proto files into its .swift classes. Previously I have installed swift_protobuf homebrew library and I could convert messages from .proto into swift classes but i was not able to convert services. As I've checked you have to use something like: "protoc protofile.proto --swiftgrpc_out=." I don't know if somebody else has had this issue in their iOS projects

@DroidFxGit
Copy link

if someone had troubles with protoc-gen-swift protoc-gen-swiftgrpc integration this tutorial was very useful for me :) https://qiita.com/tikidunpon/items/9759dc6e65da09986c1f

@JonasVautherin
Copy link
Contributor

I have been spending quite some time integrating grpc-swift to iOS, and I believe it is worth adding some insights here.

Cocoapods

I have been using Cocoapods with iOS and it works, to confirm @timburks' comment above.

Carthage

If you want to get the frameworks, you can now use Carthage, that is now supported on master. So you can build the iOS frameworks by following these instructions:

  1. In a new directory, create a file called Cartfile with the following content:

    github "grpc/grpc-swift" "master"
    
  2. From this directory, run $ carthage update --platform ios

The frameworks should get built into Carthage/Build/iOS/ next to your Cartfile.

Manual

I have also been building grpc-swift manually for iOS, with [the following script](https://github.com/Dronecode/DronecodeSDK-Swift/blob/master/Source/build_grpc.bash) (copied for the record, feel free to adapt it to your needs):

#!/bin/bash

set -e

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

source ${SCRIPT_DIR}/init_variables.bash

if [ ! -d ${BUILD_DIR}/grpc-swift ]; then
    git -C ${BUILD_DIR} clone -b 0.4.2 https://github.com/grpc/grpc-swift.git
fi

cd ${BUILD_DIR}/grpc-swift
make && make project

xcodebuild -target BoringSSL -target SwiftGRPC -target SwiftProtobuf -target CgRPC -configuration Release -sdk iphoneos IPHONEOS_DEPLOYMENT_TARGET=9.0 CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO CODE_SIGNING_ALLOWED=NO
xcodebuild -target BoringSSL -target SwiftGRPC -target SwiftProtobuf -target CgRPC -configuration Release -sdk iphonesimulator IPHONEOS_DEPLOYMENT_TARGET=9.0 CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO CODE_SIGNING_ALLOWED=NO

# Generate fat binaries
for TARGET_NAME in BoringSSL SwiftGRPC SwiftProtobuf CgRPC; do
    echo "Generating fat binary for ${TARGET_NAME}"
    cp -r ${BUILD_DIR}/grpc-swift/build/Release-iphoneos/${TARGET_NAME}.framework ${BIN_DIR}

    lipo ${BUILD_DIR}/grpc-swift/build/Release-iphoneos/${TARGET_NAME}.framework/${TARGET_NAME} ${BUILD_DIR}/grpc-swift/build/Release-iphonesimulator/${TARGET_NAME}.framework/${TARGET_NAME} -create -output ${BIN_DIR}/${TARGET_NAME}.framework/${TARGET_NAME}

    if [ -d ${BUILD_DIR}/grpc-swift/build/Release-iphonesimulator/${TARGET_NAME}.framework/Modules/${TARGET_NAME}.swiftmodule ]; then
        cp ${BUILD_DIR}/grpc-swift/build/Release-iphonesimulator/${TARGET_NAME}.framework/Modules/${TARGET_NAME}.swiftmodule/* ${BIN_DIR}/${TARGET_NAME}.framework/Modules/${TARGET_NAME}.swiftmodule/
    fi
done

mkdir -p ${BIN_DIR}/CgRPC.framework/Modules
cat >${BIN_DIR}/CgRPC.framework/Modules/module.modulemap <<EOL
framework module CgRPC {
    header "cgrpc.h"
    export *
}
EOL

mkdir -p ${BIN_DIR}/CgRPC.framework/Headers
cp ${BUILD_DIR}/grpc-swift/Sources/CgRPC/include/cgrpc.h ${BIN_DIR}/CgRPC.framework/Headers/cgrpc.h

Note the last two paragraphs where I edit the CgRPC target. I don't think I was doing it the right way (even though it was working), but I think that the solution proposed in #44 was better, which is why I implemented it here.

@basalphenaar
Copy link

@JonasVautherin Thank you so much for adding Carthage support, manually updating grpc-swift every time was becoming quite a nuisance! This is going to save me a lot of time.

@MrMage
Copy link
Collaborator

MrMage commented Aug 22, 2018

Closing this for now, as @JonasVautherin's instructions have hopefully resolved the issue.

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

No branches or pull requests

6 participants