Migrate from Protolock
Protolock is a widely used Protobuf tool that primarily concentrates on breaking change detection. It deserves a lot of praise - in the OSS world, it largely pioneered the breaking change detection effort, and has been well maintained. We can't heap enough praise on this effort, it's helped the Protobuf ecosystem move forward in a big way.
In this document, we'll discuss the pros and cons of Protolock vs
breaking change detector, as well as
buf-equivalent commands and migration.
- Protolock has a plugin interface allowing you to create external
binaries that Protolock then calls itself to verify rules. The equivalent way to do this for
bufis to ask us to add a lint or breaking rule, which we're more than happy to do in most scenarios. It's our feeling that calling out to external binaries for individual lint rules leads to issues with tool distribution and management, but this use case may be something you want, and
bufdoes not support it.
- Protolock uses a third-party Protobuf parser that is not tested to cover every edge case of the Protobuf grammar, and
has had such issues in the past. Additionally, this parser does not verify that what it is parsing is actually valid
Protobuf, meaning that Protolock can both have breakages for valid Protobuf file, and happily parse Protobuf files
that are not valid. Instead,
buflets you use either the internal compiler that is tested to cover every edge case and parses only valid files, or use
bufinput. See our compiler discussion for more details.
- Protolock uses a custom structure, represented in
JSON, to store
your Protobuf schema state. This structure is populated based on the results of the third-party Protobuf parser,
meaning that file data can be corrupted for an invalid parse. This structure also does not cover all known elements of
a Protobuf schema, especially Protobuf options that can have an effect on your API compatibility. Instead,
FileDescriptorSets, extended to Buf images, which are the core primitive of the Protobuf ecosystem, and have been stable for over a decade.
buf's equivalent to lock files are serialized
- Protolock only enforces 8 rules related to API compatibility in strict mode, and 5 with strict mode disabled.
bufenforces 46 rules related to API compatibility in its strictest mode (
FILE), and 15 rules related to wire-only compatibility in its weakest mode (
WIRE). We believe that the additional rules that
bufenforces are critical to API compatibility.
- Breaking change rules are not a binary proposition - there are different kinds of breaking changes that you may care
bufprovides four categories of breaking change rules to select - per-file generated stub breaking changes, per-package generated stub breaking changes, wire breaking changes, and wire + JSON breaking changes. Within these categories, you can go further and enable or disable individual rules through configuration.
file:line:column:messagereferences for breaking change violations, letting you know where a violation occurred, including potentially integrating this into your editor in the future. These reference your current Protobuf schema, including if types move across files between versions of your Protobuf schema. The error output can be outputted as text or JSON, with other formats coming in the future. Protolock prints out unreferenced messages.
- Protolock relies on
proto.lockfiles as the only way to store the representation of your previous Protobuf schema, and these files are represented by a custom structure.
bufallows you to use lock files through
buf build, but also allows other methods to store and retrieve your previous Protobuf schema, including:
- Cloning the head of a branch of a Git repository, either local or remote, and compiling on the fly.
- Reading a tar or zip archive, either local or remote and optionally compressed, and compiling on the fly.
- Reading a "lock file", represented as a Buf image, from either a local location or a remote http/https location.
- Both Protolock and
bufrun file discovery for your Protobuf files, however
bufallows you to skip file discovery and specify your files manually for use cases that require this, such as Bazel.
FileDescriptorSets as input,
bufprovides a protoc plugin to allow you to use
buf's breaking change detection functionality with your current
See the breaking configuration documentation for more details. Note that
configuration can be provided via the flag
--config on the command line if you do not want to have a configuration
Protolock rules to
buf configured rules
See the breaking rules documentation for an overview of all available breaking rules.
While we recommend using one of
buf's preset breaking categories, the below configuration selects the same rules as
the rules enforced by Protolock:
This roughly corresponds to the
WIRE_JSON group, with some rules added and some deleted. The below configuration is
equivalent to the above configuration:
Protolock flags that are
buf configuration options
The Protolock flag
--ignore can be handled by the
breaking.ignore_only configuration options.
The Protolock flag
--protoroot is effectively handled by the placement of the
buf.yaml configuration file.
The Protolock flag
--lockdir is handled by your against input, as
buf can take multiple types of input to compare
against. The equivalent in
buf would be to specify your Buf image location with
There are multiple methods to compare versions in
buf, see the breaking usage documentation
for more details.
This section assumes you are using stored Buf image files as your method of comparing versions of your Protobuf schema.
$ buf build -o lock.binpb
This writes a binary Buf image of your current Protobuf schema. If you prefer this to be
stored as JSON, as Protolock does, instead write to a file with a
.json extension, such as
buf build -o lock.json.
Note that by default,
buf build include source code info, which makes the resulting file significantly larger. If this
is not a concern, we recommend keeping the source code info for usage with other parts of Buf, but if you are only using
buf for breaking change detection, you can safely suppress source code info with the
$ buf breaking --against lock.binpb
This checks for breaking changes against the
lock.binpb Buf image file. Use
buf breaking --against lock.json if you wrote a JSON file.
$ buf breaking --against lock.binpb && buf build -o lock.binpb
$ docker pull bufbuild/buf
$ docker run --volume "$(pwd):/workspace" --workdir "/workspace" bufbuild/buf lint