Skip to content

Commit 45bb7f3

Browse files
committed
Use the deployed protoc spec in samples and README
1 parent eb3ebc5 commit 45bb7f3

File tree

7 files changed

+102
-73
lines changed

7 files changed

+102
-73
lines changed

examples/objective-c/auth_sample/AuthTestService.podspec

+10-6
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@ Pod::Spec.new do |s|
1313
# Base directory where the .proto files are.
1414
src = "../../protos"
1515

16-
# Directory where the generated files will be placed.
17-
dir = "Pods/" + s.name
18-
1916
# Run protoc with the Objective-C and gRPC plugins to generate protocol messages and gRPC clients.
2017
s.dependency "!ProtoCompiler-gRPCPlugin", "~> 0.14"
2118

22-
repo_root = '../../..'
23-
pods_root = "#{repo_root}/examples/objective-c/auth_sample/Pods"
19+
# Pods directory corresponding to this app's Podfile, relative to the location of this podspec.
20+
pods_root = './Pods'
2421

22+
# Path where Cocoapods downloads protoc and the gRPC plugin.
2523
protoc_dir = "#{pods_root}/!ProtoCompiler"
2624
protoc = "#{protoc_dir}/protoc"
27-
2825
plugin = "#{pods_root}/!ProtoCompiler-gRPCPlugin/grpc_objective_c_plugin"
2926

27+
# Directory where the generated files will be placed.
28+
dir = "#{pods_root}/#{s.name}"
29+
3030
s.prepare_command = <<-CMD
3131
mkdir -p #{dir}
3232
#{protoc} \
@@ -38,21 +38,25 @@ Pod::Spec.new do |s|
3838
#{src}/auth_sample.proto
3939
CMD
4040

41+
# Files generated by protoc
4142
s.subspec "Messages" do |ms|
4243
ms.source_files = "#{dir}/*.pbobjc.{h,m}", "#{dir}/**/*.pbobjc.{h,m}"
4344
ms.header_mappings_dir = dir
4445
ms.requires_arc = false
46+
# The generated files depend on the protobuf runtime.
4547
ms.dependency "Protobuf"
4648
# This is needed by all pods that depend on Protobuf:
4749
ms.pod_target_xcconfig = {
4850
'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS=1',
4951
}
5052
end
5153

54+
# Files generated by the gRPC plugin
5255
s.subspec "Services" do |ss|
5356
ss.source_files = "#{dir}/*.pbrpc.{h,m}", "#{dir}/**/*.pbrpc.{h,m}"
5457
ss.header_mappings_dir = dir
5558
ss.requires_arc = true
59+
# The generated files depend on the gRPC runtime, and on the files generated by protoc.
5660
ss.dependency "gRPC-ProtoRPC"
5761
ss.dependency "#{s.name}/Messages"
5862
end

examples/objective-c/auth_sample/Podfile

-6
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,10 @@ platform :ios, '8.0'
33

44
install! 'cocoapods', :deterministic_uuids => false
55

6-
# Location of gRPC's repo root relative to this file.
7-
GRPC_LOCAL_SRC = '../../..'
8-
96
target 'AuthSample' do
107
# Depend on the generated AuthTestService library.
118
pod 'AuthTestService', :path => '.'
129

1310
# Depend on Google's OAuth2 library
1411
pod 'Google/SignIn'
15-
16-
pod '!ProtoCompiler', :podspec => "#{GRPC_LOCAL_SRC}/src/objective-c"
17-
pod '!ProtoCompiler-gRPCPlugin', :podspec => "#{GRPC_LOCAL_SRC}/src/objective-c"
1812
end

examples/objective-c/helloworld/HelloWorld.podspec

+10-6
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@ Pod::Spec.new do |s|
1313
# Base directory where the .proto files are.
1414
src = "../../protos"
1515

16-
# Directory where the generated files will be placed.
17-
dir = "Pods/" + s.name
18-
1916
# Run protoc with the Objective-C and gRPC plugins to generate protocol messages and gRPC clients.
2017
s.dependency "!ProtoCompiler-gRPCPlugin", "~> 0.14"
2118

