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

Make load ignore modules marked as dev_dependency #25187

Open
alextercete opened this issue Feb 4, 2025 · 1 comment
Open

Make load ignore modules marked as dev_dependency #25187

alextercete opened this issue Feb 4, 2025 · 1 comment
Labels
P2 We'll consider working on this in future. (Assignee optional) team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. team-Loading-API BUILD file and macro processing: labels, package(), visibility, glob type: feature request

Comments

@alextercete
Copy link

Description of the feature request:

load should ignore modules marked as dev_dependency for BUILD.bazel files not in the root module. If a public target depends (directly or indirectly) on such module, it should error with something like "target A depends on B, but B is marked as a dev dependency".

Which category does this issue belong to?

External Dependency

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

Currently, you can't have public targets in the same BUILD.bazel file as you're loading a dev dependency:

# MODULE.bazel

bazel_dep(name = "bazel_skylib", version = "1.7.1", dev_dependency = True)
# BUILD.bazel

load("@bazel_skylib//rules:build_test.bzl", "build_test")

genrule(
    name = "genrule",
    outs = ["hello"],
    cmd = "echo world > $@",
    visibility = ["//visibility:public"],
)

build_test(
    name = "test",
    targets = [":genrule"],
)

When trying to use :genrule from another module, you get an error saying the dev dependency can't be found:

ERROR: error loading package '@@b~//': Unable to find package for @@[unknown repo 'bazel_skylib' requested from @@b~]//rules:build_test.bzl: The repository '@@[unknown repo 'bazel_skylib' requested from @@b~]' could not be resolved: No repository visible as '@bazel_skylib' from repository '@@b~'.
ERROR: /home/aleter01/Sandbox/dev_dependency/BUILD.bazel:1:6: error loading package '@@b~//': Unable to find package for @@[unknown repo 'bazel_skylib' requested from @@b~]//rules:build_test.bzl: The repository '@@[unknown repo 'bazel_skylib' requested from @@b~]' could not be resolved: No repository visible as '@bazel_skylib' from repository '@@b~'. and referenced by '//:genrule'

Which operating system are you running Bazel on?

Linux

What is the output of bazel info release?

release 7.4.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 ?


Have you found anything relevant by searching the web?

No, but I've asked about this in the Bazel Slack.

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

Here's a reproduction of the current behaviour. The current workaround seem to be to split targets which depend on the dev dependency into a separate BUILD.bazel file.

@sgowroji sgowroji added the team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. label Feb 4, 2025
@fmeum
Copy link
Collaborator

fmeum commented Feb 4, 2025

This would require being able to evaluate BUILD files without having resolved all loads, which isn't easy in the current module.

CC @brandjon @comius for "lazy load"

@meteorcloudy meteorcloudy added team-Loading-API BUILD file and macro processing: labels, package(), visibility, glob P2 We'll consider working on this in future. (Assignee optional) and removed untriaged labels Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 We'll consider working on this in future. (Assignee optional) team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. team-Loading-API BUILD file and macro processing: labels, package(), visibility, glob type: feature request
Projects
None yet
Development

No branches or pull requests

6 participants