rules_scala icon indicating copy to clipboard operation
rules_scala copied to clipboard

Cannot compile a Scrooge Finagle service

Open pvcnt opened this issue 7 years ago • 7 comments
trafficstars

Hello,

Since I upgraded my Scala rules (last version known to work was 21c8913a2cf35130870df9f07a781afc77f33693, from last March), I cannot compile anymore my Thrift services with Scrooge. Creating scrooge_scala_library when the IDL file contains only structs is ok, but I cannot create a library when the IDL file also contains a service.

When trying to compile the target scrooge_scala_library, I get a lot of compilation errors looking like: error: object finagle is not a member of package com.twitter

Previously, I used to add "//3rdparty/jvm/com/twitter:finagle_thrift" to my deps to bring in the Finagle dependency, but if I do so, I now get another error: <target //3rdparty/jvm/com/twitter:finagle_thrift> (rule 'scala_import') doesn't contain declared provider 'ThriftInfo'

I couldn't spot any documentation or tests about compiling Finagle Scrooge services, so I am a bit stuck. I can contribute tests/documentation if given a hint about how things are supposed to work. Thanks!

pvcnt avatar Aug 20 '18 15:08 pvcnt

@pvcnt could you possibly submit a failing test?

The problem is we didn't have any tests for this and are clearly not exercising this. :(

I'm afraid the refactor of the rules may have broken thrift services.

You can try to work around with:

https://github.com/bazelbuild/rules_scala/blob/master/twitter_scrooge/twitter_scrooge.bzl#L386

scrooge_scala_import(
  name = "finagle_deps",
  scala_jars = ["//3rdparty/jvm/com/twitter:finagle_thrift"]
)

and then add that as a dep...

However, if that does not work, we may have a bigger problem. Obviously, that's a pain... what we probably need to do is improve a thrift toolchain similar to the scalac provider code so that we can configure which jars are on the classpath by default.

johnynek avatar Aug 24 '18 18:08 johnynek

@johnynek Thank you for your response and suggestion.

I created a reproducibility repository here: https://github.com/pvcnt/rules_scala-issue-592 Please use bazel build thrift:service_scala_thrift to try to compile a simple Scrooge service, which fails.

I tried your suggestion, and I have another error:

ERROR: /Users/vincent/workspace/rules_scala-issue-592/thrift/BUILD:20:1: in scrooge_scala_library rule //thrift:service_scala_thrift:
Traceback (most recent call last):
	File "/Users/vincent/workspace/rules_scala-issue-592/thrift/BUILD", line 20
		scrooge_scala_library(name = 'service_scala_thrift')
	File "/private/var/tmp/_bazel_vincent/aaff53d76bc8f1f19b1b4ed957fdcd9f/external/io_bazel_rules_scala/twitter_scrooge/twitter_scrooge.bzl", line 334, in _scrooge_scala_library_impl
		struct(scala = _create_scala_struct(ctx..., ...)])
	File "/private/var/tmp/_bazel_vincent/aaff53d76bc8f1f19b1b4ed957fdcd9f/external/io_bazel_rules_scala/twitter_scrooge/twitter_scrooge.bzl", line 335, in struct
		_create_scala_struct(ctx)
	File "/private/var/tmp/_bazel_vincent/aaff53d76bc8f1f19b1b4ed957fdcd9f/external/io_bazel_rules_scala/twitter_scrooge/twitter_scrooge.bzl", line 356, in _create_scala_struct
		dep[ScroogeAspectInfo].java_info.outputs.jars
object of type 'NoneType' has no field 'jars'
ERROR: Analysis of target '//thrift:service_scala_thrift' failed; build aborted: Analysis of target '//thrift:service_scala_thrift' failed; build aborted
INFO: Elapsed time: 0.125s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (1 packages loaded)

I am not very familiar with complex Bazel rules, but let me know if I can help otherwise (e.g., by contributing tests or documentation).

pvcnt avatar Sep 03 '18 15:09 pvcnt

I fixed the last error you had with https://github.com/discordapp/rules_scala/commit/053d08aad0983cb1310b77d2bb3587c1e67b1128, but this only appears to fix that error not appearing. Compile still fails with error: object finagle is not a member of package com.twitter

samschlegel avatar Jan 11 '19 02:01 samschlegel

I encountered a similar exception and got around it by re-binding a group of libraries. I made a PR (which is pending) updating the README on how to do this: https://github.com/bazelbuild/rules_scala/pull/847

KaoruDev avatar Sep 27 '19 13:09 KaoruDev

It's been four years, I moved on. :)

pvcnt avatar Feb 17 '24 12:02 pvcnt

@pvcnt does that mean to date there is no way to compile bindings for service in thrift using scrooge?

FrankPortman avatar May 21 '24 21:05 FrankPortman

I don't know tbh, I'm not anymore using those rules.

pvcnt avatar May 24 '24 15:05 pvcnt