Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support root_module_optional_deps in module_ctx.extension_metadata #25046

Open
thesayyn opened this issue Jan 23, 2025 · 2 comments
Open

Support root_module_optional_deps in module_ctx.extension_metadata #25046

thesayyn opened this issue Jan 23, 2025 · 2 comments
Labels
team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. type: feature request untriaged

Comments

@thesayyn
Copy link
Contributor

Description of the feature request:

As of today, module extensions can report what must be put into use_repo calls using root_module_direct_deps and root_module_direct_dev_deps with the help of module_ctx.is_dev_dependency, this is good in cases where all the repositories created by the module extension most likely will be used somewhere in the repo.

However, repositories created by the module extension might be not be used at all and can be confusing to people and sometimes leads to spurious warning messages if omitted.

For instance, the rules_oci oci_pull extension creates several repositories and reports them with root_module_direct_deps. Given the example

oci = use_extension("@rules_oci//oci:extensions.bzl", "oci")

oci.pull(
    name = "distroless_base",
    platforms = ["linux/amd64", "linux/arm64/v8"]
)

use_repo(oci, "distroless_base")

the extension reports the following repos, distroless_base, distroless_base_linux_amd64, distroless_linux_arm64_v8, here distroless_base and the other repos are interchangeable, while some users need the platform specific, other don't.

Today, there is not much the extension do because it doesn't have a mechanism to determine if they were requested in the first place, so the extension has to assume they are going to be needed, and reports them with root_module_direct_deps.

Feature request is to have another field in extension_metadata that extensions can report optional deps.

module_ctx.extension_metadata(
        root_module_direct_deps = ["distroless_base"],
        root_module_optional_deps = ["distroless_base_linux_amd64", "distroless_linux_arm64_v8"]
)

Given module extension above, when users run bazel mod tidy, Bazel will create a use_repo call with distroless_base entry and add the other two repositories if we are references anywhere in the dependency graph.

Which category does this issue belong to?

External Dependency

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

Reporting dependencies from module extension that are needed optionally.

See: #24950
See: bazel-contrib/rules_oci#727
See: bazel-contrib/rules_oci#611
See: https://github.com/bazel-contrib/rules_oci/pull/611/files#r1646582755 cc @fmeum

Which operating system are you running Bazel on?

darwin-arm64

What is the output of bazel info release?

No response

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 ?


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
Copy link
Collaborator

fmeum commented Jan 25, 2025

... and add the other two repositories if we are references anywhere in the dependency graph.

This isn't feasible, but we could make it so that repos in root_module_optional_deps are never added nor removed by bazel mod tidy. Would that be sufficient for your use case?

@thesayyn
Copy link
Contributor Author

thesayyn commented Jan 25, 2025

I am not sure if that would be helpful, if a build fails and bazel doesn’t tell user it can be fixed by running some commands, I don’t see the point of adding such feature. Key here is to reduce confusion.

Perhaps if a build fails due to missing use_repo call, Bazel can simply say, I have seen this repo in one of the optional deps, let me generate a bulldozer command for you would be fantastic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. type: feature request untriaged
Projects
None yet
Development

No branches or pull requests

5 participants