22-
repo_root = '../../..'
23-
pods_root = "#{repo_root}/examples/objective-c/helloworld/Pods"
19+
# Pods directory corresponding to this app's Podfile, relative to the location of this podspec.
20+
pods_root = './Pods'
2421

22+
# Path where Cocoapods downloads protoc and the gRPC plugin.
2523
protoc_dir = "#{pods_root}/!ProtoCompiler"
2624
protoc = "#{protoc_dir}/protoc"
27-
2825
plugin = "#{pods_root}/!ProtoCompiler-gRPCPlugin/grpc_objective_c_plugin"
2926

27+
# Directory where the generated files will be placed.
28+
dir = "#{pods_root}/#{s.name}"
29+
3030
s.prepare_command = <<-CMD
3131
mkdir -p #{dir}
3232
#{protoc} \
@@ -38,21 +38,25 @@ Pod::Spec.new do |s|
3838
#{src}/helloworld.proto
3939
CMD
4040

41+
# Files generated by protoc
4142
s.subspec "Messages" do |ms|
4243
ms.source_files = "#{dir}/*.pbobjc.{h,m}", "#{dir}/**/*.pbobjc.{h,m}"
4344
ms.header_mappings_dir = dir
4445
ms.requires_arc = false
46+
# The generated files depend on the protobuf runtime.
4547
ms.dependency "Protobuf"
4648
# This is needed by all pods that depend on Protobuf:
4749
ms.pod_target_xcconfig = {
4850
'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS=1',
4951
}
5052
end
5153

54+
# Files generated by the gRPC plugin
5255
s.subspec "Services" do |ss|
5356
ss.source_files = "#{dir}/*.pbrpc.{h,m}", "#{dir}/**/*.pbrpc.{h,m}"
5457
ss.header_mappings_dir = dir
5558
ss.requires_arc = true
59+
# The generated files depend on the gRPC runtime, and on the files generated by protoc.
5660
ss.dependency "gRPC-ProtoRPC"
5761
ss.dependency "#{s.name}/Messages"
5862
end

examples/objective-c/helloworld/Podfile

-6
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,7 @@ platform :ios, '8.0'
33

44
install! 'cocoapods', :deterministic_uuids => false
55

6-
# Location of gRPC's repo root relative to this file.
7-
GRPC_LOCAL_SRC = '../../..'
8-
96
target 'HelloWorld' do
107
# Depend on the generated HelloWorld library.
118
pod 'HelloWorld', :path => '.'
12-
13-
pod '!ProtoCompiler', :podspec => "#{GRPC_LOCAL_SRC}/src/objective-c"
14-
pod '!ProtoCompiler-gRPCPlugin', :podspec => "#{GRPC_LOCAL_SRC}/src/objective-c"
159
end

examples/objective-c/route_guide/Podfile

-6
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,7 @@ platform :ios, '8.0'
33

44
install! 'cocoapods', :deterministic_uuids => false
55

6-
# Location of gRPC's repo root relative to this file.
7-
GRPC_LOCAL_SRC = '../../..'
8-
96
target 'RouteGuideClient' do
107
# Depend on the generated RouteGuide library.
118
pod 'RouteGuide', :path => '.'
12-
13-
pod '!ProtoCompiler', :podspec => "#{GRPC_LOCAL_SRC}/src/objective-c"
14-
pod '!ProtoCompiler-gRPCPlugin', :podspec => "#{GRPC_LOCAL_SRC}/src/objective-c"
159
end

examples/objective-c/route_guide/RouteGuide.podspec

+10-6
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@ Pod::Spec.new do |s|
1313
# Base directory where the .proto files are.
1414
src = "../../protos"
1515

16-
# Directory where the generated files will be placed.
17-
dir = "Pods/" + s.name
18-
1916
# Run protoc with the Objective-C and gRPC plugins to generate protocol messages and gRPC clients.
2017
s.dependency "!ProtoCompiler-gRPCPlugin", "~> 0.14"
2118

22-
repo_root = '../../..'
23-
pods_root = "#{repo_root}/examples/objective-c/route_guide/Pods"
19+
# Pods directory corresponding to this app's Podfile, relative to the location of this podspec.
20+
pods_root = './Pods'
2421

22+
# Path where Cocoapods downloads protoc and the gRPC plugin.
2523
protoc_dir = "#{pods_root}/!ProtoCompiler"
2624
protoc = "#{protoc_dir}/protoc"
27-
2825
plugin = "#{pods_root}/!ProtoCompiler-gRPCPlugin/grpc_objective_c_plugin"
2926

27+
# Directory where the generated files will be placed.
28+
dir = "#{pods_root}/#{s.name}"
29+
3030
s.prepare_command = <<-CMD
3131
mkdir -p #{dir}
3232
#{protoc} \
@@ -38,21 +38,25 @@ Pod::Spec.new do |s|
3838
#{src}/route_guide.proto
3939
CMD
4040

41+
# Files generated by protoc
4142
s.subspec "Messages" do |ms|
4243
ms.source_files = "#{dir}/*.pbobjc.{h,m}", "#{dir}/**/*.pbobjc.{h,m}"
4344
ms.header_mappings_dir = dir
4445
ms.requires_arc = false
46+
# The generated files depend on the protobuf runtime.
4547
ms.dependency "Protobuf"
4648
# This is needed by all pods that depend on Protobuf:
4749
ms.pod_target_xcconfig = {
4850
'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS=1',
4951
}
5052
end
5153

54+
# Files generated by the gRPC plugin
5255
s.subspec "Services" do |ss|
5356
ss.source_files = "#{dir}/*.pbrpc.{h,m}", "#{dir}/**/*.pbrpc.{h,m}"
5457
ss.header_mappings_dir = dir
5558
ss.requires_arc = true
59+
# The generated files depend on the gRPC runtime, and on the files generated by protoc.
5660
ss.dependency "gRPC-ProtoRPC"
5761
ss.dependency "#{s.name}/Messages"
5862
end

src/objective-c/README.md

