Open hsyed opened 6 years ago
The visibility cannot be opened, but im curious why kotlin needs it? AbstractServerImplBuilder should be visible to the InProcessServerBuilder
This doesn't seem to be visibility thing (private, protected, etc). It seems AbstractServerImplBuilder could not be found. Maybe you're not including transitive dependencies in your build rule? (Or maybe Kotlin transitive dependency handling has a bug?)
I don't see anything more we can do here. It seems the classpath of whatever rule is having trouble needs fixing. We don't have much expertise there.
If you get more details, comment and we can re-open.
Maybe you're not including transitive dependencies in your build rule
This is indeed the case. The Kotlin rules aren't as sophisticated as the Java rules, and the java rules "strict deps" semantics are emulated.
Changing the Kotlin rules to use the full transitive classpath without strict dep enforcement would be quite a step backward. I do have a POC implementation for strict-deps for Kotlin and this implementation uses the full transitive classpath just like the java rules. However this POC uses the command line jdk jdeps tool for strict-dep post processing. It will be a while before I can work on this again and I'd like some feedback from people who work on bazel full time before I will commit to this design -- I think a Kotlin compiler plugin is better suited.
@ejona86 / @carl-mastrangelo would it be possible to export only the internal target via another java_library
or alias
and give it a fairly glaring do_not_use_me_esque
target (perhaps in the internal package) so I can add it directly to the classpath as a work-around this wouldn't affect the correctness of the visibility when using the dependencies correctly.
FWI for these deps
kt_jvm_library(
name = "grpc",
srcs = glob(["*.kt"]),
visibility = ["//visibility:public"],
deps = [
"//third_party/jvm/com/typesafe:config",
"//third_party/vendor/config4k",
"//third_party/plugins:immutables",
# the following two are aliases
"//third_party:grpc-core",
"//third_party:grpc-netty",
"//third_party/jvm/com/google/guava",
"//third_party/jvm/org/slf4j:slf4j_api",
"@io_netty_netty_handler//jar",
"//third_party/jvm/com/google/inject:guice"
],
)
I get the following compile classpath from the rules currently:
bazel-out/darwin-fastbuild/genfiles/external/com_typesafe_config/jar/_ijar/jar/external/com_typesafe_config/jar/config-1.3.2-ijar.jar
bazel-out/darwin-fastbuild/bin/third_party/vendor/config4k/config4k.jar
bazel-out/darwin-fastbuild/genfiles/external/org_immutables_value/jar/_ijar/jar/external/org_immutables_value/jar/value-2.5.6-ijar.jar
bazel-out/darwin-fastbuild/bin/external/grpc_java/core/libcore-hjar.jar
bazel-out/darwin-fastbuild/bin/external/grpc_java/netty/libnetty-hjar.jar
bazel-out/darwin-fastbuild/genfiles/external/com_google_guava_guava/jar/_ijar/jar/external/com_google_guava_guava/jar/guava-24.0-jre-ijar.jar
bazel-out/darwin-fastbuild/genfiles/external/org_slf4j_slf4j_api/jar/_ijar/jar/external/org_slf4j_slf4j_api/jar/slf4j-api-1.7.25-ijar.jar
bazel-out/darwin-fastbuild/genfiles/external/io_netty_netty_handler/jar/_ijar/jar/external/io_netty_netty_handler/jar/netty-handler-4.1.17.Final-ijar.jar
bazel-out/darwin-fastbuild/genfiles/external/com_google_inject_guice/jar/_ijar/jar/external/com_google_inject_guice/jar/guice-4.2.0-ijar.jar
external/com_github_jetbrains_kotlin/lib/kotlin-stdlib.jar
external/com_github_jetbrains_kotlin/lib/kotlin-stdlib-jdk7.jar
external/com_github_jetbrains_kotlin/lib/kotlin-stdlib-jdk8.jar
Okay. I think I follow now. The pieces:
InProcessServerBuilder
in Kotlin sourceAbstractServerImplBuilder
) to the explicit deps, to avoid the strict_deps processing.I did try briefly to see if I could see how Java works for (3). I glanced at the hjar for :inprocess
. It includes a META-INF/TRANSITIVE folder with AbstractServerImplBuilder
(and ServerBuilder
). The class has had all its methods stripped; not just the method bodies. But there's more magic going on, as you can't reference ServerBuilder
at all if you are only depending on :inprocess
, while you can reference inherited methods (like executor()
).
This makes me feel like (3) could at least be partially blamed on the Kotlin strict_deps implementation. Before we open up a target for working around this issue, I'd really like to see an issue filed for the Kotlin Bazel rules so we can learn if/when this issue is resolved.
@ejona86 fyi using this as an interim fix.
def some_workspace_setup_macro( grpc_java_commit)
_github_archive(
name = "io_grpc_grpc_java",
repo = "grpc/grpc-java",
commit = grpc_java_commit,
# expose inprocess
build_file_content="""
alias(
name="core_internal_exposed",
actual="//core:internal",
visibility=["//visibility:public"]
)
"""
)
def _github_archive(name, repo, commit, build_file_content=None):
if build_file_content:
native.new_http_archive(
name = name,
strip_prefix = "%s-%s" % (repo.split("/")[1], commit),
url = "https://github.com/%s/archive/%s.zip" % (repo, commit),
type = "zip",
build_file_content=build_file_content
)
else:
native.http_archive(
name = name,
strip_prefix = "%s-%s" % (repo.split("/")[1], commit),
url = "https://github.com/%s/archive/%s.zip" % (repo, commit),
type = "zip",
)
@hsyed, why the workaround? I am fine with opening up visibility as a workaround, but I want a tracking issue for the Kotlin strict_deps so we can remove the workaround when no longer necessary.
@ejona86 it's temporary. I am working on kotlin coroutine based grpc stub generation internally and had some mixed mode kotlin / java targets. This was making the build a bit convoluted. Will remove the workaround once you have added the changes.
I'm running into this issue right now @hsyed If there is anything I can do to help out in fixing this, let me know.
Also bumping in to this.
What version of gRPC are you using?
Bazel:
What did you expect to see?
Visibility resolution not causing a problem.
Problem
I am the maintainer of the Kotlin Bazel rules and I am working on porting some of our Grpc stuff to Kotlin. The visibility of the internal targets is causing the Kotlin compiler problems. I have only hit this problem in Kotlin. The Java rules don't have this problem. The only symbol I am using is the InProcessServerBuilder in my test class.
The Kotlin compiler is probably being too eager. I hope there is a work short term work around.
If there isn't a quick fix would it be possible to open up the visibility ?