diff --git a/README.md b/README.md
index 4b6ff01..9dc0946 100644
--- a/README.md
+++ b/README.md
@@ -30,9 +30,22 @@ diff(
)
```
+### Compare binary files
+
+```starlark
+load("@diff.bzl//diff:defs.bzl", "cmp")
+
+cmp(
+ name = "compare_bins",
+ args = ["--bytes", "4", "--verbose"],
+ srcs = ["bin_a", "bin_b"],
+ out = "cmp_output"
+)
+```
+
### Keep generated sources up to date
-Pass `validate = 1` to `diff` to create a build validation error when a generated source input diverges from the output tree file.
+Pass `validate = 1` to `cmp` or `diff` to create a build validation error when a generated source input diverges from the output tree file.
```starlark
load("@diff.bzl//diff:defs.bzl", "diff")
@@ -47,7 +60,7 @@ diff(
)
```
-A build error message with command to run to patch the file will be output.
+An error message with command to run to patch the file will be output.
```
ERROR: diff command exited with non-zero status.
diff --git a/diff/defs.bzl b/diff/defs.bzl
index 569c752..1e08cc6 100644
--- a/diff/defs.bzl
+++ b/diff/defs.bzl
@@ -7,6 +7,31 @@ load("//diff/private:diff.bzl", "diff_rule")
def cmp(name, srcs, args = [], out = None, **kwargs):
"""Runs cmp (binary diff) between two files and returns the output.
+ Examples:
+
+ Compare two binaries.
+
+ ```starlark
+ cmp(
+ name = "compare_bins",
+ args = ["--bytes", "4", "--verbose"],
+ srcs = ["bin_a", "bin_b"],
+ out = "cmp_output"
+ )
+ ```
+
+ Run cmp in a genrule.
+
+ ```starlark
+ genrule(
+ name = "run_cmp",
+ srcs = ["bin_a", "bin_b"],
+ outs = ["cmp_output"],
+ cmd = "$(CMP_BIN) --verbose $(execpath bin_a) $(execpath bin_b) > $@",
+ toolchains = ["@diff.bzl//diff/toolchain:execution_type"],
+ )
+ ```
+
Args:
name: The name of the rule
srcs: The files to compare.
@@ -54,6 +79,18 @@ def diff(name, srcs, args = ["--unified"], patch = None, **kwargs):
)
```
+ Run diff in a genrule.
+
+ ```starlark
+ genrule(
+ name = "run_diff",
+ srcs = ["a.txt", "b.txt"],
+ outs = ["a.patch"],
+ cmd = "$(DIFF_BIN) --unified $(execpath a.txt) $(execpath b.txt) > $@",
+ toolchains = ["@diff.bzl//diff/toolchain:execution_type"],
+ )
+ ```
+
_By default, diff creates a unified format patch by passing `["--unified"]`
to `args`. If overriding arguments, --unified must be added explicitly._
diff --git a/docs/rules.md b/docs/rules.md
index 40cbc63..80e6553 100644
--- a/docs/rules.md
+++ b/docs/rules.md
@@ -14,6 +14,32 @@ cmp(name, srcs,