bazel icon indicating copy to clipboard operation
bazel copied to clipboard

Add support for patches to `git_repository` in `source.json`

Open froody opened this issue 1 year ago • 2 comments

Description of the feature request:

As defined in https://bazel.build/external/registry, the git_repository type doesn't support patches, only archive does.

I am trying to migrate my project to use bazel modules, but I have a lot of third-party deps that don't support bazel at all. For most of these it's possible add a small build_file_content to new_git_repository, but it seems there's no analog for this with bazel modules. For example, I have this currently in my WORKSPACE file:

new_git_repository(
    name="ctti",
    build_file_content="""
cc_library(
    name="ctti",
    hdrs=glob(["include/**/*"]),
    includes=["include"],
    visibility = ["//visibility:public"],
    )""",
    remote="https://github.com/Manu343726/ctti",
    commit="2c7ab7dcd114c20802656b527e28b6e91e698e14",
    shallow_since="1533063710 +0200",
)

To create a registry entry for this in my local registry, I can't use archive as there's no published release for this git hash, and I can't use git_repository because the repo doesn't have a BUILD or MODULE.bazel file. Thus my only option (if I want a registry) is to either make a release and host it somewhere myself, or fork the git repo and commit the BUILD/MODULE.bazel files to that fork. It would be much nicer if I could contain all the module-specific changes in a single location (my local registry).

Even nicer would be some syntactic sugar allowing me to specify build_file_content in the MODULE.bazel in the registry without having to add a BUILD or MODULE.bazel files to the repo

Which category does this issue belong to?

No response

What underlying problem are you trying to solve with this feature?

Represent third-party dependencies that don't natively support bazel as modules in my own local registry so I can use these modules from multiple repositories without having to copy-paste a lot of setup code

Which operating system are you running Bazel on?

ubuntu-22.04

What is the output of bazel info release?

release 7.2.0

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What's the output of git remote get-url origin; git rev-parse HEAD ?

No response

Have you found anything relevant by searching the web?

No response

Any other information, logs, or outputs that you want to share?

No response

froody avatar Jun 22 '24 11:06 froody

For this kind of dependency, you could probably just use git_repository via use_repo_rule. Does that work for you? The advantage over making it a module is that your build file can directly reference any other deps of your root module.

fmeum avatar Jun 22 '24 12:06 fmeum

In my case I have multiple "root" modules, and I want to have a shared set of third-party modules that are easy to access (e.g. via bazel_dep). I don't see how to make use_repo_rule work in a registry entry as it creates a new repo, whereas I want to populate the current module

froody avatar Jun 22 '24 14:06 froody

This sounds like a reasonable FR that's also quite newbie-friendly. So PRs welcome :)

Wyverald avatar Jul 08 '24 19:07 Wyverald

@Wyverald I'm going to work on it :)

ebouye avatar Jul 17 '24 11:07 ebouye

hey all, also adding support for overlay would be great ! See https://github.com/bazelbuild/bazel/pull/22525

hugomano avatar Aug 30 '24 13:08 hugomano

For this kind of dependency, you could probably just use git_repository via use_repo_rule. Does that work for you? The advantage over making it a module is that your build file can directly reference any other deps of your root module. Is this still the issue ?@fmeum @Wyverald

priyanshscpp avatar Jan 26 '25 20:01 priyanshscpp

i want to contribute

Priya-0217 avatar Mar 13 '25 13:03 Priya-0217

For this kind of dependency, you could probably just use git_repository via use_repo_rule. Does that work for you?

The downside for that is you end up needing to maintain the parts of the build in multiple places (i.e. every single project that depends on that other library). The BCR has something like a few hundred modules with at least one version having patch files adding a MODULE.bazel, so it seems to be a common thing to publicly publish external Bazel'ification of libraries that don't provide first party support. Doing that via use_repo_rule and git_repository is not practical for all the reason bzlmod was created in the first place.

bcsgh avatar Mar 26 '25 04:03 bcsgh