bazelbuild / bazel

a fast, scalable, multi-language and extensible build system
https://bazel.build
Apache License 2.0
22.69k stars 3.98k forks source link

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

Open froody opened 1 week ago

froody commented 1 week ago

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

fmeum commented 1 week ago

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.

froody commented 1 week ago

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