+72-37
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
[![Cocoapods](https://img.shields.io/cocoapods/v/gRPC.svg)](https://cocoapods.org/pods/gRPC)
22
# gRPC for Objective-C
33

4-
- [Install protoc with the gRPC plugin](#install)
54
- [Write your API declaration in proto format](#write-protos)
65
- [Integrate a proto library in your project](#cocoapods)
76
- [Use the generated library in your code](#use)
87
- [Use gRPC without Protobuf](#no-proto)
9-
- [Alternative installation methods](#alternatives)
8+
- [Alternatives to the steps above](#alternatives)
9+
- [Install protoc with the gRPC plugin](#install)
1010
- [Install protoc and the gRPC plugin without using Homebrew](#no-homebrew)
1111
- [Integrate the generated gRPC library without using Cocoapods](#no-cocoapods)
1212

@@ -15,18 +15,6 @@ usage and adds some interoperability guarantees. Here we use [Protocol Buffers][
1515
plugin for the Protobuf Compiler (_protoc_) to generate client libraries to communicate with gRPC
1616
services.
1717

18-
<a name="install"></a>
19-
## Install protoc with the gRPC plugin
20-
21-
On Mac OS X, install [homebrew][].
22-
23-
Run the following command to install _protoc_ and the gRPC _protoc_ plugin:
24-
```sh
25-
$ curl -fsSL https://goo.gl/getgrpc | bash -
26-
```
27-
This will download and run the [gRPC install script][]. After the command completes, you're ready to
28-
proceed.
29-
3018
<a name="write-protos"></a>
3119
## Write your API declaration in proto format
3220

@@ -40,7 +28,8 @@ Install [Cocoapods](https://cocoapods.org/#install).
4028

4129
You need to create a Podspec file for your proto library. You may simply copy the following example
4230
to the directory where your `.proto` files are located, updating the name, version and license as
43-
necessary:
31+
necessary. You also need to set the `pods_root` variable to the correct value, depending on where
32+
you place this podspec relative to your Podfile.
4433

4534
```ruby
4635
Pod::Spec.new do |s|
@@ -55,16 +44,44 @@ Pod::Spec.new do |s|
5544
s.ios.deployment_target = '7.1'
5645
s.osx.deployment_target = '10.9'
5746

47+
# Base directory where the .proto files are.
48+
src = '.'
49+
50+
# We'll use protoc with the gRPC plugin.
51+
s.dependency '!ProtoCompiler-gRPCPlugin', '~> 0.14'
52+
53+
# Pods directory corresponding to this app's Podfile, relative to the location of this podspec.
54+
pods_root = '<path to your Podfile>/Pods'
55+
56+
# Path where Cocoapods downloads protoc and the gRPC plugin.
57+
protoc_dir = "#{pods_root}/!ProtoCompiler"
58+
protoc = "#{protoc_dir}/protoc"
59+
plugin = "#{pods_root}/!ProtoCompiler-gRPCPlugin/grpc_objective_c_plugin"
60+
61+
# Directory where you want the generated files to be placed. This is an example.
62+
dir = "#{pods_root}/#{s.name}"
63+
5864
# Run protoc with the Objective-C and gRPC plugins to generate protocol messages and gRPC clients.
5965
# You can run this command manually if you later change your protos and need to regenerate.
60-
s.prepare_command = "protoc --objc_out=. --objcgrpc_out=. *.proto"
66+
# Alternatively, you can advance the version of this podspec and run `pod update`.
67+
s.prepare_command = <<-CMD
68+
mkdir -p #{dir}
69+
#{protoc} \
70+
--plugin=protoc-gen-grpc=#{plugin} \
71+
--objc_out=#{dir} \
72+
--grpc_out=#{dir} \
73+
-I #{src} \
74+
-I #{protoc_dir} \
75+
#{src}/*.proto
76+
CMD
6177

6278
# The --objc_out plugin generates a pair of .pbobjc.h/.pbobjc.m files for each .proto file.
63-
s.subspec "Messages" do |ms|
64-
ms.source_files = "*.pbobjc.{h,m}"
65-
ms.header_mappings_dir = "."
79+
s.subspec 'Messages' do |ms|
80+
ms.source_files = "#{dir}/*.pbobjc.{h,m}"
81+
ms.header_mappings_dir = dir
6682
ms.requires_arc = false
67-
ms.dependency "Protobuf", "~> 3.0.0-beta-2"
83+
# The generated files depend on the protobuf runtime.
84+
ms.dependency 'Protobuf'
6885
# This is needed by all pods that depend on Protobuf:
6986
ms.pod_target_xcconfig = {
7087
'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS=1',
@@ -73,11 +90,12 @@ Pod::Spec.new do |s|
7390

7491
# The --objcgrpc_out plugin generates a pair of .pbrpc.h/.pbrpc.m files for each .proto file with
7592
# a service defined.
76-
s.subspec "Services" do |ss|
77-
ss.source_files = "*.pbrpc.{h,m}"
78-
ss.header_mappings_dir = "."
93+
s.subspec 'Services' do |ss|
94+
ss.source_files = "#{dir}/*.pbrpc.{h,m}"
95+
ss.header_mappings_dir = dir
7996
ss.requires_arc = true
80-
ss.dependency "gRPC-ProtoRPC", "~> 0.14"
97+
# The generated files depend on the gRPC runtime, and on the files generated by `--objc_out`.
98+
ss.dependency 'gRPC-ProtoRPC'
8199
ss.dependency "#{s.name}/Messages"
82100
end
83101
end
@@ -89,11 +107,14 @@ Note: If your proto files are in a directory hierarchy, you might want to adjust
89107
the sample Podspec above. For example, you could use:
90108

91109
```ruby
92-
s.prepare_command = "protoc --objc_out=. --objcgrpc_out=. *.proto **/*.proto"
110+
s.prepare_command = <<-CMD
111+
...
112+
#{src}/*.proto #{src}/**/*.proto
113+
CMD
93114
...
94-
ms.source_files = "*.pbobjc.{h,m}", "**/*.pbobjc.{h,m}"
115+
ms.source_files = "#{dir}/*.pbobjc.{h,m}", "#{dir}/**/*.pbobjc.{h,m}"
95116
...
96-
ss.source_files = "*.pbrpc.{h,m}", "**/*.pbrpc.{h,m}"
117+
ss.source_files = "#{dir}/*.pbrpc.{h,m}", "#{dir}/**/*.pbrpc.{h,m}"
97118
```
98119

99120
Once your library has a Podspec, Cocoapods can install it into any XCode project. For that, go into
@@ -121,19 +142,33 @@ pod install
121142
<a name="use"></a>
122143
## Use the generated library in your code
123144

124-
Please check this [sample app][] for examples of how to use a generated gRPC library.
145+
Please check the [example apps][] for examples of how to use a generated gRPC library.
125146

126147
<a name="no-proto"></a>
127148
## Use gRPC without Protobuf
128149

129-
The [sample app][] has an example of how to use the generic gRPC Objective-C client without
130-
generated files.
150+
This [tests file](https://github.com/grpc/grpc/tree/master/src/objective-c/tests/GRPCClientTests.m)
151+
shows how to use the generic gRPC Objective-C client without generated protobuf files.
131152

132153
<a name="alternatives"></a>
133-
## Alternative installation methods
154+
## Alternatives to the steps above
155+
156+
<a name="install"></a>
157+
### Install _protoc_ with the gRPC plugin
158+
159+
Although it's not recommended (because it can lead to hard-to-solve version conflicts), it is
160+
sometimes more convenient to install _protoc_ and the gRPC plugin in your development machine,
161+
instead of letting Cocoapods download the appropriate versions for you. To do so, on Mac OS X or
162+
later, install [homebrew][].
163+
164+
The run the following command to install _protoc_ and the gRPC _protoc_ plugin:
165+
```sh
166+
$ curl -fsSL https://goo.gl/getgrpc | bash -
167+
```
168+
This will download and run the [gRPC install script][].
134169

135170
<a name="no-homebrew"></a>
136-
### Install protoc and the gRPC plugin without using Homebrew
171+
### Install _protoc_ and the gRPC plugin without using Homebrew
137172

138173
First install v3 of the Protocol Buffers compiler (_protoc_), by cloning
139174
[its Git repository](https://github.com/google/protobuf) and following these
@@ -145,15 +180,15 @@ cloned.
145180

146181
Compile the gRPC plugins for _protoc_:
147182
```sh
148-
make plugins
183+
make grpc_objective_c_plugin
149184
```
150185

151186
Create a symbolic link to the compiled plugin binary somewhere in your `$PATH`:
152187
```sh
153188
ln -s `pwd`/bins/opt/grpc_objective_c_plugin /usr/local/bin/protoc-gen-objcgrpc
154189
```
155-
(Notice that the name of the created link must begin with "protoc-gen-" for _protoc_ to recognize it
156-
as a plugin).
190+
(Notice that the name of the created link must begin with "`protoc-gen-`" for _protoc_ to recognize
191+
it as a plugin).
157192

158193
If you don't want to create the symbolic link, you can alternatively copy the binary (with the
159194
appropriate name). Or you might prefer instead to specify the plugin's path as a flag when invoking
@@ -178,5 +213,5 @@ Objective-C Protobuf runtime library.
178213
[Protocol Buffers]:https://developers.google.com/protocol-buffers/
179214
[homebrew]:http://brew.sh
180215
[gRPC install script]:https://raw.githubusercontent.com/grpc/homebrew-grpc/master/scripts/install
181-
[example Podfile]:https://github.com/grpc/grpc/blob/master/src/objective-c/examples/Sample/Podfile
182-
[sample app]: https://github.com/grpc/grpc/tree/master/src/objective-c/examples/Sample
216+
[example Podfile]:https://github.com/grpc/grpc/blob/master/examples/objective-c/helloworld/Podfile
217+
[example apps]: https://github.com/grpc/grpc/tree/master/examples/objective-c

0 commit comments

Comments
 (0)