protoc flag to set "-I $PROTOBUF_INSTALL_DIR/include" implicitly
What language does this apply to?
protoc compiler
Describe the problem you are trying to solve.
Protobuf installations typically come with the include directory that has most of the necessary protobuf files for common types like google.protobuf.Empty.
However, this directory is not included by default, nor is there a simple way to include them during protoc invocation.
Describe the solution you'd like
- add a new flag
--import-default-includesto theprotoccompiler to implicitly add-I $(which protoc)/../include(this assumes unzip method, installations via package managers have different structure). - This will allow users to automatically set the import path to the correct set of supported protobuf files that came with the compiler, by simply doing
protoc --import-default-includes -I./path/to/my/other/includes my_file.proto
Describe alternatives you've considered
https://github.com/stub42/protobuf-snap/issues/1 <-- proposed setting a global $PROTOBUF_HOME during installation via snap so that users can do
protoc -I${PROTOBUF_HOME}/include ....
but this is not a universal solution as it would only work for snap
Additional context
nil
I unpacked protoc to $HOME/.local and am also running into the issue where the included protobuf files cannot be found.
If protoc was automatically adding $HOME/.local/include:$PREFIX/local/include:$PREFIX/include (with protoc installed to $PREFIX/bin) to the import path, that would be very convenient.
Another alternative which does not depend on protoc installation method is to reference protocolbuffers/protobuf directly when you are building. I added https://github.com/protocolbuffers/protobuf as a submodule of my repo. Then when calling protoc I add:
-I vendor/github.com/protocolbuffers/protobuf/src
I'm not familiar C/C++ use of include directories and this feels more appropriate way to reference dependencies (make it explicit).
I will add my support to the first solution, ie an environment variable with the default import path. This could be configured to include multiple paths (like the PATH variable) I am currently trying to create a machine independent build script. I cannot specify the import location explicitly as it depends where the relevant files were installed on the current machine (my dev machine, colleague's machine, build server, etc)
We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please add a comment.
This issue is labeled inactive because the last activity was over 90 days ago.
We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please reopen it.
This issue was closed and archived because there has been no new activity in the 14 days since the inactive label was added.