I am trying to port an android app to ios and new to mac/xcode ecosystem. My app uses Google proto buffs and using instructions at https://github.com/alexeyxo/protobuf-swift/blob/master/README.md I am able to build protobuf for swift and add ProtocolBuffers.xcodeproj to my project. I was even able to generate .swift files for my proto files outside of xcode using protoc directly. However, my question is how do I integrate .proto files in Xcode so xcode can find/compile them? Do I need to copy my .proto files manually in my project? I am using Xcode 7.2.1 and protoc version is 3.0.0. Thanks in advance.
Asked
Active
Viewed 2,723 times
1 Answers
6

silyevsk
- 4,021
- 3
- 31
- 30
-
Thanks silyevsk. I guess that will generate cc files. With swift extension to proto, the generated files are .swift (i used --swift_out), however the same rule with .swift extension insted of .pb.cc doesn't seem to work for me. Any idea with that? For now, I will try to use this and see whether that solves my immediate problem. Thanks for your help ! – Abhijit Vaidya Mar 07 '16 at 18:03
-
@AbhijitVaidya - What error do you get when trying to build with the rule? – silyevsk Mar 07 '16 at 19:10
-
Hi Silyevsk, I am trying your suggestion now for generating .pb.h/.cc files first. I added those two rules but was getting header not found errors. So I first tried to add /usr/include (recurisve) in header search paths (since that path has required headers) but that didn't work. So next based on suggestions online, I added (path to my protobufdownload)/src in header and now it is finding headers but i am getting compilation errors such as 'No type name 'string' in namespace 'std'' when it is trying to compile the code. Any hints? – Abhijit Vaidya Mar 07 '16 at 20:49
-
@AbhijitVaidya - don't use c++, you probably need swift. I left c++ in the example just because I use it. (I initially didn't notice that you need swift.) Anyways, you should set the rule with the command that you use manually to compile .proto files. – silyevsk Mar 07 '16 at 20:58
-
I think I am close. I changed the rules to generate swift_out and the generated .swift files for my proto (foo.proto.swift) is in the same directory as my proto (both are in in INPUT_FILE_DIR). However, the viewcontroller.swift which is also in the same directory is unable to find the public class which is present in foo.proto.swift. Am I missing some dependency here? My assumption is because all these files are in the same directory, the generated classes should be available to other .swift files in that directory. I am very new to swift btw :) – Abhijit Vaidya Mar 07 '16 at 23:08
-
1Actually never mind. I figured it out. I was missing the filename in compile sources. Thanks for your help ! – Abhijit Vaidya Mar 07 '16 at 23:14
-
What if I encountered this error `GPBProtocolBuffers_RuntimeSupport.h' file not found`? @silyevsk – Johnny Oct 29 '17 at 10:24
-
why use the sources directory (input_file_dir) for output ??? There is a Derived_File_Dir for that - which Xcode uses by default, and better observes for changes. Xcode also continues to compile the sources created by protoc automatically then (just like it's doing with sources generated from CoreData schema, CoreML model files etc. – Motti Shneor Jul 18 '19 at 07:03