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

strict_deps_mode = error complains about dependencies that aren't referenced #1571

Open
evis opened this issue May 6, 2024 · 3 comments
Open

Comments

@evis
Copy link

evis commented May 6, 2024

I tried to turn on strict_deps_mode = "error" in my scala_toolchain(), but it complains about dependencies that aren't used directly in my Scala code.

BUILD:

proto_library(
    name = "model_proto",
    srcs = ["model.proto"],
    visibility = ["//visibility:public"],
)

java_proto_library(
    name = "model_java_proto",
    visibility = ["//visibility:public"],
    deps = [
        ":model_proto",
    ],
)

scala_library(
    name = "scala_class",
    srcs = ["ScalaClass.scala"],
    visibility = ["//deps-mode:__subpackages__"],
    deps = [":model_java_proto"],
)

model.proto:

syntax = "proto3";

package deps_mode;

enum ProtoEnum {
  UNKNOWN = 0;
  KNOWN = 1;
}

ScalaClass.scala:

package deps_mode

case class ScalaClass(value: Model.ProtoEnum)

Expected bazel build result: success (it builds with strict_deps_mode = "off").

Actual bazel build result: fails with

error: Target '@@com_google_protobuf//java/core:lite_runtime_only' is used but isn't explicitly declared, please add it to the deps.
You can use the following buildozer command:
buildozer 'add deps @@com_google_protobuf//java/core:lite_runtime_only' //deps-mode:scala_class
error: Target '@@com_google_protobuf//java/core:core' is used but isn't explicitly declared, please add it to the deps.
You can use the following buildozer command:
buildozer 'add deps @@com_google_protobuf//java/core:core' //deps-mode:scala_class
2 errors
Build failed
java.lang.RuntimeException: Build failed
        at io.bazel.rulesscala.scalac.ScalacInvoker.invokeCompiler(ScalacInvoker.java:55)
        at io.bazel.rulesscala.scalac.ScalacWorker.compileScalaSources(ScalacWorker.java:253)
        at io.bazel.rulesscala.scalac.ScalacWorker.work(ScalacWorker.java:69)
        at io.bazel.rulesscala.worker.Worker.persistentWorkerMain(Worker.java:86)
        at io.bazel.rulesscala.worker.Worker.workerMain(Worker.java:39)
        at io.bazel.rulesscala.scalac.ScalacWorker.main(ScalacWorker.java:33)

It's kind of surprising, since protobuf//java isn't used explicitly in my Scala code, it's used transitively via ProtoEnum.

Moreover, if I run all of given buildozer commands, then build fails again:

in scala_library rule //deps-mode:scala_class: target '@@com_google_protobuf//java/core:lite_runtime_only' is not visible from target '//deps-mode:scala_class'. Check the visibility declaration of the former target if you think the dependency is legitimate

Although, if I just do buildozer 'add deps @@com_google_protobuf//java/core:core' //deps-mode:scala_class, then build succeeds. But I'd like to avoid adding this dependency everywhere.

@evis
Copy link
Author

evis commented May 6, 2024

Also, strict_deps_mode = error sometimes suggests to add proto_library() dependencies, instead of java_proto_library() dependencies. Couldn't create MVCE yet, though.

@liucijus
Copy link
Collaborator

liucijus commented May 6, 2024

Hi, @evis! Thanks for reporting. Could you create a small repo to reproduce your problem?

Regarding java_proto_library deps being incorrectly reported - it's a known issue. It happens because the archive is stamped with incorrect target label from the aspect. The similar issue for scala_proto_library is here for more info: #1234 (comment)

@evis
Copy link
Author

evis commented May 7, 2024

Regarding java_proto_library deps being incorrectly reported - it's a known issue

Thanks for your link, found bazelbuild/bazel#4990 here

Could you create a small repo to reproduce your problem?

Yes, I'll try

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants