Skip to main content

Patching Bazel Dependencies

Steps to patch http_archive

When you want to configure the content of dependencies, you can follow the steps below:

  1. Clone the target to patch
  2. Edit the target
  3. Generate a patch with git command
  4. Configure patches and patch_args

1. Clone the target to patch

The first thing you need to do is clone (and checkout) the target to patch.

git clone <URL of the target>
git checkout <commit to modify>

2. Edit the target

The next step is to edit the target as you want.

3. Generate a patch with git command

After you complete editing of the cloned dependency, generate a patch file with git diff command as follows:

git diff > my.patch

4. Locate the patch to the Bazel workspace

Put the patch file into the workspace and export it for bazel. See scripts/bazel/rules_typescript_proto/{BUILD.bazel,*.patch} for example.

5. Configure patches and patch_args

The last step is to set patch_args and patches to http_archive as follows:

name = "blahblah",
patch_args = ["-p1"],
patches = ["//path/to/my.patch"],
sha256 = "6d4edbf28ff6720aedf5f97f9b9a7679401bf7fca9d14a0fff80f644a99992b4",
urls = [""],

Notes on patching dependencies fetched by other rules

Some rules like go_repository in rules_go provides a similar interface to http_archive for patching. If a rule does NOT have one, you need to consider to contribute the rule or patching it before fecthing the rules with http_archive!