Our iOS app currently is using Google protobuffer gRPC as our API layer to communicate between App and backend. And so we have these .proto
files in our backend directory which will be converting to .grpc.swift
and .pb.swift
files by gRPC-Swift-Plugins and then consumed by the App.
This works okay, but the process of converting is very tedious, and we would like to automate the whole process.
Below is how we're doing it:
- Delete previously copied directory, and copy all
.proto
files from backend (.proto
files are maintained by backend devs) to App directory named "Protos" via a shell script - We already set up Build rules and include
.proto
files in Compile Sources. Following the steps from an answer here on SO
Screenshot of the current setup in Xcode Build Rules:
- Whenever we build the project,
.pb.swift
and.grpc.swift
are generated and putting into a directory named "generated" under the "Protos" folder.
Here are the problems:
- If the backend added a new
.proto
files into the source directory, my script will only copy the files into the Protos directory but not included news files in the Compile Sources list. - Similar to the first problem, we need to manually set up Compile Sources in Xcode and that means if a new dev joins our team, he/she also needs to do the same setup again.
- We sometimes need to refer to the
.grpc.swift
and.ph.swift
files while coding. But If we add these files into Xcode and build the project again, Xcode will complain that these generated files are there like (Sorry, we're working on a private repo, so the project name and file names are replaced):
Multiple commands produce '${user_path}/${proto_name}.pb.o':
- Target '${my_project_name}' (project '${my_project_name}') has compile command for Swift source files
- Target '${my_project_name}' (project '${my_project_name}') has compile command for Swift source files
Any answers or comments and suggestions are greatly appreciated!
It's interesting I didn't have those problems with Swift if I use the $DERIVED_FILE_DIR
I don't use the plugin because I've got the plugin installed in my
/usr/local/bin
But I have exactly those problems when we use the output for cpp files.