The protoc
error messaging is a little cryptic here. You have 3 options for providing a plugin to protoc
:
- A plugin in your
$PATH
following the protoc-gen-$NAME
format. This will be automatically picked up.
- A plugin not conforming to the above naming convention, but available in your
$PATH
. This can be executed with the --plugin=$some-nonconventional-name
.
- A plugin not in your
$PATH
. This requires suppling an absolute path or relative path (from the current working directory) to the executable. This is executed with --plugin=proto-gen-$any-name-you-want=$path-to-executable
Expanding on 3 above. If you create a file example-plugin
:
#!/bin/bash
echo "Example Plugin Running!"
You'll then want to make sure it's executable:
chmod +x ./example-plugin
We need an output directory, let's make one:
mdkir plugin-output
We need a .proto
file. Find one and name it anything you like, like MyProto.proto
Let's pick an arbitrary name for this plugin. We can call it foo
.
Then you'll execute it with protoc
as follows:
protoc --plugin=protoc-gen-foo=$PATH_TO_EXAMPLE_PLUGIN --foo_output=./plugin-output MyProto.proto
You should see something like:
--foo_out: protoc-gen-foo: Plugin output is unparseable: Example Plugin Running!\n